fix: deprecate field kind (#9609)
This pull request refines how deprecated and new trace fields are mapped and handled within the query service, ensuring more accurate field translation and data type usage. It also updates related test cases and constant definitions to reflect these changes, improving consistency and correctness when working with trace attributes like `kind` and `kind_string`.
This commit is contained in:
@@ -53,9 +53,14 @@ func getClickHouseTracesColumnDataType(columnDataType v3.AttributeKeyDataType) s
|
||||
|
||||
func getColumnName(key v3.AttributeKey, replaceAlias bool) string {
|
||||
if replaceAlias {
|
||||
// It should be in DeprecatedStaticFieldsTraces
|
||||
if _, ok := constants.DeprecatedStaticFieldsTraces[key.Key]; ok {
|
||||
// It should not be in NewStaticFieldsTraces
|
||||
if _, ok := constants.NewStaticFieldsTraces[key.Key]; !ok {
|
||||
key = constants.NewStaticFieldsTraces[constants.OldToNewTraceFieldsMap[key.Key]]
|
||||
// It should have a mapping in OldToNewTraceFieldsMap
|
||||
if _, ok := constants.OldToNewTraceFieldsMap[key.Key]; ok {
|
||||
key = constants.NewStaticFieldsTraces[constants.OldToNewTraceFieldsMap[key.Key]]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ func Test_getSelectLabels(t *testing.T) {
|
||||
want: " name as `name`, `resource_string_service_name` as `service_name`",
|
||||
},
|
||||
{
|
||||
name: "depricated Columns",
|
||||
name: "deprecated Columns",
|
||||
args: args{
|
||||
groupBy: []v3.AttributeKey{
|
||||
{Key: "spanKind", DataType: v3.AttributeKeyDataTypeString},
|
||||
@@ -209,19 +209,20 @@ func Test_getSelectLabels(t *testing.T) {
|
||||
{Key: "spanID", DataType: v3.AttributeKeyDataTypeString},
|
||||
{Key: "serviceName", DataType: v3.AttributeKeyDataTypeString},
|
||||
{Key: "httpRoute", DataType: v3.AttributeKeyDataTypeString},
|
||||
{Key: "kind", DataType: v3.AttributeKeyDataTypeInt64},
|
||||
},
|
||||
},
|
||||
want: " kind_string as `spanKind`, status_message as `statusMessage`, trace_id as `traceID`, span_id as `spanID`, resource_string_service$$name as `serviceName`, attribute_string_http$$route as `httpRoute`",
|
||||
want: " kind_string as `spanKind`, status_message as `statusMessage`, trace_id as `traceID`, span_id as `spanID`, resource_string_service$$name as `serviceName`, attribute_string_http$$route as `httpRoute`, kind as `kind`",
|
||||
},
|
||||
{
|
||||
name: "non depricated Columns",
|
||||
args: args{
|
||||
groupBy: []v3.AttributeKey{
|
||||
{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag},
|
||||
{Key: "kind", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag},
|
||||
{Key: "kind_string", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag},
|
||||
},
|
||||
},
|
||||
want: " name as `name`, kind as `kind`",
|
||||
want: " name as `name`, kind_string as `kind_string`",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -362,11 +362,6 @@ var NewStaticFieldsTraces = map[string]v3.AttributeKey{
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
IsColumn: true,
|
||||
},
|
||||
"kind": {
|
||||
Key: "kind",
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
IsColumn: true,
|
||||
},
|
||||
"kind_string": {
|
||||
Key: "kind_string",
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
@@ -521,7 +516,7 @@ var DeprecatedStaticFieldsTraces = map[string]v3.AttributeKey{
|
||||
},
|
||||
"kind": {
|
||||
Key: "kind",
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
DataType: v3.AttributeKeyDataTypeInt64,
|
||||
IsColumn: true,
|
||||
},
|
||||
"spanKind": {
|
||||
|
||||
@@ -41,13 +41,6 @@ var (
|
||||
FieldContext: telemetrytypes.FieldContextSpan,
|
||||
FieldDataType: telemetrytypes.FieldDataTypeString,
|
||||
},
|
||||
"kind": {
|
||||
Name: "kind",
|
||||
Description: "Span kind enum (number). Use `kind_string` instead. Learn more [here](https://opentelemetry.io/docs/concepts/signals/traces/#span-kind)",
|
||||
Signal: telemetrytypes.SignalTraces,
|
||||
FieldContext: telemetrytypes.FieldContextSpan,
|
||||
FieldDataType: telemetrytypes.FieldDataTypeNumber,
|
||||
},
|
||||
"kind_string": {
|
||||
Name: "kind_string",
|
||||
Description: "Span kind enum (string). Known values are ['Client', 'Server', 'Internal', 'Producer', 'Consumer']. Learn more [here](https://opentelemetry.io/docs/concepts/signals/traces/#span-kind)",
|
||||
@@ -134,6 +127,13 @@ var (
|
||||
FieldContext: telemetrytypes.FieldContextSpan,
|
||||
FieldDataType: telemetrytypes.FieldDataTypeString,
|
||||
},
|
||||
"kind": {
|
||||
Name: "kind",
|
||||
Description: "Span kind enum (number). Use `kind_string` instead. Learn more [here](https://opentelemetry.io/docs/concepts/signals/traces/#span-kind)",
|
||||
Signal: telemetrytypes.SignalTraces,
|
||||
FieldContext: telemetrytypes.FieldContextSpan,
|
||||
FieldDataType: telemetrytypes.FieldDataTypeNumber,
|
||||
},
|
||||
}
|
||||
|
||||
CalculatedFields = map[string]telemetrytypes.TelemetryFieldKey{
|
||||
|
||||
@@ -200,7 +200,10 @@ func (m *defaultFieldMapper) getColumn(
|
||||
return indexV3Columns[oldToNew[key.Name]], nil
|
||||
}
|
||||
if _, ok := IntrinsicFieldsDeprecated[key.Name]; ok {
|
||||
return indexV3Columns[oldToNew[key.Name]], nil
|
||||
// Check if we have a mapping for the deprecated intrinsic field
|
||||
if _, ok := indexV3Columns[oldToNew[key.Name]]; ok {
|
||||
return indexV3Columns[oldToNew[key.Name]], nil
|
||||
}
|
||||
}
|
||||
|
||||
if col, ok := indexV3Columns[key.Name]; ok {
|
||||
|
||||
@@ -659,6 +659,22 @@ func TestStatementBuilderTraceQuery(t *testing.T) {
|
||||
},
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
name: "list query with deprecated filter field",
|
||||
requestType: qbtypes.RequestTypeTrace,
|
||||
query: qbtypes.QueryBuilderQuery[qbtypes.TraceAggregation]{
|
||||
Signal: telemetrytypes.SignalTraces,
|
||||
Filter: &qbtypes.Filter{
|
||||
Expression: "kind = 2 or spanKind = 'Server'",
|
||||
},
|
||||
Limit: 10,
|
||||
},
|
||||
expected: qbtypes.Statement{
|
||||
Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_traces.distributed_traces_v3_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?), __toe AS (SELECT trace_id FROM signoz_traces.distributed_signoz_index_v3 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (toFloat64(kind) = ? OR kind_string = ?) AND timestamp >= ? AND timestamp < ? AND ts_bucket_start >= ? AND ts_bucket_start <= ?), __toe_duration_sorted AS (SELECT trace_id, duration_nano, resource_string_service$$name as `service.name`, name FROM signoz_traces.distributed_signoz_index_v3 WHERE parent_span_id = '' AND trace_id GLOBAL IN __toe AND timestamp >= ? AND timestamp < ? AND ts_bucket_start >= ? AND ts_bucket_start <= ? ORDER BY duration_nano DESC LIMIT 1 BY trace_id) SELECT __toe_duration_sorted.`service.name` AS `service.name`, __toe_duration_sorted.name AS `name`, count() AS span_count, __toe_duration_sorted.duration_nano AS `duration_nano`, __toe_duration_sorted.trace_id AS `trace_id` FROM __toe INNER JOIN __toe_duration_sorted ON __toe.trace_id = __toe_duration_sorted.trace_id GROUP BY trace_id, duration_nano, name, `service.name` ORDER BY duration_nano DESC LIMIT 1 BY trace_id LIMIT ? SETTINGS distributed_product_mode='allow', max_memory_usage=10000000000",
|
||||
Args: []any{uint64(1747945619), uint64(1747983448), float64(2), "Server", "1747947419000000000", "1747983448000000000", uint64(1747945619), uint64(1747983448), "1747947419000000000", "1747983448000000000", uint64(1747945619), uint64(1747983448), 10},
|
||||
},
|
||||
expectedErr: nil,
|
||||
},
|
||||
}
|
||||
|
||||
fm := NewFieldMapper()
|
||||
|
||||
Reference in New Issue
Block a user