-
Notifications
You must be signed in to change notification settings - Fork 24
feat(core): Prefer deferred log events to better track failure #2969
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @dmihalcik-virtru, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the audit logging mechanism to improve the reliability and completeness of audit trails. By introducing a deferred logging pattern, audit events are now created early in a request's execution and progressively updated with relevant information as the operation proceeds. The final log entry is then emitted only when the operation concludes, whether successfully or with an error, or if the request is cancelled. This change ensures that audit logs accurately reflect the full state and outcome of each request, providing more robust tracking and debugging capabilities. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. A log begun, then held in wait, Context gathered, sealed by fate. Defer's embrace, a watchful eye, To track the truth, 'til tasks pass by. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant and valuable refactoring to use deferred audit log events, which will improve failure tracking, especially for cancelled or timed-out requests. The implementation of the deferred event pattern is well-executed across the majority of the services. I've identified one high-severity issue where successful operations might be incorrectly audited as 'cancelled' if a subsequent operation in the same request panics. I've also noted a minor misuse of the new pattern in one location that could be simplified for better clarity. Overall, this is a solid improvement to the auditing mechanism.
| if !success { | ||
| auditEvent.Action.Result = ActionResultCancel | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic overrides the result of all audit events in a transaction to cancel if the request as a whole fails (e.g., panics), even if some operations within the request have already completed successfully and were logged as such. For example, in DeleteAllUnmappedSubjectConditionSets, database deletions are committed, and then corresponding success audit events are queued. If the request panics later, these successful deletions will be incorrectly audited as cancel. This can lead to misleading audit trails.
A test case for an operation that succeeds and is audited with Success(), followed by a panic in the same request, would demonstrate this issue.
Consider changing this to only mark events as cancel if they haven't been explicitly marked as success already. This would preserve the correct status of completed operations within a failed request.
| auditEvent := s.logger.Audit.PolicyCRUD(ctx, auditParams) | ||
| auditEvent.Success(scs) | ||
| auditEvent.Log() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to auditEvent.Log() here is redundant. auditEvent.Success(scs) has already marked the event as complete and queued it for logging within the current audit transaction. The Log() method is primarily intended for use with defer to handle cases where an operation might fail before Success() is called. Since the database operation has already completed successfully and you are just logging the results, the explicit Log() call is not needed and can be removed for clarity.
| auditEvent := s.logger.Audit.PolicyCRUD(ctx, auditParams) | |
| auditEvent.Success(scs) | |
| auditEvent.Log() | |
| auditEvent := s.logger.Audit.PolicyCRUD(ctx, auditParams) | |
| auditEvent.Success(scs) |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
|
If a request times out or is canceled, there is no response given back to the requestor. It seems like there are some audit events where audit-worthy things could have happened (i.e. policy write mutations) without a response, but the most critical audit events around decisions and rewraps have no meaning to clients without a response received back. In essence, those two events arguably never happened without a response because the client action is so dependent upon the response. Should there be any distinction made for this case? |
This is only true in kind circumstances. Response delivery, and ACK of that delivery (in TCP) are not atomic. It is possible for someone to receive a response, fail to ack it, then close the connection. |
These new audit methods allow properly registering an event as going-to-happen, so that they are properly logged in the event of a cancellation or panic.
prompt: There seems to be some code duplication with the different audit types (DeferredX). Is there an idiomatic way in go to combine them?
ec479d1 to
d948ad6
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
These events will now be logged with a So, depending on how the events are aggregated and summarized, some events that are meaningless will now be available, and potentially cause problems. Do we have any sample audit processors I can look into to see how they can be modified, or if such modification may be required? |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Proposed Changes
audit.Eventobjects, which in turn have their own log method.Checklist
Testing Instructions