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]>

(cherry picked from commit 206904e)
  • Loading branch information
mlbiscoc authored and dsmiley committed Nov 2, 2024
1 parent 88ecadd commit 1850608
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 1 addition & 3 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 1850608

Please sign in to comment.