|
2 | 2 | from datetime import datetime |
3 | 3 | from typing import Any |
4 | 4 |
|
| 5 | +from sentry_protos.snuba.v1.trace_item_attribute_pb2 import ( |
| 6 | + AttributeKey, |
| 7 | + AttributeValue, |
| 8 | + IntArray, |
| 9 | + StrArray, |
| 10 | +) |
| 11 | +from sentry_protos.snuba.v1.trace_item_filter_pb2 import ComparisonFilter, TraceItemFilter |
| 12 | + |
5 | 13 | from sentry.models.environment import Environment |
6 | 14 | from sentry.models.organization import Organization |
7 | 15 | from sentry.models.project import Project |
| 16 | +from sentry.search.eap.rpc_utils import and_trace_item_filters, or_trace_item_filters |
8 | 17 | from sentry.search.events.types import SnubaParams |
9 | 18 |
|
10 | 19 |
|
@@ -74,3 +83,56 @@ def _to_count_map(rows: Sequence[Mapping[str, Any]]) -> dict[Hashable, int]: |
74 | 83 | return False |
75 | 84 |
|
76 | 85 | return all(exp_count <= control_map[key] for key, exp_count in experimental_map.items()) |
| 86 | + |
| 87 | + |
| 88 | +def build_group_id_in_filter(group_ids: Sequence[int]) -> TraceItemFilter: |
| 89 | + return TraceItemFilter( |
| 90 | + comparison_filter=ComparisonFilter( |
| 91 | + key=AttributeKey(name="group_id", type=AttributeKey.TYPE_INT), |
| 92 | + op=ComparisonFilter.OP_IN, |
| 93 | + value=AttributeValue(val_int_array=IntArray(values=list(group_ids))), |
| 94 | + ) |
| 95 | + ) |
| 96 | + |
| 97 | + |
| 98 | +def build_event_id_in_filter(event_ids: Sequence[str]) -> TraceItemFilter: |
| 99 | + return TraceItemFilter( |
| 100 | + comparison_filter=ComparisonFilter( |
| 101 | + key=AttributeKey(name="sentry.item_id", type=AttributeKey.TYPE_STRING), |
| 102 | + op=ComparisonFilter.OP_IN, |
| 103 | + value=AttributeValue(val_str_array=StrArray(values=list(event_ids))), |
| 104 | + ) |
| 105 | + ) |
| 106 | + |
| 107 | + |
| 108 | +def build_keyset_pagination_filter( |
| 109 | + timestamp_value: str, |
| 110 | + event_id: str, |
| 111 | +) -> TraceItemFilter: |
| 112 | + ts_epoch = datetime.fromisoformat(timestamp_value).timestamp() |
| 113 | + timestamp_key = AttributeKey(name="sentry.timestamp", type=AttributeKey.TYPE_DOUBLE) |
| 114 | + event_id_key = AttributeKey(name="sentry.item_id", type=AttributeKey.TYPE_STRING) |
| 115 | + |
| 116 | + ts_lte = TraceItemFilter( |
| 117 | + comparison_filter=ComparisonFilter( |
| 118 | + key=timestamp_key, |
| 119 | + op=ComparisonFilter.OP_LESS_THAN_OR_EQUALS, |
| 120 | + value=AttributeValue(val_double=ts_epoch), |
| 121 | + ) |
| 122 | + ) |
| 123 | + ts_lt = TraceItemFilter( |
| 124 | + comparison_filter=ComparisonFilter( |
| 125 | + key=timestamp_key, |
| 126 | + op=ComparisonFilter.OP_LESS_THAN, |
| 127 | + value=AttributeValue(val_double=ts_epoch), |
| 128 | + ) |
| 129 | + ) |
| 130 | + eid_lt = TraceItemFilter( |
| 131 | + comparison_filter=ComparisonFilter( |
| 132 | + key=event_id_key, |
| 133 | + op=ComparisonFilter.OP_LESS_THAN, |
| 134 | + value=AttributeValue(val_str=event_id), |
| 135 | + ) |
| 136 | + ) |
| 137 | + |
| 138 | + return and_trace_item_filters(ts_lte, or_trace_item_filters(ts_lt, eid_lt)) |
0 commit comments