Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add logging to segments code #4625

Merged
merged 7 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
],
"essential": true,
"environment": [
{
"name": "LOG_LEVEL",
"value": "info"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably fine, but for consistency, I think this should be INFO ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Updated.

},
{
"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
Loading