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

Conversation

zachaysan
Copy link
Contributor

Changes

Adds logging to help diagnose a strange bug that came up in production around conditions being created in large numbers.

How did you test this code?

The existing test suite should cover the code running ok.

@zachaysan zachaysan requested a review from a team as a code owner September 12, 2024 19:42
@zachaysan zachaysan requested review from matthewelwell and removed request for a team September 12, 2024 19:42
Copy link

vercel bot commented Sep 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Sep 16, 2024 2:41pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Sep 16, 2024 2:41pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Sep 16, 2024 2:41pm

Copy link

sentry-io bot commented Sep 12, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: api/segments/models.py

Function Unhandled Issue
deep_clone AssertionError /api/v1/projects/{project_pk}/segm...
Event Count: 2
📄 File: api/segments/serializers.py (Click to Expand)
Function Unhandled Issue
update AssertionError /api/v1/projects/{project_pk}/segm...
Event Count: 2
---

Did you find this useful? React with a 👍 or 👎

@zachaysan zachaysan removed the request for review from matthewelwell September 12, 2024 19:42
@github-actions github-actions bot added api Issue related to the REST API fix labels Sep 12, 2024
Copy link
Contributor

github-actions bot commented Sep 12, 2024

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-4625 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-4625 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-4625 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-4625 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-4625 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-4625 Finished ✅ Results

@zachaysan zachaysan requested a review from rolodato September 12, 2024 19:43
Copy link
Contributor

github-actions bot commented Sep 12, 2024

Uffizzi Preview deployment-56218 was deleted.

@github-actions github-actions bot added fix and removed fix labels Sep 12, 2024
Copy link

codecov bot commented Sep 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.17%. Comparing base (52b9780) to head (e84ad26).
Report is 15 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4625   +/-   ##
=======================================
  Coverage   97.17%   97.17%           
=======================================
  Files        1162     1162           
  Lines       40267    40275    +8     
=======================================
+ Hits        39130    39138    +8     
  Misses       1137     1137           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -246,6 +247,10 @@ def deep_clone(self, cloned_segment: Segment) -> "SegmentRule":
cloned_rule.uuid = uuid.uuid4()
cloned_rule.id = None
cloned_rule.save()
if is_saas():
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to worry about only logging in SaaS - most people won't have the log level set to info anyway ... in fact, I'm not sure that we do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I sorta agree with you but this was the feedback from @rolodato so I deferred to his judgement.
  2. We don't log info in production? That's really surprising. How should I diagnose issues like this where we want to track down problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I've reverted the commit that adds the is_saas check, though I'm not really sure if this PR is useful if we're not logging info in production so I still need guidance on that one.

Copy link
Contributor

Choose a reason for hiding this comment

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

(2) based on this and this, I don't think we do.

You'll need to propose a solution :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two solutions come to mind:

  1. Enable logging info in production. I don't really see the downside of logging info. It's the log level that's been set at every other company I've been at and I can't be the only engineer that's surprised to see that it's not logged. Disabling debug level logging makes sense though.
  2. Switch the logging level to warning which sorta rubs me the wrong way since these aren't really warnings, but I can add comments next to each logging warning call that says basically "these aren't really warnings but we want to log them in production and production is currently set at the warning level" but something more pithier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, I'm happy with (1) - can you add that to this PR? It should just be a case of setting that environment variable in the task definition JSON file (+ the one for staging too for consistency).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I think I've set the environment variables for staging and production properly, but I'm not really sure how to test the setting. Maybe we can verify once this is merged into main on staging?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, exactly.

@github-actions github-actions bot added fix and removed fix labels Sep 13, 2024
@github-actions github-actions bot added fix and removed fix labels Sep 13, 2024
@@ -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.

@matthewelwell matthewelwell added this pull request to the merge queue Sep 26, 2024
Merged via the queue into main with commit 12a8a8e Sep 26, 2024
35 checks passed
@matthewelwell matthewelwell deleted the fix/add_logging_to_segment_code branch September 26, 2024 10:19
@matthewelwell
Copy link
Contributor

Tested in staging

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants