Skip to content

Commit

Permalink
fix: Add logging to segments code (#4625)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan authored Sep 26, 2024
1 parent 566520f commit 12a8a8e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
12 changes: 12 additions & 0 deletions api/segments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def deep_clone(self, cloned_segment: Segment) -> "SegmentRule":
cloned_rule.uuid = uuid.uuid4()
cloned_rule.id = None
cloned_rule.save()
logger.info(
f"Deep copying rule {self.id} for cloned rule {cloned_rule.id} for cloned segment {cloned_segment.id}"
)

# Conditions are only part of the sub-rules.
assert self.conditions.exists() is False
Expand All @@ -259,6 +262,10 @@ def deep_clone(self, cloned_segment: Segment) -> "SegmentRule":
cloned_sub_rule.uuid = uuid.uuid4()
cloned_sub_rule.id = None
cloned_sub_rule.save()
logger.info(
f"Deep copying sub rule {sub_rule.id} for cloned sub rule {cloned_sub_rule.id} "
f"for cloned segment {cloned_segment.id}"
)

cloned_conditions = []
for condition in sub_rule.conditions.all():
Expand All @@ -267,6 +274,11 @@ def deep_clone(self, cloned_segment: Segment) -> "SegmentRule":
cloned_condition.uuid = uuid.uuid4()
cloned_condition.id = None
cloned_conditions.append(cloned_condition)
logger.info(
f"Cloning condition {condition.id} for cloned condition {cloned_condition.uuid} "
f"for cloned segment {cloned_segment.id}"
)

Condition.objects.bulk_create(cloned_conditions)

return cloned_rule
Expand Down
9 changes: 9 additions & 0 deletions api/segments/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import typing

from django.conf import settings
Expand All @@ -13,6 +14,8 @@
from projects.models import Project
from segments.models import Condition, Segment, SegmentRule

logger = logging.getLogger(__name__)


class ConditionSerializer(serializers.ModelSerializer):
delete = serializers.BooleanField(write_only=True, required=False)
Expand Down Expand Up @@ -89,6 +92,9 @@ def update(self, instance: Segment, validated_data: dict[str, typing.Any]) -> No

# Create a version of the segment now that we're updating.
cloned_segment = instance.deep_clone()
logger.info(
f"Updating cloned segment {cloned_segment.id} for original segment {instance.id}"
)

try:
self._update_segment_rules(rules_data, segment=instance)
Expand Down Expand Up @@ -123,6 +129,9 @@ def validate_segment_rules_conditions_limit(

count = self._calculate_condition_count(rules_data)

if self.instance:
logger.info(f"Segment {self.instance.id} has count of conditions {count}")

if count > settings.SEGMENT_RULES_CONDITIONS_LIMIT:
raise ValidationError(
{
Expand Down
6 changes: 5 additions & 1 deletion infrastructure/aws/production/ecs-task-definition-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
],
"essential": true,
"environment": [
{
"name": "LOG_LEVEL",
"value": "INFO"
},
{
"name": "AWS_REGION",
"value": "eu-west-2"
Expand Down Expand Up @@ -273,4 +277,4 @@
],
"cpu": "1024",
"memory": "2048"
}
}
4 changes: 4 additions & 0 deletions infrastructure/aws/staging/ecs-task-definition-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
],
"essential": true,
"environment": [
{
"name": "LOG_LEVEL",
"value": "INFO"
},
{
"name": "AWS_REGION",
"value": "eu-west-2"
Expand Down

0 comments on commit 12a8a8e

Please sign in to comment.