SonarSource/sonarqube · error · IllegalArgumentException
Metrics %s are not found
Error message
Metrics %s are not found
What it means
SearchHistoryAction.searchMetrics validates that all up-to-date requested metrics exist before computing measure history, throwing IllegalArgumentException with the unfound metric keys. Unlike the component endpoints this surfaces as a 400 (bad request) rather than 404, but the cause is identical: requested metric keys absent from the metrics table.
Source
Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java:268
SnapshotQuery dbQuery = new SnapshotQuery()
.setRootComponentUuid(component.branchUuid())
.setStatus(STATUS_PROCESSED)
.setSort(SORT_FIELD.BY_DATE, SORT_ORDER.ASC);
ofNullable(request.getFrom()).ifPresent(from -> dbQuery.setCreatedAfter(parseStartingDateOrDateTime(from).getTime()));
ofNullable(request.getTo()).ifPresent(to -> dbQuery.setCreatedBefore(parseEndingDateOrDateTime(to).getTime() + 1_000L));
return dbClient.snapshotDao().selectAnalysesByQuery(dbSession, dbQuery);
}
private List<MetricDto> searchMetrics(DbSession dbSession, SearchHistoryRequest request) {
List<String> upToDateRequestedMetrics = RemovedMetricConverter.withRemovedMetricAlias(request.getMetrics());
List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, upToDateRequestedMetrics);
if (upToDateRequestedMetrics.size() > metrics.size()) {
Set<String> requestedMetrics = new HashSet<>(upToDateRequestedMetrics);
Set<String> foundMetrics = metrics.stream().map(MetricDto::getKey).collect(Collectors.toSet());
Set<String> unfoundMetrics = Sets.difference(requestedMetrics, foundMetrics).immutableCopy();
throw new IllegalArgumentException(format("Metrics %s are not found", String.join(", ", unfoundMetrics)));
}
return metrics;
}
private ComponentDto loadComponent(DbSession dbSession, SearchHistoryRequest request) {
String componentKey = request.getComponent();
String branch = request.getBranch();
String pullRequest = request.getPullRequest();
return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest);
}
static class SearchHistoryRequest {
private final String component;
private final String branch;
private final String pullRequest;
private final List<String> metrics;
private final String from;View on GitHub (pinned to 184c821202)
Solutions
- Fix or drop the metric keys listed in the 'Metrics ... are not found' message.
- List valid metrics via api/metrics/search and retry with confirmed keys.
- Restore the plugin defining custom metrics before querying their history.
- Wrap the call defensively in scripts and validate keys against the metrics list.
Example fix
// before GET api/measures/search_history?component=my-app&metrics=ncol // after GET api/measures/search_history?component=my-app&metrics=ncloc
Defensive patterns
Strategy: validation
Validate before calling
const known = new Set((await api.get('/api/metrics/search', {ps: 500})).metrics.map(m => m.key));
const missing = keys.filter(k => !known.has(k));
if (missing.length) throw new Error('Metrics not found: ' + missing.join(', ')); Try / catch
try { ... } catch (e) { if (String(e.message).includes('are not found')) { const missing = e.message.match(/Metrics (.*) are not found/)[1].split(', '); ... } throw e; } Prevention
- Fetch the metric list at script startup and intersect it with your requested keys.
- After plugin removal, audit history queries that depended on its metrics.
When it happens
Trigger: Calling api/measures/search_history with a metrics parameter containing one or more keys that selectByKeys does not resolve in the database.
Common situations: History dashboards referencing renamed/deleted metrics after upgrades; misspelled keys in CI scripts; custom metrics from a plugin that was removed so historical queries fail.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- The following metric keys are not found: %s
- The following metric keys are not found: %s
- There is no metric with key=%s
- Project '%s' not found
- Issue with key '%s' does not exist
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/d66d3f6e7563775e.
Report an issue: GitHub.