Skip to content

Commit ecc5a6b

Browse files
Rachel ChenRachel Chen
authored andcommitted
ok this method is jank but its still functional
1 parent ca2cf30 commit ecc5a6b

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

snuba/web/rpc/common/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ def trace_item_filters_to_expression(item_filter: TraceItemFilter) -> Expression
294294
v_expression = literal(v.val_str)
295295
case "val_float":
296296
v_expression = literal(v.val_float)
297+
case "val_double":
298+
v_expression = literal(v.val_double)
297299
case "val_int":
298300
v_expression = literal(v.val_int)
299301
case "val_null":
@@ -310,6 +312,10 @@ def trace_item_filters_to_expression(item_filter: TraceItemFilter) -> Expression
310312
v_expression = literals_array(
311313
None, list(map(lambda x: literal(x), v.val_float_array.values))
312314
)
315+
case "val_double_array":
316+
v_expression = literals_array(
317+
None, list(map(lambda x: literal(x), v.val_double_array.values))
318+
)
313319
case default:
314320
raise NotImplementedError(
315321
f"translation of AttributeValue type {default} is not implemented"

snuba/web/rpc/v1/endpoint_get_traces.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
_DEFAULT_ROW_LIMIT = 10_000
4545
_BUFFER_WINDOW = 2 * 3600 # 2 hours
4646

47+
48+
def _convert_key_to_support_doubles_and_floats_for_backward_compat(
49+
key: TraceAttribute.Key.ValueType,
50+
) -> TraceAttribute.Key.ValueType:
51+
return TraceAttribute.Key.ValueType(-1 * key)
52+
53+
4754
_ATTRIBUTES: dict[
4855
TraceAttribute.Key.ValueType,
4956
tuple[str, AttributeKey.Type.ValueType],
@@ -69,6 +76,16 @@
6976
AttributeKey.Type.TYPE_STRING,
7077
),
7178
}
79+
# for every AttributeKey of TYPE_FLOAT a user may add during the backward compat period, this adds the TYPE_DOUBLE equivalent
80+
_attributes_backward_compat = dict()
81+
for k in _ATTRIBUTES:
82+
v = _ATTRIBUTES[k]
83+
if v[1] == AttributeKey.Type.TYPE_FLOAT:
84+
_attributes_backward_compat[
85+
_convert_key_to_support_doubles_and_floats_for_backward_compat(k)
86+
] = (v[0], AttributeKey.Type.TYPE_DOUBLE)
87+
_ATTRIBUTES.update(_attributes_backward_compat)
88+
7289
_TYPES_TO_CLICKHOUSE: dict[
7390
AttributeKey.Type.ValueType,
7491
tuple[str, Callable[[Any], AttributeValue]],
@@ -85,6 +102,10 @@
85102
"Float64",
86103
lambda x: AttributeValue(val_float=float(x)),
87104
),
105+
AttributeKey.Type.TYPE_DOUBLE: (
106+
"Float64",
107+
lambda x: AttributeValue(val_double=float(x)),
108+
),
88109
}
89110

90111

@@ -102,11 +123,19 @@ def _attribute_to_expression(
102123
alias=_ATTRIBUTES[trace_attribute.key][0],
103124
)
104125
if trace_attribute.key == TraceAttribute.Key.KEY_START_TIMESTAMP:
105-
attribute = _ATTRIBUTES[trace_attribute.key]
126+
attribute = (
127+
_ATTRIBUTES[
128+
_convert_key_to_support_doubles_and_floats_for_backward_compat(
129+
trace_attribute.key
130+
)
131+
]
132+
if trace_attribute.type == AttributeKey.Type.TYPE_DOUBLE
133+
else _ATTRIBUTES[trace_attribute.key]
134+
)
106135
return f.cast(
107136
f.min(column("start_timestamp")),
108137
_TYPES_TO_CLICKHOUSE[attribute[1]][0],
109-
alias=_ATTRIBUTES[trace_attribute.key][0],
138+
alias=attribute[0],
110139
)
111140
if trace_attribute.key == TraceAttribute.Key.KEY_ROOT_SPAN_NAME:
112141
# TODO: Change to return the root span name instead of the trace's first span's name.
@@ -116,7 +145,15 @@ def _attribute_to_expression(
116145
alias=_ATTRIBUTES[trace_attribute.key][0],
117146
)
118147
if trace_attribute.key in _ATTRIBUTES:
119-
attribute = _ATTRIBUTES[trace_attribute.key]
148+
attribute = (
149+
_ATTRIBUTES[
150+
_convert_key_to_support_doubles_and_floats_for_backward_compat(
151+
trace_attribute.key
152+
)
153+
]
154+
if trace_attribute.type == AttributeKey.Type.TYPE_DOUBLE
155+
else _ATTRIBUTES[trace_attribute.key]
156+
)
120157
return f.cast(
121158
column(attribute[0]),
122159
_TYPES_TO_CLICKHOUSE[attribute[1]][0],
@@ -165,8 +202,15 @@ def _convert_results(
165202
TraceAttribute,
166203
] = defaultdict(TraceAttribute)
167204
for attribute in request.attributes:
168-
value = row[_ATTRIBUTES[attribute.key][0]]
169-
type = _ATTRIBUTES[attribute.key][1]
205+
backward_compat_attribute_key = (
206+
_convert_key_to_support_doubles_and_floats_for_backward_compat(
207+
attribute.key
208+
)
209+
if attribute.type == AttributeKey.Type.TYPE_DOUBLE
210+
else attribute.key
211+
)
212+
value = row[_ATTRIBUTES[backward_compat_attribute_key][0]]
213+
type = _ATTRIBUTES[backward_compat_attribute_key][1]
170214
values[attribute.key] = TraceAttribute(
171215
key=attribute.key,
172216
value=_TYPES_TO_CLICKHOUSE[type][1](value),

snuba/web/rpc/v1/resolvers/R_eap_spans/resolver_trace_item_table.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ def _convert_results(
196196
elif column.key.type == AttributeKey.TYPE_DOUBLE:
197197
converters[column.label] = lambda x: AttributeValue(val_double=float(x))
198198
elif column.HasField("aggregation"):
199-
converters[column.label] = lambda x: AttributeValue(val_float=float(x))
199+
if column.key.type == AttributeKey.TYPE_FLOAT:
200+
converters[column.label] = lambda x: AttributeValue(val_float=float(x))
201+
if column.key.type == AttributeKey.TYPE_DOUBLE:
202+
converters[column.label] = lambda x: AttributeValue(val_double=float(x))
200203
else:
201204
raise BadSnubaRPCRequestException(
202205
"column is neither an attribute or aggregation"

0 commit comments

Comments
 (0)