Skip to content

feat(logservice): Add possible data field to filter #68953

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

Merged
merged 5 commits into from
Apr 16, 2024

Conversation

mbauer404
Copy link
Contributor

Adds a possible data field to find_last_log() to enable filtering by that field if and only if it is included.

@mbauer404 mbauer404 requested a review from a team as a code owner April 15, 2024 23:37
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 15, 2024
organization_id: int | None,
target_object_id: int | None,
event: int | None,
data: dict[str, str] | None,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
data: dict[str, str] | None,
data: dict[str, str] | None = None,

We can default data to be None so that we don't need to update the log_service.find_last_log() calls to add the data parameter in both sentry and getsentry.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup. When changing parameters of hybrid cloud services, everything new must have default parameters due to fragmented deployment.

target_object=target_object_id,
event=event,
).last()
if data: # Only use data field for fitlering if it isn't None
Copy link
Contributor

Choose a reason for hiding this comment

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

what about

            last_entry_q: QuerySet[AuditLogEntry] = AuditLogEntry.objects.filter(
                organization_id=organization_id,
                target_object=target_object_id,
                event=event,
            )

            if data:
              last_entry_q = last_entry_q.filter(data=data)
            last_entry: AuditLogEntry | None = last_entry_q.last()

organization_id: int | None,
target_object_id: int | None,
event: int | None,
data: dict[str, str] | None,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
data: dict[str, str] | None,
data: dict[str, str] | None = None,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the additional default added, I haven't been able to figure out how to get the params to include the data field when calling cls._get_abstract_rpc_methods() here. Any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

You also need to change the signature of the abstract base class (LogService) to match. When the signatures don't match it isn't included.

@@ -38,6 +38,7 @@ def find_last_log(
organization_id: int | None,
target_object_id: int | None,
event: int | None,
data: dict[str, str] | None,
Copy link
Contributor

Choose a reason for hiding this comment

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

= None

Copy link
Member

@dashed dashed left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@mbauer404 mbauer404 force-pushed the mbauer/add-data-to-log-service branch from 9aae3f6 to d17cc32 Compare April 16, 2024 19:01
@mbauer404 mbauer404 merged commit 5c2394b into master Apr 16, 2024
@mbauer404 mbauer404 deleted the mbauer/add-data-to-log-service branch April 16, 2024 19:35
@github-actions github-actions bot locked and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants