{"record":{"id":"49b4e0bb7b9dc6ec","repo":"SigNoz/signoz","slug":"couldn-t-query-clickhouse-for-received-metrics-sta","errorCode":null,"errorMessage":"couldn't query clickhouse for received metrics status: %w","messagePattern":"couldn't query clickhouse for received metrics status: %w","errorType":"exception","errorClass":"model.InternalError","httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":3404,"sourceCode":"\t\tgroup by metric_name\n\t\tlimit 1\n\t\t`, signozMetricDBName, signozTSTableNameV4, whereClause,\n\t\t\tsignozMetricDBName, signozTSTableNameV4Reduced, whereClause,\n\t\t)\n\t} else {\n\t\tquery = fmt.Sprintf(`\n\t\tSELECT metric_name, anyLast(labels), max(unix_milli)\n\t\tfrom %s.%s\n\t\twhere %s\n\t\tgroup by metric_name\n\t\tlimit 1\n\t\t`, signozMetricDBName, signozTSTableNameV4, whereClause,\n\t\t)\n\t}\n\n\trows, err := r.db.Query(ctx, query)\n\tif err != nil {\n\t\treturn nil, model.InternalError(fmt.Errorf(\n\t\t\t\"couldn't query clickhouse for received metrics status: %w\", err,\n\t\t))\n\t}\n\tdefer rows.Close()\n\n\tvar result *model.MetricStatus\n\n\tif rows.Next() {\n\n\t\tresult = &model.MetricStatus{}\n\t\tvar labelsJson string\n\n\t\terr := rows.Scan(\n\t\t\t&result.MetricName,\n\t\t\t&labelsJson,\n\t\t\t&result.LastReceivedTsMillis,\n\t\t)\n\t\tif err != nil {","sourceCodeStart":3386,"sourceCodeEnd":3422,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L3386-L3422","documentation":"Internal error wrapping a ClickHouse query failure while fetching the latest-received status of a metric (last received timestamp and labels) from the time_series table. The %w wrapping preserves the underlying ClickHouse error for diagnosis.","triggerScenarios":"GetLatestReceivedMetric successfully validated names but the status query failed — bad quoted metric name interpolation, missing time_series table, timeout, or connection failure.","commonSituations":"Metric names with special characters breaking utils.ClickHouseFormattedValue quoting; ClickHouse unavailable; schema migration pending after SigNoz upgrade.","solutions":["Read the wrapped ClickHouse error to classify cause","Test the same query manually in clickhouse-client with the quoted metric names","Verify signoz_metrics.time_series exists and query-service version matches schema","Check ClickHouse health and query-service connection pool metrics"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify table exists before heavy calls\nif !chTableExists(ctx, db, \"signoz_metrics\", \"time_series\") {\n    return errors.New(\"time_series table missing; run migrations\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var ich *chError\n    if errors.As(err, &ich) && ich.Transient() { retry(ctx, call) }\n}","preventionTips":["Quote metric names with ClickHouseFormattedValue","Health-check ClickHouse before batch operations"],"tags":["signoz","clickhouse","query-failed","internal-error"],"backgroundTag":"database-query-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}