{"record":{"id":"381a3d124e34aead","repo":"jaegertracing/jaeger","slug":"failed-executing-metrics-query-w","errorCode":null,"errorMessage":"failed executing metrics query: %w","messagePattern":"failed executing metrics query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/metricstore/elasticsearch/reader.go","lineNumber":224,"sourceCode":"\t\t}\n\t\tpercentileKey := fmt.Sprintf(\"%.1f\", percentileValue)\n\t\taggMapValue, ok := percentiles.Values[percentileKey]\n\t\tif !ok {\n\t\t\treturn math.NaN()\n\t\t}\n\t\treturn aggMapValue\n\t}\n\treturn bucketsToPoints(buckets, valueExtractor)\n}\n\n// executeSearch performs the Elasticsearch search.\nfunc (r MetricsReader) executeSearch(ctx context.Context, p MetricsQueryParams, timeRange TimeRange) (*esclient.SearchResponse, error) {\n\tspan := r.queryLogger.TraceQuery(ctx, p.metricName)\n\tdefer span.End()\n\n\tsearchResult, err := r.queryBuilder.Execute(ctx, p.boolQuery, p.aggQuery, timeRange)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"failed executing metrics query: %w\", err)\n\t\tr.queryLogger.LogErrorToSpan(span, err)\n\t\treturn nil, err\n\t}\n\n\tr.queryLogger.LogAndTraceResult(span, searchResult)\n\n\t// Return raw search result\n\treturn searchResult, nil\n}\n\nfunc calculateTimeRange(params *metricstore.BaseQueryParameters) (TimeRange, error) {\n\tif params == nil || params.EndTime == nil || params.Lookback == nil {\n\t\treturn TimeRange{}, errors.New(\"invalid parameters\")\n\t}\n\tendTime := *params.EndTime\n\tstartTime := endTime.Add(-*params.Lookback)\n\textendedStartTime := startTime.Add(-10 * time.Minute)\n","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/storage/metricstore/elasticsearch/reader.go#L206-L242","documentation":"MetricsReader.executeSearch runs the Elasticsearch metrics query (histograms, call rates, error rates) through the query builder. If the underlying Execute call fails — transport error, bad query, index missing, cluster unavailable — the error is wrapped as 'failed executing metrics query' and logged to the tracing span before being returned to GetLatencies/GetCallRates/GetErrorRates callers.","triggerScenarios":"Calling GetLatencies, GetCallRates, or GetErrorRates when the Elasticsearch/OpenSearch cluster is unreachable, the response index doesn't exist, the query DSL is rejected (HTTP 400), or the request times out.","commonSituations":"Wrong ES server address/credentials in config; jaeger-span indices rolled over or deleted by ILM before the metrics window; metricstore storage type misconfigured; network/DNS failure between Jaeger and ES.","solutions":["Inspect the wrapped cause (%w) for the concrete HTTP/transport error from Elasticsearch.","Verify ES connectivity and credentials (curl the cluster's /_cluster/health).","Confirm the target indices exist for the queried time range (ILM retention may have deleted them).","Retry with backoff if the cause is a transient network/timeout error."],"exampleFix":"// caller handling\nmetrics, err := reader.GetCallRates(ctx, params)\nif err != nil {\n  log.Printf(\"metrics query failed: %v\", err) // cause is wrapped, inspect it\n  return\n}","handlingStrategy":"retry","validationCode":"// before querying\nif err := esClient.Ping(ctx); err != nil {\n  return fmt.Errorf(\"elasticsearch unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"metrics, err := reader.GetCallRates(ctx, params)\nif err != nil {\n  if strings.Contains(err.Error(), \"failed executing metrics query\") {\n    // transient: retry with backoff; otherwise surface the wrapped cause\n    return retryWithBackoff(ctx, func() error { _, err = reader.GetCallRates(ctx, params); return err })\n  }\n  return err\n}","preventionTips":["Monitor ES cluster health and configure connection/auth settings before enabling the metrics store.","Keep ILM retention longer than the maximum metrics query window.","Log the wrapped cause (%w) — it contains the concrete HTTP status/transport error.","Add retry with backoff for transient network errors."],"tags":["elasticsearch","network","metrics","query"],"backgroundTag":"query-execution-failed","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}