diff --git a/snuba/web/rpc/common/common.py b/snuba/web/rpc/common/common.py index a62a9ed995f..f05c9c46057 100644 --- a/snuba/web/rpc/common/common.py +++ b/snuba/web/rpc/common/common.py @@ -294,6 +294,8 @@ def trace_item_filters_to_expression(item_filter: TraceItemFilter) -> Expression v_expression = literal(v.val_str) case "val_float": v_expression = literal(v.val_float) + case "val_double": + v_expression = literal(v.val_double) case "val_int": v_expression = literal(v.val_int) case "val_null": @@ -310,6 +312,10 @@ def trace_item_filters_to_expression(item_filter: TraceItemFilter) -> Expression v_expression = literals_array( None, list(map(lambda x: literal(x), v.val_float_array.values)) ) + case "val_double_array": + v_expression = literals_array( + None, list(map(lambda x: literal(x), v.val_double_array.values)) + ) case default: raise NotImplementedError( f"translation of AttributeValue type {default} is not implemented" diff --git a/snuba/web/rpc/v1/endpoint_get_traces.py b/snuba/web/rpc/v1/endpoint_get_traces.py index 572ede9fc91..1e96ceeef3d 100644 --- a/snuba/web/rpc/v1/endpoint_get_traces.py +++ b/snuba/web/rpc/v1/endpoint_get_traces.py @@ -44,6 +44,13 @@ _DEFAULT_ROW_LIMIT = 10_000 _BUFFER_WINDOW = 2 * 3600 # 2 hours + +def _convert_key_to_support_doubles_and_floats_for_backward_compat( + key: TraceAttribute.Key.ValueType, +) -> TraceAttribute.Key.ValueType: + return TraceAttribute.Key.ValueType(-1 * key) + + _ATTRIBUTES: dict[ TraceAttribute.Key.ValueType, tuple[str, AttributeKey.Type.ValueType], @@ -69,6 +76,14 @@ AttributeKey.Type.TYPE_STRING, ), } +# for every AttributeKey of TYPE_FLOAT a user may add during the backward compat period, this adds the TYPE_DOUBLE equivalent +for k in _ATTRIBUTES: + v = _ATTRIBUTES[k] + if v[1] == AttributeKey.Type.TYPE_FLOAT: + _ATTRIBUTES[ + _convert_key_to_support_doubles_and_floats_for_backward_compat(k) + ] = (v[0], AttributeKey.Type.TYPE_DOUBLE) + _TYPES_TO_CLICKHOUSE: dict[ AttributeKey.Type.ValueType, tuple[str, Callable[[Any], AttributeValue]], @@ -85,6 +100,10 @@ "Float64", lambda x: AttributeValue(val_float=float(x)), ), + AttributeKey.Type.TYPE_DOUBLE: ( + "Float64", + lambda x: AttributeValue(val_double=float(x)), + ), } @@ -102,11 +121,19 @@ def _attribute_to_expression( alias=_ATTRIBUTES[trace_attribute.key][0], ) if trace_attribute.key == TraceAttribute.Key.KEY_START_TIMESTAMP: - attribute = _ATTRIBUTES[trace_attribute.key] + attribute = ( + _ATTRIBUTES[ + _convert_key_to_support_doubles_and_floats_for_backward_compat( + trace_attribute.key + ) + ] + if trace_attribute.type == AttributeKey.Type.TYPE_DOUBLE + else _ATTRIBUTES[trace_attribute.key] + ) return f.cast( f.min(column("start_timestamp")), _TYPES_TO_CLICKHOUSE[attribute[1]][0], - alias=_ATTRIBUTES[trace_attribute.key][0], + alias=attribute[0], ) if trace_attribute.key == TraceAttribute.Key.KEY_ROOT_SPAN_NAME: # TODO: Change to return the root span name instead of the trace's first span's name. @@ -116,7 +143,15 @@ def _attribute_to_expression( alias=_ATTRIBUTES[trace_attribute.key][0], ) if trace_attribute.key in _ATTRIBUTES: - attribute = _ATTRIBUTES[trace_attribute.key] + attribute = ( + _ATTRIBUTES[ + _convert_key_to_support_doubles_and_floats_for_backward_compat( + trace_attribute.key + ) + ] + if trace_attribute.type == AttributeKey.Type.TYPE_DOUBLE + else _ATTRIBUTES[trace_attribute.key] + ) return f.cast( column(attribute[0]), _TYPES_TO_CLICKHOUSE[attribute[1]][0], @@ -165,8 +200,15 @@ def _convert_results( TraceAttribute, ] = defaultdict(TraceAttribute) for attribute in request.attributes: - value = row[_ATTRIBUTES[attribute.key][0]] - type = _ATTRIBUTES[attribute.key][1] + backward_compat_attribute_key = ( + _convert_key_to_support_doubles_and_floats_for_backward_compat( + attribute.key + ) + if attribute.type == AttributeKey.Type.TYPE_DOUBLE + else attribute.key + ) + value = row[_ATTRIBUTES[backward_compat_attribute_key][0]] + type = _ATTRIBUTES[backward_compat_attribute_key][1] values[attribute.key] = TraceAttribute( key=attribute.key, value=_TYPES_TO_CLICKHOUSE[type][1](value), diff --git a/snuba/web/rpc/v1/resolvers/R_eap_spans/resolver_trace_item_table.py b/snuba/web/rpc/v1/resolvers/R_eap_spans/resolver_trace_item_table.py index a209a33713d..d7d98377999 100644 --- a/snuba/web/rpc/v1/resolvers/R_eap_spans/resolver_trace_item_table.py +++ b/snuba/web/rpc/v1/resolvers/R_eap_spans/resolver_trace_item_table.py @@ -196,7 +196,10 @@ def _convert_results( elif column.key.type == AttributeKey.TYPE_DOUBLE: converters[column.label] = lambda x: AttributeValue(val_double=float(x)) elif column.HasField("aggregation"): - converters[column.label] = lambda x: AttributeValue(val_float=float(x)) + if column.key.type == AttributeKey.TYPE_FLOAT: + converters[column.label] = lambda x: AttributeValue(val_float=float(x)) + if column.key.type == AttributeKey.TYPE_DOUBLE: + converters[column.label] = lambda x: AttributeValue(val_double=float(x)) else: raise BadSnubaRPCRequestException( "column is neither an attribute or aggregation"