Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: fix count aggregate attribute column name (#6613)

Nityananda Gohain0fbfb6b22b0e
diff --git a/pkg/query-service/app/traces/v4/query_builder.go b/pkg/query-service/app/traces/v4/query_builder.go
index 366f3f6ee4..d650e1cdaa 100644
--- a/pkg/query-service/app/traces/v4/query_builder.go
+++ b/pkg/query-service/app/traces/v4/query_builder.go
@@ -355,8 +355,9 @@ func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, panelType v3.
filterSubQuery = fmt.Sprintf("%s AND %s", filterSubQuery, subQuery)
}
} else {
- column := getColumnName(mq.AggregateAttribute)
- filterSubQuery = fmt.Sprintf("%s AND has(%s, '%s')", filterSubQuery, column, mq.AggregateAttribute.Key)
+ cType := getClickHouseTracesColumnType(mq.AggregateAttribute.Type)
+ cDataType := getClickHouseTracesColumnDataType(mq.AggregateAttribute.DataType)
+ filterSubQuery = fmt.Sprintf("%s AND mapContains(%s_%s, '%s')", filterSubQuery, cType, cDataType, mq.AggregateAttribute.Key)
}
}
op := "toFloat64(count())"
diff --git a/pkg/query-service/app/traces/v4/query_builder_test.go b/pkg/query-service/app/traces/v4/query_builder_test.go
index d29f77a74b..9db2e815f9 100644
--- a/pkg/query-service/app/traces/v4/query_builder_test.go
+++ b/pkg/query-service/app/traces/v4/query_builder_test.go
@@ -451,6 +451,62 @@ func Test_buildTracesQuery(t *testing.T) {
"AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND attributes_string['http.method'] = '100' AND mapContains(attributes_string, 'http.method') " +
"group by `http.method` order by `http.method` ASC",
},
+ {
+ name: "Test buildTracesQuery - count with attr",
+ args: args{
+ panelType: v3.PanelTypeTable,
+ start: 1680066360726210000,
+ end: 1680066458000000000,
+ step: 1000,
+ mq: &v3.BuilderQuery{
+ AggregateOperator: v3.AggregateOperatorCount,
+ AggregateAttribute: v3.AttributeKey{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag},
+ Filters: &v3.FilterSet{
+ Items: []v3.FilterItem{
+ {
+ Key: v3.AttributeKey{Key: "http.method", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag},
+ Value: 100,
+ Operator: v3.FilterOperatorEqual,
+ },
+ },
+ },
+ GroupBy: []v3.AttributeKey{{Key: "http.method", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag}},
+ OrderBy: []v3.OrderBy{
+ {ColumnName: "http.method", Order: "ASC"}},
+ },
+ },
+ want: "SELECT attributes_string['http.method'] as `http.method`, toFloat64(count()) as value from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " +
+ "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND attributes_string['http.method'] = '100' AND mapContains(attributes_string, 'http.method') AND mapContains(attributes_string, 'name') " +
+ "group by `http.method` order by `http.method` ASC",
+ },
+ {
+ name: "Test buildTracesQuery - count with mat attr",
+ args: args{
+ panelType: v3.PanelTypeTable,
+ start: 1680066360726210000,
+ end: 1680066458000000000,
+ step: 1000,
+ mq: &v3.BuilderQuery{
+ AggregateOperator: v3.AggregateOperatorCount,
+ AggregateAttribute: v3.AttributeKey{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true},
+ Filters: &v3.FilterSet{
+ Items: []v3.FilterItem{
+ {
+ Key: v3.AttributeKey{Key: "http.method", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag},
+ Value: 100,
+ Operator: v3.FilterOperatorEqual,
+ },
+ },
+ },
+ GroupBy: []v3.AttributeKey{{Key: "http.method", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag}},
+ OrderBy: []v3.OrderBy{
+ {ColumnName: "http.method", Order: "ASC"}},
+ },
+ },
+ want: "SELECT attributes_string['http.method'] as `http.method`, toFloat64(count()) as value from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " +
+ "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND attributes_string['http.method'] = '100' AND mapContains(attributes_string, 'http.method') AND name != '' " +
+ "group by `http.method` order by `http.method` ASC",
+ },
{
name: "Test buildTracesQuery",
args: args{
diff --git a/pkg/query-service/rules/threshold_rule.go b/pkg/query-service/rules/threshold_rule.go
index ad55083f8f..5b5f02a52c 100644
--- a/pkg/query-service/rules/threshold_rule.go
+++ b/pkg/query-service/rules/threshold_rule.go
@@ -73,8 +73,9 @@ func NewThresholdRule(
}
t := ThresholdRule{
- BaseRule: baseRule,
- version: p.Version,
+ BaseRule: baseRule,
+ version: p.Version,
+ useTraceNewSchema: useTraceNewSchema,
}
querierOption := querier.QuerierOptions{