{"record":{"id":"ae9f65939a3b65e9","repo":"SigNoz/signoz","slug":"atleast-1-metric-name-must-be-specified","errorCode":null,"errorMessage":"atleast 1 metric name must be specified","messagePattern":"atleast 1 metric name must be specified","errorType":"validation","errorClass":"model.BadRequest","httpStatus":400,"severity":"warning","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":3349,"sourceCode":"\t\tUnit:        unit,\n\t\tType:        metricType,\n\t\tIsMonotonic: isMonotonic,\n\t\tTemporality: temporality,\n\t}, nil\n}\n\nfunc (r *ClickHouseReader) GetLatestReceivedMetric(\n\tctx context.Context, orgID valuer.UUID, metricNames []string, labelValues map[string]string,\n) (*model.MetricStatus, *model.ApiError) {\n\tctx = ctxtypes.NewContextWithCommentVals(ctx, map[string]string{\n\t\tinstrumentationtypes.TelemetrySignal:  telemetrytypes.SignalMetrics.StringValue(),\n\t\tinstrumentationtypes.CodeNamespace:    \"clickhouse-reader\",\n\t\tinstrumentationtypes.CodeFunctionName: \"GetLatestReceivedMetric\",\n\t})\n\t// at least 1 metric name must be specified.\n\t// this query can be too slow otherwise.\n\tif len(metricNames) < 1 {\n\t\treturn nil, model.BadRequest(fmt.Errorf(\"atleast 1 metric name must be specified\"))\n\t}\n\n\tquotedMetricNames := []string{}\n\tfor _, m := range metricNames {\n\t\tquotedMetricNames = append(quotedMetricNames, utils.ClickHouseFormattedValue(m))\n\t}\n\tcommaSeparatedMetricNames := strings.Join(quotedMetricNames, \", \")\n\n\twhereClauseParts := []string{\n\t\tfmt.Sprintf(`metric_name in (%s)`, commaSeparatedMetricNames),\n\t}\n\n\tfor label, val := range labelValues {\n\t\twhereClauseParts = append(\n\t\t\twhereClauseParts,\n\t\t\tfmt.Sprintf(`JSONExtractString(labels, '%s') = '%s'`, label, val),\n\t\t)\n\t}","sourceCodeStart":3331,"sourceCodeEnd":3367,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L3331-L3367","documentation":"Bad-request error from GetLatestReceivedMetric: the API requires at least one metric name because querying latest-received status without a name filter would scan the entire metrics store and be prohibitively slow. It's a deliberate guard, not an infrastructure failure.","triggerScenarios":"Calling GetLatestReceivedMetric (or its HTTP handler) with an empty metricNames slice, e.g. an API request missing the metricNames query param or passing an empty array.","commonSituations":"Frontend bug sending empty metricNames; curl/API scripts omitting the required param; programmatic callers defaulting to empty slice.","solutions":["Pass at least one concrete metric name in the request","Fix the caller to validate required params before invoking the API","Check the handler's param parsing if the client did send names"],"exampleFix":"// before\nstatus, apiErr := reader.GetLatestReceivedMetric(ctx, []string{})\n\n// after\nif len(metricNames) == 0 {\n    return nil, model.BadRequest(fmt.Errorf(\"atleast 1 metric name must be specified\"))\n}\nstatus, apiErr := reader.GetLatestReceivedMetric(ctx, metricNames)","handlingStrategy":"validation","validationCode":"if len(metricNames) == 0 {\n    return model.BadRequest(fmt.Errorf(\"atleast 1 metric name must be specified\"))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate required params at API boundary","Write tests for empty-list requests"],"tags":["signoz","validation","bad-request","metrics"],"backgroundTag":"missing-required-parameter","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}