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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/sentry/services/hybrid_cloud/log/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime

from django.db import IntegrityError, router, transaction
from django.db.models import QuerySet

from sentry.db.postgres.transactions import enforce_constraints
from sentry.models.auditlogentry import AuditLogEntry
Expand Down Expand Up @@ -51,13 +52,21 @@ def record_user_ip(self, *, event: UserIpEvent) -> None:
).update(last_active=event.last_seen)

def find_last_log(
self, *, organization_id: int | None, target_object_id: int | None, event: int | None
self,
*,
organization_id: int | None,
target_object_id: int | None,
event: int | None,
data: dict[str, str] | None = None,
) -> AuditLogEvent | None:
last_entry: AuditLogEntry | None = AuditLogEntry.objects.filter(
last_entry_q: QuerySet[AuditLogEntry] = AuditLogEntry.objects.filter(
organization_id=organization_id,
target_object=target_object_id,
event=event,
).last()
)
if data:
last_entry_q = last_entry_q.filter(data=data)
last_entry: AuditLogEntry | None = last_entry_q.last()

if last_entry is None:
return None
Expand Down Expand Up @@ -87,6 +96,11 @@ def record_user_ip(self, *, event: UserIpEvent) -> None:
outbox.save()

def find_last_log(
self, *, organization_id: int | None, target_object_id: int | None, event: int | None
self,
*,
organization_id: int | None,
target_object_id: int | None,
event: int | None,
data: dict[str, str] | None = None,
) -> AuditLogEvent | None:
return None
1 change: 1 addition & 0 deletions src/sentry/services/hybrid_cloud/log/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = None,
) -> AuditLogEvent | None:
pass

Expand Down