From d7cea38590ba37a50efe3bbc3d05fe9065d9e4b4 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Fri, 3 Oct 2025 17:22:09 -0400 Subject: [PATCH] ref(ourlogs): Move log aggregate definitions to own file Not sure why these definitions were in the spans folder. Moving it out to the logs folder. --- src/sentry/search/eap/ourlogs/aggregates.py | 203 +++++++++++++++++++ src/sentry/search/eap/ourlogs/definitions.py | 2 +- src/sentry/search/eap/spans/aggregates.py | 191 ----------------- 3 files changed, 204 insertions(+), 192 deletions(-) create mode 100644 src/sentry/search/eap/ourlogs/aggregates.py diff --git a/src/sentry/search/eap/ourlogs/aggregates.py b/src/sentry/search/eap/ourlogs/aggregates.py new file mode 100644 index 00000000000000..b811bb85713183 --- /dev/null +++ b/src/sentry/search/eap/ourlogs/aggregates.py @@ -0,0 +1,203 @@ +from sentry_protos.snuba.v1.trace_item_attribute_pb2 import Function + +from sentry.search.eap import constants +from sentry.search.eap.columns import AggregateDefinition, AttributeArgumentDefinition + + +def count_processor(count_value: int | None) -> int: + if count_value is None: + return 0 + else: + return count_value + + +LOG_AGGREGATE_DEFINITIONS = { + "count": AggregateDefinition( + internal_function=Function.FUNCTION_COUNT, + infer_search_type_from_arguments=False, + processor=count_processor, + default_search_type="integer", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "string", + "number", + "integer", + }, + default_arg="log.body", + ) + ], + ), + "count_unique": AggregateDefinition( + internal_function=Function.FUNCTION_UNIQ, + default_search_type="integer", + infer_search_type_from_arguments=False, + processor=count_processor, + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "string", + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "sum": AggregateDefinition( + internal_function=Function.FUNCTION_SUM, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "avg": AggregateDefinition( + internal_function=Function.FUNCTION_AVG, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "p50": AggregateDefinition( + internal_function=Function.FUNCTION_P50, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "p75": AggregateDefinition( + internal_function=Function.FUNCTION_P75, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "p90": AggregateDefinition( + internal_function=Function.FUNCTION_P90, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "p95": AggregateDefinition( + internal_function=Function.FUNCTION_P95, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "p99": AggregateDefinition( + internal_function=Function.FUNCTION_P99, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "max": AggregateDefinition( + internal_function=Function.FUNCTION_MAX, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), + "min": AggregateDefinition( + internal_function=Function.FUNCTION_MIN, + default_search_type="number", + arguments=[ + AttributeArgumentDefinition( + attribute_types={ + "duration", + "number", + "integer", + "percentage", + "currency", + *constants.SIZE_TYPE, + *constants.DURATION_TYPE, + }, + ) + ], + ), +} diff --git a/src/sentry/search/eap/ourlogs/definitions.py b/src/sentry/search/eap/ourlogs/definitions.py index 0a6759bb993a08..2fe10eb8366534 100644 --- a/src/sentry/search/eap/ourlogs/definitions.py +++ b/src/sentry/search/eap/ourlogs/definitions.py @@ -1,13 +1,13 @@ from sentry_protos.snuba.v1.request_common_pb2 import TraceItemType from sentry.search.eap.columns import ColumnDefinitions +from sentry.search.eap.ourlogs.aggregates import LOG_AGGREGATE_DEFINITIONS from sentry.search.eap.ourlogs.attributes import ( OURLOG_ATTRIBUTE_DEFINITIONS, OURLOG_VIRTUAL_CONTEXTS, ourlog_column_to_custom_alias, ourlog_custom_alias_to_column, ) -from sentry.search.eap.spans.aggregates import LOG_AGGREGATE_DEFINITIONS OURLOG_DEFINITIONS = ColumnDefinitions( aggregates=LOG_AGGREGATE_DEFINITIONS, diff --git a/src/sentry/search/eap/spans/aggregates.py b/src/sentry/search/eap/spans/aggregates.py index b901a2a390c023..2459ae1db2e194 100644 --- a/src/sentry/search/eap/spans/aggregates.py +++ b/src/sentry/search/eap/spans/aggregates.py @@ -725,194 +725,3 @@ def resolve_bounded_sample(args: ResolvedArguments) -> tuple[AttributeKey, Trace ], ), } - -LOG_AGGREGATE_DEFINITIONS = { - "count": AggregateDefinition( - internal_function=Function.FUNCTION_COUNT, - infer_search_type_from_arguments=False, - processor=count_processor, - default_search_type="integer", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "string", - "number", - "integer", - }, - default_arg="log.body", - ) - ], - ), - "count_unique": AggregateDefinition( - internal_function=Function.FUNCTION_UNIQ, - default_search_type="integer", - infer_search_type_from_arguments=False, - processor=count_processor, - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "string", - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "sum": AggregateDefinition( - internal_function=Function.FUNCTION_SUM, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "avg": AggregateDefinition( - internal_function=Function.FUNCTION_AVG, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "p50": AggregateDefinition( - internal_function=Function.FUNCTION_P50, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "p75": AggregateDefinition( - internal_function=Function.FUNCTION_P75, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "p90": AggregateDefinition( - internal_function=Function.FUNCTION_P90, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "p95": AggregateDefinition( - internal_function=Function.FUNCTION_P95, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "p99": AggregateDefinition( - internal_function=Function.FUNCTION_P99, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "max": AggregateDefinition( - internal_function=Function.FUNCTION_MAX, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), - "min": AggregateDefinition( - internal_function=Function.FUNCTION_MIN, - default_search_type="number", - arguments=[ - AttributeArgumentDefinition( - attribute_types={ - "duration", - "number", - "integer", - "percentage", - "currency", - *constants.SIZE_TYPE, - *constants.DURATION_TYPE, - }, - ) - ], - ), -}