From 12a8a8ee694cdd0eb0ef6a2ea0708a003796b738 Mon Sep 17 00:00:00 2001 From: Zach Aysan Date: Thu, 26 Sep 2024 06:18:45 -0400 Subject: [PATCH] fix: Add logging to segments code (#4625) --- api/segments/models.py | 12 ++++++++++++ api/segments/serializers.py | 9 +++++++++ .../aws/production/ecs-task-definition-web.json | 6 +++++- .../aws/staging/ecs-task-definition-web.json | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/api/segments/models.py b/api/segments/models.py index 3fae7fd2b34e..8b8553484985 100644 --- a/api/segments/models.py +++ b/api/segments/models.py @@ -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 @@ -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(): @@ -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 diff --git a/api/segments/serializers.py b/api/segments/serializers.py index 322357038eef..053d119d0499 100644 --- a/api/segments/serializers.py +++ b/api/segments/serializers.py @@ -1,3 +1,4 @@ +import logging import typing from django.conf import settings @@ -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) @@ -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) @@ -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( { diff --git a/infrastructure/aws/production/ecs-task-definition-web.json b/infrastructure/aws/production/ecs-task-definition-web.json index ceed5987901c..1a5092aa7293 100644 --- a/infrastructure/aws/production/ecs-task-definition-web.json +++ b/infrastructure/aws/production/ecs-task-definition-web.json @@ -19,6 +19,10 @@ ], "essential": true, "environment": [ + { + "name": "LOG_LEVEL", + "value": "INFO" + }, { "name": "AWS_REGION", "value": "eu-west-2" @@ -273,4 +277,4 @@ ], "cpu": "1024", "memory": "2048" -} \ No newline at end of file +} diff --git a/infrastructure/aws/staging/ecs-task-definition-web.json b/infrastructure/aws/staging/ecs-task-definition-web.json index 16938a00ae39..98c16f29c4f4 100644 --- a/infrastructure/aws/staging/ecs-task-definition-web.json +++ b/infrastructure/aws/staging/ecs-task-definition-web.json @@ -19,6 +19,10 @@ ], "essential": true, "environment": [ + { + "name": "LOG_LEVEL", + "value": "INFO" + }, { "name": "AWS_REGION", "value": "eu-west-2"