diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 01c70c17409..bfe09f10354 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -11,9 +11,7 @@ Bug Fixes * SOLR-17515: Http2SolrClient now sets its 'AuthenticationStore' in all circumstances, preventing NPE's when used with a HttpClientBuilderFactory (Jason Gerlowski) -Dependency Upgrades ---------------------- -(No changes) +* SOLR-17530: Metrics: The new Prometheus response writer wasn't detecting TLOG or PULL replicas properly. (Matthew Biscocho) ================== 9.7.0 ================== New Features diff --git a/solr/core/src/java/org/apache/solr/metrics/prometheus/core/PrometheusCoreFormatterInfo.java b/solr/core/src/java/org/apache/solr/metrics/prometheus/core/PrometheusCoreFormatterInfo.java index 51f5d9765d9..baa7be5898b 100644 --- a/solr/core/src/java/org/apache/solr/metrics/prometheus/core/PrometheusCoreFormatterInfo.java +++ b/solr/core/src/java/org/apache/solr/metrics/prometheus/core/PrometheusCoreFormatterInfo.java @@ -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]+)$"); } diff --git a/solr/core/src/test/org/apache/solr/metrics/SolrPrometheusFormatterTest.java b/solr/core/src/test/org/apache/solr/metrics/SolrPrometheusFormatterTest.java index 186c83c8a91..5c62910b43f 100644 --- a/solr/core/src/test/org/apache/solr/metrics/SolrPrometheusFormatterTest.java +++ b/solr/core/src/test/org/apache/solr/metrics/SolrPrometheusFormatterTest.java @@ -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; @@ -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; @@ -141,6 +144,34 @@ public Map 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) {}