Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions backend/api/serializers/model_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from django.conf import settings
from django.db.models import Max, Min, Sum
from drf_spectacular.utils import extend_schema_serializer
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from metering_billing.invoice import (
generate_balance_adjustment_invoice,
generate_invoice,
Expand Down Expand Up @@ -67,6 +64,8 @@
USAGE_BEHAVIOR,
USAGE_BILLING_BEHAVIOR,
)
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

SVIX_CONNECTOR = settings.SVIX_CONNECTOR
logger = logging.getLogger("django.server")
Expand Down Expand Up @@ -1326,7 +1325,7 @@ class Meta:
)
idempotency_id = serializers.CharField(
required=True,
help_text="A unique identifier for the specific event being passed in. Passing in a unique id allows Lotus to make sure no double counting occurs. We recommend using a UUID4. You can use the same idempotency_id again after 7 days",
help_text="A unique identifier for the specific event being passed in. Passing in a unique id allows Lotus to make sure no double counting occurs. We recommend using a UUID4.",
)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.5 on 2023-02-22 05:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('metering_billing', '0203_delete_oldevent'),
]

operations = [
migrations.AlterField(
model_name='idempotencecheck',
name='time_created',
field=models.DateTimeField(help_text='The time that the event occured, represented as a datetime in RFC3339 in the UTC timezome.'),
),
]
6 changes: 3 additions & 3 deletions backend/metering_billing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ class IdempotenceCheck(models.Model):
Organization, on_delete=models.SET_NULL, related_name="+", null=True, blank=True
)
time_created = models.DateTimeField(
help_text="The time that the event occured, represented as a datetime in ISO 8601 in the UTC timezome."
help_text="The time that the event occured, represented as a datetime in RFC3339 in the UTC timezome."
)
uuidv5_idempotency_id = models.UUIDField(primary_key=True)

Expand Down Expand Up @@ -1077,7 +1077,7 @@ class Event(models.Model):
)
uuidv5_event_name = models.UUIDField()
time_created = models.DateTimeField(
help_text="The time that the event occured, represented as a datetime in ISO 8601 in the UTC timezome."
help_text="The time that the event occured, represented as a datetime in RFC3339 in the UTC timezome."
)
properties = models.JSONField(
default=dict,
Expand Down Expand Up @@ -2136,7 +2136,7 @@ class Meta:
constraints = [
models.CheckConstraint(
check=(Q(parent_plan__isnull=True) & Q(target_customer__isnull=True))
| Q(parent_plan__isnull=False) & Q(target_customer__isnull=False),
| (Q(parent_plan__isnull=False) & Q(target_customer__isnull=False)),
name="both_null_or_both_not_null",
),
]
Expand Down
15 changes: 13 additions & 2 deletions backend/metering_billing/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import api.views as api_views
import posthog
import sentry_sdk
from actstream.models import Action
from api.serializers.webhook_serializers import (
CustomerCreatedSerializer,
Expand Down Expand Up @@ -211,7 +212,7 @@ def create(self, request, *args, **kwargs):
if expiry_date is None
else (expiry_date - now_utc()).total_seconds()
)
cache.set(api_key.prefix, api_key.organization.pk, timeout)
cache.set(key, api_key.organization.pk, timeout)
headers = self.get_success_headers(serializer.data)
return Response(
{"api_key": serializer.data, "key": key},
Expand All @@ -220,7 +221,15 @@ def create(self, request, *args, **kwargs):
)

def perform_destroy(self, instance):
cache.delete(instance.prefix)
try:
cache.delete_pattern(f"{instance.prefix}*")
except Exception as e:
logger.error("Error deleting cache using delete pattern")
sentry_sdk.capture_exception(e)
keys_to_delete = []
for key in cache.keys(f"{instance.prefix}*"):
keys_to_delete.append(key)
cache.delete_many(keys_to_delete)
return super().perform_destroy(instance)

@extend_schema(
Expand Down Expand Up @@ -1306,3 +1315,5 @@ def get_serializer_context(self):
return context
return context
return context
return context
return context
30 changes: 23 additions & 7 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ services:
ports:
- "8071:8071"
depends_on:
- db
- redis
- db
- redis
links:
- db
- redis
- db
- redis
restart: on-failure

backend: &backend
backend:
&backend
env_file:
- ./env/.env.dev
build:
Expand All @@ -70,11 +71,11 @@ services:
- redis
- redpanda

event-ingestion:
event-guidance:
env_file:
- ./env/.env.dev
build:
context: ./go/eventingestor
context: ./go/event-guidance
dockerfile: Dockerfile
ports:
- 7999:7999
Expand All @@ -85,6 +86,21 @@ services:
- backend
restart: "on-failure:15"

event-ingestion:
env_file:
- ./env/.env.dev
build:
context: ./go/event-ingestion
dockerfile: Dockerfile
ports:
- 7998:7998
depends_on:
- db
- redis
- redpanda
- backend
restart: "on-failure:15"

frontend:
restart: always
build:
Expand Down
23 changes: 19 additions & 4 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,33 @@ services:
- redpanda
restart: on-failure

event-guidance:
env_file:
- ./env/.env.prod
build:
context: ./go/event-guidance
dockerfile: Dockerfile
expose:
- 7999
depends_on:
- db
- redis
- redpanda
restart: "on-failure:15"

event-ingestion:
env_file:
- ./env/.env.dev
- ./env/.env.prod
build:
context: ./go/eventingestor
context: ./go/event-ingestion
dockerfile: Dockerfile
ports:
- 7999:7999
expose:
- 7998
depends_on:
- db
- redis
- redpanda
- backend
restart: "on-failure:15"

frontend:
Expand Down
2 changes: 1 addition & 1 deletion docs/metering/logging-events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Events are defined as the following:
The `event_name` should correspond to what the event is and match what you
define in your metrics.

The `time_created` is an ISO 8601 format date in UTC (no timezone offset).
The `time_created` is an RFC3339 format date in UTC.

The `idempotency_id` is a unique identifier for the specific event being passed
in. Passing in a unique id allows Lotus to make sure no double counting occurs.
Expand Down
Loading