Skip to content

Commit

Permalink
SOLR-17530: Metrics: fix Prometheus response writer for TLOG & PULL r…
Browse files Browse the repository at this point in the history
…eplicas (#2795)

The new Prometheus response writer wasn't detecting TLOG or PULL replicas properly.

---------

Co-authored-by: David Smiley <[email protected]>
  • Loading branch information
mlbiscoc and dsmiley authored Nov 2, 2024
1 parent 4d482b2 commit 206904e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ led to the suppression of exceptions. (Andrey Bozhko)

* SOLR-11318: Introduce unit testing for AssertTool. (Eric Pugh, Jason Gerlowski)

================== 9.7.1 ==================
Bug Fixes
---------------------
* SOLR-17530: Metrics: Thew new Prometheus response writer wasn't detecting TLOG or PULL replicas properly.
(Matthew Biscocho)

================== 9.7.0 ==================
New Features
---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ enum CoreCategory {
CORE
}

Pattern CLOUD_CORE_PATTERN = Pattern.compile("^core_(.*)_(shard[0-9]+)_(replica_n[0-9]+)$");
Pattern CLOUD_CORE_PATTERN = Pattern.compile("^core_(.*)_(shard[0-9]+)_(replica_.[0-9]+)$");
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.solr.metrics;

import static org.apache.solr.metrics.prometheus.core.PrometheusCoreFormatterInfo.CLOUD_CORE_PATTERN;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
Expand All @@ -29,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.metrics.prometheus.SolrMetric;
import org.apache.solr.metrics.prometheus.SolrPrometheusFormatter;
Expand Down Expand Up @@ -141,6 +144,34 @@ public Map<String, Number> getValue() {
assertEquals(expectedLabels, actual.getLabels());
}

@Test
public void testCloudCorePattern() {
String coreName = "core_test-core_shard2_replica_t123";
Matcher m = CLOUD_CORE_PATTERN.matcher(coreName);
assertTrue(m.find());
assertEquals("test-core", m.group(1));
assertEquals("shard2", m.group(2));
assertEquals("replica_t123", m.group(3));

coreName = "core_foo_bar_shard24_replica_p8";
m = CLOUD_CORE_PATTERN.matcher(coreName);
assertTrue(m.matches());
assertEquals("foo_bar", m.group(1));
assertEquals("shard24", m.group(2));
assertEquals("replica_p8", m.group(3));
}

@Test
public void testBadCloudCorePattern() {
String badCoreName = "core_solrtest_shard100_replica_xyz23";
Matcher m = CLOUD_CORE_PATTERN.matcher(badCoreName);
assertFalse(m.matches());

badCoreName = "core_solrtest_shards100_replica_x23";
m = CLOUD_CORE_PATTERN.matcher(badCoreName);
assertFalse(m.matches());
}

static class TestSolrPrometheusFormatter extends SolrPrometheusFormatter {
@Override
public void exportDropwizardMetric(Metric dropwizardMetric, String metricName) {}
Expand Down

0 comments on commit 206904e

Please sign in to comment.