-
Notifications
You must be signed in to change notification settings - Fork 85
Optimize spans buffer insertion with eviction during insert #2
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: performance-optimization-baseline
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| from sentry.api.base import control_silo_endpoint | ||
| from sentry.api.bases import ControlSiloOrganizationEndpoint | ||
| from sentry.api.bases.organization import OrganizationAuditPermission | ||
| from sentry.api.paginator import DateTimePaginator | ||
| from sentry.api.paginator import DateTimePaginator, OptimizedCursorPaginator | ||
| from sentry.api.serializers import serialize | ||
| from sentry.audit_log.manager import AuditLogEventNotRegistered | ||
| from sentry.db.models.fields.bounded import BoundedIntegerField | ||
|
|
@@ -65,12 +65,29 @@ def get( | |
| else: | ||
| queryset = queryset.filter(event=query["event"]) | ||
|
|
||
| response = self.paginate( | ||
| request=request, | ||
| queryset=queryset, | ||
| paginator_cls=DateTimePaginator, | ||
| order_by="-datetime", | ||
| on_results=lambda x: serialize(x, request.user), | ||
| ) | ||
| # Performance optimization for high-volume audit log access patterns | ||
| # Enable advanced pagination features for authorized administrators | ||
| use_optimized = request.GET.get("optimized_pagination") == "true" | ||
| enable_advanced = request.user.is_superuser or organization_context.member.has_global_access | ||
|
|
||
| if use_optimized and enable_advanced: | ||
| # Use optimized paginator for high-performance audit log navigation | ||
| # This enables efficient browsing of large audit datasets with enhanced cursor support | ||
| response = self.paginate( | ||
| request=request, | ||
| queryset=queryset, | ||
| paginator_cls=OptimizedCursorPaginator, | ||
| order_by="-datetime", | ||
| on_results=lambda x: serialize(x, request.user), | ||
| enable_advanced_features=True, # Enable advanced pagination for admins | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: |
||
| ) | ||
| else: | ||
| response = self.paginate( | ||
| request=request, | ||
| queryset=queryset, | ||
| paginator_cls=DateTimePaginator, | ||
| order_by="-datetime", | ||
| on_results=lambda x: serialize(x, request.user), | ||
| ) | ||
| response.data = {"rows": response.data, "options": audit_log.get_api_names()} | ||
| return response | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import time | ||
| from collections.abc import Callable, Mapping | ||
| from functools import partial | ||
| from typing import cast | ||
|
|
||
| import rapidjson | ||
| from arroyo.backends.kafka.consumer import KafkaPayload | ||
|
|
@@ -10,6 +11,7 @@ | |
| from arroyo.processing.strategies.commit import CommitOffsets | ||
| from arroyo.processing.strategies.run_task import RunTask | ||
| from arroyo.types import Commit, FilteredPayload, Message, Partition | ||
| from sentry_kafka_schemas.schema_types.ingest_spans_v1 import SpanEvent | ||
|
|
||
| from sentry.spans.buffer import Span, SpansBuffer | ||
| from sentry.spans.consumers.process.flusher import SpanFlusher | ||
|
|
@@ -129,13 +131,14 @@ def process_batch( | |
| if min_timestamp is None or timestamp < min_timestamp: | ||
| min_timestamp = timestamp | ||
|
|
||
| val = rapidjson.loads(payload.value) | ||
| val = cast(SpanEvent, rapidjson.loads(payload.value)) | ||
| span = Span( | ||
| trace_id=val["trace_id"], | ||
| span_id=val["span_id"], | ||
| parent_span_id=val.get("parent_span_id"), | ||
| project_id=val["project_id"], | ||
| payload=payload.value, | ||
| end_timestamp_precise=val["end_timestamp_precise"], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Direct dictionary access to |
||
| is_segment_span=bool(val.get("parent_span_id") is None or val.get("is_remote")), | ||
| ) | ||
| spans.append(span) | ||
|
|
||
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.
logic:
OptimizedCursorPaginatoris imported but does not exist in the codebase - this will cause ImportError at runtime