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: audit log integrations for versioned environments #4876

Merged
merged 10 commits into from
Dec 6, 2024

Conversation

matthewelwell
Copy link
Contributor

Changes

Fixes audit log based integrations when running in a versioned environment.

How did you test this code?

Updated existing tests.

@matthewelwell matthewelwell requested a review from a team as a code owner November 29, 2024 11:17
@matthewelwell matthewelwell requested review from khvn26 and removed request for a team November 29, 2024 11:17
Copy link

vercel bot commented Nov 29, 2024

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

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 5:16pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 5:16pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 5:16pm

@github-actions github-actions bot added the api Issue related to the REST API label Nov 29, 2024
Copy link
Contributor

github-actions bot commented Nov 29, 2024

Docker builds report

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

@github-actions github-actions bot added the fix label Nov 29, 2024
Copy link
Contributor

github-actions bot commented Nov 29, 2024

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/4876

⚙️ Updating now by workflow run 12184720423.

What is Uffizzi? Learn more!

@@ -61,6 +61,7 @@ def signal_wrapper(sender, instance, **kwargs):
RelatedObjectType.FEATURE.name,
RelatedObjectType.FEATURE_STATE.name,
RelatedObjectType.SEGMENT.name,
RelatedObjectType.EF_VERSION.name,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is essentially the only thing that needed to change to fix the issue. The rest of the changes are related to the tests, improving the integration for EF versions, or refactoring.

Comment on lines +118 to +119
grafana_config = GrafanaProjectConfiguration(base_url="test.com", api_key="test")
project.grafana_config = grafana_config
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having added the logic to prevent the postpone decorator from spawning unmanaged threads we need to move this here to prevent the generation of the audit log record itself from triggering an external request to Grafana (or Dynatrace as the case may be below).

Comment on lines +76 to +79
mocker.patch(
"integrations.dynatrace.dynatrace.get_audited_instance_from_audit_log_record",
return_value=related_object,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't love having to introduce a mock here, but this test is all a little bit superficial anyway. I'd rather replace all of these parameterised tests with more end-to-end style tests like the new one I added for EF version here.

api/util/util.py Outdated
t = Thread(target=function, args=args, kwargs=kwargs)
t.daemon = True
t.start()
if settings.ENABLE_POSTPONE_DECORATOR:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is somewhat ugly, and I'd rather remove the postpone decorator entirely to rely instead upon the run_in_thread method exposed by registered tasks. But, I'd still then want to be able to disable the threading in a test environment because it's all a bit difficult to test anyway (and it's how we sometimes end up with errors in the logs, but not in the tests).

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.38%. Comparing base (05ab7cf) to head (b4cce4d).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4876   +/-   ##
=======================================
  Coverage   97.38%   97.38%           
=======================================
  Files        1189     1189           
  Lines       41420    41453   +33     
=======================================
+ Hits        40338    40371   +33     
  Misses       1082     1082           

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

@github-actions github-actions bot added fix and removed fix labels Nov 29, 2024
…sioning

# Conflicts:
#	api/app/settings/test.py
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