Skip to content

Commit

Permalink
SOLR-17368: Fix TestPrometheusResponseWriter by clearing registries (#…
Browse files Browse the repository at this point in the history
…2613)

SharedMetricRegistries.clear()
Parse numeric value based on if tags exist


Co-authored-by: Matthew Biscocho <mbiscocho@bloomberg.net>
Co-authored-by: David Smiley <dsmiley@salesforce.com>
  • Loading branch information
3 people authored Aug 3, 2024
1 parent 759b94f commit 14375b6
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import com.codahale.metrics.SettableGauge;
import com.codahale.metrics.SharedMetricRegistries;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.List;
Expand All @@ -34,6 +35,7 @@
import org.apache.solr.metrics.SolrMetricManager;
import org.apache.solr.util.ExternalPaths;
import org.apache.solr.util.SolrJettyTestRule;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
Expand All @@ -47,6 +49,8 @@ public class TestPrometheusResponseWriter extends SolrTestCaseJ4 {

@BeforeClass
public static void beforeClass() throws Exception {
SharedMetricRegistries.clear();

solrClientTestRule.startSolr(LuceneTestCase.createTempDir());
solrClientTestRule.newCollection().withConfigSet(ExternalPaths.DEFAULT_CONFIGSET).create();
var cc = solrClientTestRule.getCoreContainer();
Expand All @@ -62,6 +66,11 @@ public static void beforeClass() throws Exception {
registerGauge(manager, "solr.jvm", "gc.dummyMetrics.count");
}

@AfterClass
public static void clearMetricsRegistries() {
SharedMetricRegistries.clear();
}

@Test
public void testPrometheusStructureOutput() throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams();
Expand All @@ -78,7 +87,12 @@ public void testPrometheusStructureOutput() throws Exception {
output.lines().filter(line -> !line.startsWith("#")).collect(Collectors.toList());
filteredResponse.forEach(
(actualMetric) -> {
String actualValue = actualMetric.substring(actualMetric.lastIndexOf("} ") + 1);
String actualValue;
if (actualMetric.contains("}")) {
actualValue = actualMetric.substring(actualMetric.lastIndexOf("} ") + 1);
} else {
actualValue = actualMetric.split(" ")[1];
}
assertTrue(
"All metrics should start with 'solr_metrics_'",
actualMetric.startsWith("solr_metrics_"));
Expand Down

0 comments on commit 14375b6

Please sign in to comment.