Skip to content

Commit

Permalink
Merge pull request #530 from Channyboy/528-metricNameQuery
Browse files Browse the repository at this point in the history
Check if metric exists in scope when querying across scopes
  • Loading branch information
Channyboy authored Aug 31, 2022
2 parents d761d04 + c7188c1 commit 9b22731
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ else if (scope != null && metricName != null) {
*/
else if (scope == null && metricName != null) {
output = exporter.exportOneMetricAcrossScopes(metricName);

if (output == null || output.isEmpty() || output.length() == 0) {
responder.respondWith(404, "Metric " + metricName + " not found in any scope ",
Collections.emptyMap());
return;
}
}
/*
* Something went wrong :(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public String exportOneMetricAcrossScopes(String name) {
StringBuilder sb = new StringBuilder();
for (MeterRegistry meterRegistry : prometheusRegistryList) {
PrometheusMeterRegistry promMeterRegistry = (PrometheusMeterRegistry) meterRegistry;

//Skip scrape if meter doesn't contain this metric
if (promMeterRegistry.find(name).meter() == null) {
continue;
}

/*
* For each Prometheus registry found:
* 1. Calculate potential formatted names
Expand Down

0 comments on commit 9b22731

Please sign in to comment.