uptrace / uptrace

Open source APM: OpenTelemetry traces, metrics, and logs
https://uptrace.dev/get/open-source-apm.html
GNU Affero General Public License v3.0
3.41k stars 175 forks source link

createSpanMetric failed DB::Exception: Column s.count is not under aggregate function and not in GROUP BY keys #403

Closed rgl closed 3 months ago

rgl commented 4 months ago

While trying to play with uptrace 1.7.6 and clickhouse-server 24.7.1.2915 at https://github.com/rgl/opentelemetry-uptrace-playground, uptrace fails while starting with the error:

error   metrics/init.go:43  initSpanMetrics failed  {"error": "createSpanMetric \"uptrace_tracing_events\" failed: createMatView failed: DB::Exception: Column s.count is not under aggregate function and not in GROUP BY keys.

The full error is:

uptrace-1  | [ch]  17:21:14.510   CREATE VIEW            6.62ms  CREATE MATERIALIZED VIEW "metrics_uptrace_tracing_events_mv" TO uptrace.datapoint_minutes AS SELECT s.project_id, 'uptrace_tracing_events' AS metric, toStartOfMinute(s.time) AS time, 'counter' AS instrument, xxHash64(arrayStringConcat([toString(s."system"), toString(s."group_id"), toString(s."name"), toString(s."host_name")], '-')) AS attrs_hash, ['_system', '_group_id', '_name', 'host_name'] AS string_keys, [toString(s."system"), toString(s."group_id"), toString(s."name"), toString(s."host_name")] AS string_values, toJSONString(map('display_name', toString(any(s."display_name")))) AS annotations, s."count" AS sum FROM uptrace.spans_index AS s WHERE (s.type IN ('message', 'other-events') = 1) GROUP BY s.project_id, toStartOfMinute(s.time), toString(s."system"), toString(s."group_id"), toString(s."name"), toString(s."host_name") SETTINGS allow_experimental_analyzer = 1     *ch.Error: DB::Exception: Column s.count is not under aggregate function and not in GROUP BY keys. In query SELECT s.project_id, 'uptrace_tracing_events' AS metric, toStartOfMinute(s.time) AS time, 'counter' AS instrument, xxHash64(arrayStringConcat([toString(s.system), toString(s.group_id), toString(s.name), toString(s.host_name)], '-')) AS attrs_hash, ['_system', '_group_id', '_name', 'host_name'] AS string_keys, [toString(s.system), toString(s.group_id), toString(s.name), toString(s.host_name)] AS string_values, toJSONString(map('display_name', toString(any(s.display_name)))) AS annotations, s.count AS sum FROM uptrace.spans_index AS s WHERE (s.type IN ('message', 'other-events')) = 1 GROUP BY s.project_id, toStartOfMinute(s.time), toString(s.system), toString(s.group_id), toString(s.name), toString(s.host_name) SETTINGS allow_experimental_analyzer = 1 (215) 
uptrace-1  | 2024-07-31T17:21:14.510Z   error   metrics/init.go:43  initSpanMetrics failed  {"error": "createSpanMetric \"uptrace_tracing_events\" failed: createMatView failed: DB::Exception: Column s.count is not under aggregate function and not in GROUP BY keys. In query SELECT s.project_id, 'uptrace_tracing_events' AS metric, toStartOfMinute(s.time) AS time, 'counter' AS instrument, xxHash64(arrayStringConcat([toString(s.system), toString(s.group_id), toString(s.name), toString(s.host_name)], '-')) AS attrs_hash, ['_system', '_group_id', '_name', 'host_name'] AS string_keys, [toString(s.system), toString(s.group_id), toString(s.name), toString(s.host_name)] AS string_values, toJSONString(map('display_name', toString(any(s.display_name)))) AS annotations, s.count AS sum FROM uptrace.spans_index AS s WHERE (s.type IN ('message', 'other-events')) = 1 GROUP BY s.project_id, toStartOfMinute(s.time), toString(s.system), toString(s.group_id), toString(s.name), toString(s.host_name) SETTINGS allow_experimental_analyzer = 1 (215)"}
uptrace-1  | github.com/uptrace/uptrace/pkg/metrics.Init
uptrace-1  |    github.com/uptrace/uptrace/pkg/metrics/init.go:43
uptrace-1  | main.init.func2
uptrace-1  |    github.com/uptrace/uptrace/cmd/uptrace/main.go:143
uptrace-1  | github.com/urfave/cli/v2.(*Command).Run
uptrace-1  |    github.com/urfave/cli/v2@v2.27.1/command.go:279
uptrace-1  | github.com/urfave/cli/v2.(*Command).Run
uptrace-1  |    github.com/urfave/cli/v2@v2.27.1/command.go:272
uptrace-1  | github.com/urfave/cli/v2.(*App).RunContext
uptrace-1  |    github.com/urfave/cli/v2@v2.27.1/app.go:337
uptrace-1  | github.com/urfave/cli/v2.(*App).Run
uptrace-1  |    github.com/urfave/cli/v2@v2.27.1/app.go:311
uptrace-1  | main.main
uptrace-1  |    github.com/uptrace/uptrace/cmd/uptrace/main.go:75
uptrace-1  | runtime.main
uptrace-1  |    runtime/proc.go:271

Any idea why is this happening?

vmihailenco commented 3 months ago

I would remove metrics_from_spans from your Uptrace config. Recent Uptrace versions provide the uptrace_tracing_events metric automatically.