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

Add audit backend #1886

Merged
merged 42 commits into from
Aug 13, 2024
Merged

Add audit backend #1886

merged 42 commits into from
Aug 13, 2024

Conversation

waxlamp
Copy link
Member

@waxlamp waxlamp commented Mar 6, 2024

This PR implements the backend portion of the audit design doc with the following changes:

  • a new model, AuditRecord, that captures audit event information in a general, extensible way
  • a collection of static methods on AuditRecord that construct several audit record types
  • invocation of those static methods at the points in the codebase where the associated actions are carried out

This PR should not be merged outside of the operations plan described in the design doc, so this will be a draft PR until we're ready to carry out that plan.

edit by @yarikoptic: Closes #61

Copy link
Member Author

@waxlamp waxlamp left a comment

Choose a reason for hiding this comment

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

Some points where I'm looking for specific feedback in my "self-review". Otherwise:

  • @mvandenburgh, I thought about cutting the Asset.previous field out in this PR, but that is technically out of scope now that I think about it. Once we capture a DB snapshot and put this into production, you can remove that field in your GC work. Does that sound right?
  • I'm deliberately deferring frontend support to a future PR. I am leaning towards creating a new branch named audit and basing this PR to that branch so that the frontend work can land there as well, enabling us to merge a feature complete branch into production when we're ready. Looking for feedback on this idea.
  • I'd also like to add tests, but not sure how. I'd love to work with someone (@jjnesbitt?) to figure that out. I read this article but did not fully grok it.
    • I tested this PR manually by carrying out each significant action and then observing the creation of AuditRecords in the admin console. Everything seems to work but of course I am not confident I tested every edge and corner case.
  • What to do about these lint errors? I think both represent essential complexity, so I just put an ignore on them. Thoughts?
    • dandiapi/api/services/asset/init.py:108:5: PLR0913 Too many arguments in function definition (6 > 5)

    • dandiapi/api/views/dandiset.py:375:9: C901 users is too complex (11 > 10)

dandiapi/api/services/embargo/__init__.py Outdated Show resolved Hide resolved
dandiapi/api/views/dandiset.py Outdated Show resolved Hide resolved
dandiapi/api/views/version.py Outdated Show resolved Hide resolved
dandiapi/api/models/audit.py Outdated Show resolved Hide resolved
Copy link
Member

@jjnesbitt jjnesbitt left a comment

Choose a reason for hiding this comment

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

A few suggestions but otherwise I like this implementation a lot! It seems fairly lightweight, and I like the specific attention to ensuring the audit records are created in the same transaction as the objects they are tracking.

dandiapi/api/models/audit.py Outdated Show resolved Hide resolved
dandiapi/api/models/audit.py Outdated Show resolved Hide resolved
dandiapi/api/models/audit.py Outdated Show resolved Hide resolved
dandiapi/api/tests/test_asset_paths.py Outdated Show resolved Hide resolved
dandiapi/api/views/dandiset.py Outdated Show resolved Hide resolved
dandiapi/api/views/dandiset.py Outdated Show resolved Hide resolved
dandiapi/api/models/audit.py Outdated Show resolved Hide resolved
dandiapi/api/views/version.py Outdated Show resolved Hide resolved
@mvandenburgh
Copy link
Member

mvandenburgh commented Mar 15, 2024

  • @mvandenburgh, I thought about cutting the Asset.previous field out in this PR, but that is technically out of scope now that I think about it. Once we capture a DB snapshot and put this into production, you can remove that field in your GC work. Does that sound right?

I agree, I think removing the Asset.previous field falls more into the garbage collection scope (although there is some crossover with audit).

  • I'm deliberately deferring frontend support to a future PR. I am leaning towards creating a new branch named audit and basing this PR to that branch so that the frontend work can land there as well, enabling us to merge a feature complete branch into production when we're ready. Looking for feedback on this idea.

I agree frontend should be a future PR. I don't have any strong feelings towards the feature branch idea. An alternative approach could be just merging both of them piecemeal into master, without cutting a release. Then once we're ready, we can cut a release and both will go to prod at the same time. The only thought I have is because we have so many large PRs flying around lately, merging two smaller PRs into master at seperate times might be less painful then waiting to merge one huge one.

  • What to do about these lint errors? I think both represent essential complexity, so I just put an ignore on them. Thoughts?

    • dandiapi/api/services/asset/init.py:108:5: PLR0913 Too many arguments in function definition (6 > 5)

    • dandiapi/api/views/dandiset.py:375:9: C901 users is too complex (11 > 10)

I kind of agree with ruff that the users function is too complex. But I don't think your PR is adding any additional complexity to what is already there, so I think ignoring it is fine. And maybe we can defer a refactor to a later time.

The change_asset service function is somewhat complex, but then again, "changing" an asset is a complex operation due to our domain model and all the intricacies like de-duplication, publishing, etc. Maybe that would be worth revisting and possibly break up, but again I'm not sure this PR is the right place for that.

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

29 similar comments
@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

@dandibot
Copy link
Member

🚀 PR was released in v0.3.93 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

idea: "log" of transactions
5 participants