{"record":{"id":"bf4e10605260a727","repo":"SigNoz/signoz","slug":"error-while-querying-histogram-buckets-s","errorCode":null,"errorMessage":"error while querying histogram buckets: %s","messagePattern":"error while querying histogram buckets: (.+?)","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":3309,"sourceCode":"\t\t\t\t)\n\t\t\t\tGROUP BY le\n\t\t\t\tORDER BY le`, signozMetricDBName, signozTSTableNameV41Day, signozMetricDBName, signozTSTableNameV4Reduced)\n\t\t} else {\n\t\t\tquery = fmt.Sprintf(`\n\t\t\tSELECT JSONExtractString(labels, 'le') AS le\n\t\t\tFROM %s.%s\n\t\t\tWHERE metric_name = $1\n\t\t\t\tAND unix_milli >= $2\n\t\t\t\tAND type = 'Histogram'\n\t\t\t\tAND (JSONExtractString(labels, 'service_name') = $3 OR JSONExtractString(labels, 'service.name') = $4)\n\t\t\tGROUP BY le\n\t\t\tORDER BY le`, signozMetricDBName, signozTSTableNameV41Day)\n\t\t}\n\n\t\trows, err := r.db.Query(ctx, query, metricName, unixMilli, serviceName, serviceName)\n\t\tif err != nil {\n\t\t\tr.logger.Error(\"Error while querying histogram buckets\", errorsV2.Attr(err))\n\t\t\treturn nil, fmt.Errorf(\"error while querying histogram buckets: %s\", err.Error())\n\t\t}\n\t\tdefer rows.Close()\n\n\t\tfor rows.Next() {\n\t\t\tvar leStr string\n\t\t\tif err := rows.Scan(&leStr); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error while scanning le: %s\", err.Error())\n\t\t\t}\n\t\t\tle, err := strconv.ParseFloat(leStr, 64)\n\t\t\tif err != nil || math.IsInf(le, 0) {\n\t\t\t\tr.logger.Error(\"Invalid 'le' bucket value\", \"value\", leStr, errorsV2.Attr(err))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tleFloat64 = append(leFloat64, le)\n\t\t}\n\t}\n\n\treturn &v3.MetricMetadataResponse{","sourceCodeStart":3291,"sourceCodeEnd":3327,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L3291-L3327","documentation":"Raised when the ClickHouse query that fetches histogram 'le' bucket boundaries fails. The query targets the signoz_metrics time_series table filtered by metric name, unixMilli cutoff, and service name; any ClickHouse error (syntax from bad identifiers, timeout, unavailable table) surfaces here.","triggerScenarios":"Calling GetHistogramBucketList (or equivalent) with a metric name containing special characters that break the interpolated query; when signoz_metrics.time_series_v4_1_day doesn't exist (older SigNoz schema); ClickHouse timeout or memory limit exceeded.","commonSituations":"Version mismatch between query-service and ClickHouse schema (v4 tables not migrated); very wide service/metric filters scanning huge partitions; ClickHouse node restart or connection pool exhaustion; metric names with quotes injected via dashboard variables.","solutions":["Check wrapped ClickHouse error text for syntax vs timeout causes","Verify the v4 time_series table exists in signoz_metrics DB (migration status)","Sanitize/validate metric and service names before calling the API","Increase ClickHouse query timeout or max memory limit if the error is a resource timeout"],"exampleFix":"// before\nrows, err := r.db.Query(ctx, query, metricName, unixMilli, serviceName, serviceName)\n\n// after: validate inputs to avoid query construction issues\nif metricName == \"\" || serviceName == \"\" {\n    return nil, model.BadRequest(fmt.Errorf(\"metricName and serviceName are required\"))\n}\nrows, err := r.db.Query(ctx, query, metricName, unixMilli, serviceName, serviceName)","handlingStrategy":"retry","validationCode":"if metricName == \"\" || serviceName == \"\" {\n    return errors.New(\"metricName and serviceName are required\")\n}","typeGuard":null,"tryCatchPattern":"// Retry transient ClickHouse failures\nvar rows *sql.Rows\nfor attempt := 0; attempt < 3; attempt++ {\n    rows, err = r.db.Query(ctx, query, args...)\n    if err == nil { break }\n    time.Sleep(backoff(attempt))\n}","preventionTips":["Keep query-service and ClickHouse schema versions aligned","Sanitize metric/service names","Set adequate ClickHouse timeouts"],"tags":["signoz","clickhouse","histogram","query-failed"],"backgroundTag":"database-query-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}