{"record":{"id":"af02c22199f965e8","repo":"SonarSource/sonarqube","slug":"the-following-metric-keys-are-not-found-s","errorCode":null,"errorMessage":"The following metric keys are not found: %s","messagePattern":"The following metric keys are not found: (.+?)","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java","lineNumber":190,"sourceCode":"      String pullRequest = request.getPullRequest();\n      ComponentDto component = loadComponent(dbSession, request, branch, pullRequest);\n      checkPermissions(component);\n      SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.branchUuid()).orElse(null);\n\n      List<MetricDto> metrics = searchMetrics(dbSession, new HashSet<>(withRemovedMetricAlias(request.getMetricKeys())));\n      MeasureDto measureDto = searchMeasures(dbSession, component, metrics);\n\n      Measures.Period period = snapshotToWsPeriods(analysis).orElse(null);\n      return buildResponse(dbSession, request, component, measureDto, metrics, period, request.getMetricKeys());\n    }\n  }\n\n  public List<MetricDto> searchMetrics(DbSession dbSession, Set<String> metricKeys) {\n    List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, metricKeys);\n    if (metrics.size() < metricKeys.size()) {\n      Set<String> foundMetricKeys = metrics.stream().map(MetricDto::getKey).collect(Collectors.toSet());\n      Set<String> missingMetricKeys = metricKeys.stream().filter(m -> !foundMetricKeys.contains(m)).collect(Collectors.toSet());\n      throw new NotFoundException(format(\"The following metric keys are not found: %s\", String.join(\", \", missingMetricKeys)));\n    }\n\n    return metrics;\n  }\n\n  @CheckForNull\n  private MeasureDto searchMeasures(DbSession dbSession, ComponentDto component, Collection<MetricDto> metrics) {\n    MeasureDto measureDto = dbClient.measureDao().selectByComponentUuid(dbSession, component.uuid()).orElse(null);\n    addBestValuesToMeasures(measureDto, component, metrics);\n    return measureDto;\n  }\n\n  /**\n   * Conditions for best value measure:\n   * <ul>\n   * <li>component is a production file or test file</li>\n   * <li>metric is optimized for best value</li>\n   * </ul>","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java#L172-L208","documentation":"ComponentAction.searchMetrics loads the requested metric keys from the metrics DAO and, if fewer metrics come back than were requested, computes the missing keys and throws NotFoundException listing them. This means one or more 'metricKeys' supplied to the component measures WS action do not exist in the database.","triggerScenarios":"Calling api/measures/component with a metricKeys parameter containing a key that has no matching row in the metrics table (typo, custom metric deleted, plugin metric unavailable).","commonSituations":"Typos in metric keys (e.g. 'code_smells' vs 'code_smells'); referencing custom metrics after a plugin was uninstalled; hard-coded dashboards broken after upgrading SonarQube and metric renames.","solutions":["Compare the error's list of missing keys against the request's metricKeys and fix or remove the misspelled ones.","Verify each key exists via api/metrics/search before calling the component endpoint.","Reinstall/enable the plugin providing custom metrics if a plugin metric is missing.","Update hard-coded dashboards/scripts after SonarQube upgrades where metrics were renamed or removed."],"exampleFix":"// before\nGET api/measures/component?component=my-app&metricKeys=ncloc,bogus_metric\n// after\nGET api/measures/component?component=my-app&metricKeys=ncloc,sqale_rating","handlingStrategy":"validation","validationCode":"const known = new Set((await api.get('/api/metrics/search', {ps: 500})).metrics.map(m => m.key));\nconst missing = requestedKeys.filter(k => !known.has(k));\nif (missing.length) throw new Error('Unknown metric keys: ' + missing.join(', '));","typeGuard":null,"tryCatchPattern":"try { ... } catch (e) { if (e.response?.status === 404 && /not found/.test(e.message)) { /* strip listed keys and retry */ } else throw e; }","preventionTips":["Resolve metric keys dynamically from api/metrics/search instead of hard-coding.","Re-verify keys after SonarQube upgrades and plugin changes."],"tags":["webapi","metrics","not-found","sonarqube"],"backgroundTag":"resource-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}