Skip to content

Commit acde988

Browse files
author
mbiscocho
committed
Export jetty/jvm/node registry metrics
1 parent b8475f8 commit acde988

39 files changed

+1355
-294
lines changed

solr/core/src/java/org/apache/solr/handler/admin/MetricsHandler.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,18 @@ private NamedList<Object> handlePrometheusExport(SolrParams params) {
190190

191191
for (String registryName : requestedRegistries) {
192192
MetricRegistry dropwizardRegistry = metricManager.registry(registryName);
193-
// Currently only export Solr Core registries
194-
if (registryName.startsWith("solr.core")) {
195-
PrometheusResponseWriter.toPrometheus(
196-
dropwizardRegistry,
197-
registryName,
198-
metricFilters,
199-
mustMatchFilter,
200-
propertyFilter,
201-
false,
202-
false,
203-
true,
204-
(registry) -> {
205-
response.add(registryName, registry);
206-
});
207-
}
193+
PrometheusResponseWriter.toPrometheus(
194+
dropwizardRegistry,
195+
registryName,
196+
metricFilters,
197+
mustMatchFilter,
198+
propertyFilter,
199+
false,
200+
false,
201+
true,
202+
(registry) -> {
203+
response.add(registryName, registry);
204+
});
208205
}
209206
return response;
210207
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.solr.metrics.prometheus;
18+
19+
import com.codahale.metrics.Metric;
20+
import io.prometheus.metrics.model.snapshots.Labels;
21+
import java.util.ArrayList;
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
25+
/**
26+
* Base class is a wrapper to categorize and export {@link com.codahale.metrics.Metric} to {@link
27+
* io.prometheus.metrics.model.snapshots.DataPointSnapshot} and register to a {@link
28+
* SolrPrometheusExporter}. {@link com.codahale.metrics.MetricRegistry} does not support tags unlike
29+
* prometheus. Metrics registered to the registry need to be parsed out from the metric name to be
30+
* exported to {@link io.prometheus.metrics.model.snapshots.DataPointSnapshot}
31+
*/
32+
public abstract class SolrMetric {
33+
public Metric dropwizardMetric;
34+
public String metricName;
35+
public Map<String, String> labels = new HashMap<>();
36+
37+
public SolrMetric() {}
38+
39+
public SolrMetric(Metric dropwizardMetric, String metricName) {
40+
this.dropwizardMetric = dropwizardMetric;
41+
this.metricName = metricName;
42+
}
43+
44+
public abstract SolrMetric parseLabels();
45+
46+
public abstract void toPrometheus(SolrPrometheusExporter exporter);
47+
48+
public Labels getLabels() {
49+
return Labels.of(new ArrayList<>(labels.keySet()), new ArrayList<>(labels.values()));
50+
}
51+
}

solr/core/src/java/org/apache/solr/metrics/prometheus/core/SolrCoreNoOpMetric.java renamed to solr/core/src/java/org/apache/solr/metrics/prometheus/SolrNoOpMetric.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,16 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.solr.metrics.prometheus.core;
17+
package org.apache.solr.metrics.prometheus;
1818

19-
import com.codahale.metrics.Metric;
20-
import org.apache.solr.metrics.prometheus.SolrPrometheusCoreExporter;
21-
22-
public class SolrCoreNoOpMetric extends SolrCoreMetric {
23-
24-
public SolrCoreNoOpMetric(
25-
Metric dropwizardMetric, String coreName, String metricName, boolean cloudMode) {
26-
super(dropwizardMetric, coreName, metricName, cloudMode);
27-
}
19+
public class SolrNoOpMetric extends SolrMetric {
20+
public SolrNoOpMetric() {}
2821

2922
@Override
30-
public SolrCoreMetric parseLabels() {
23+
public SolrMetric parseLabels() {
3124
return this;
3225
}
3326

3427
@Override
35-
public void toPrometheus(SolrPrometheusCoreExporter exporter) {}
28+
public void toPrometheus(SolrPrometheusExporter exporter) {}
3629
}

solr/core/src/java/org/apache/solr/metrics/prometheus/SolrPrometheusExporter.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,21 @@ public SolrPrometheusExporter() {
4646

4747
/**
4848
* Export {@link Metric} to {@link io.prometheus.metrics.model.snapshots.MetricSnapshot} and
49-
* registers the Snapshot
49+
* register the Snapshot
5050
*
5151
* @param dropwizardMetric the {@link Metric} to be exported
5252
* @param metricName Dropwizard metric name
5353
*/
5454
public abstract void exportDropwizardMetric(Metric dropwizardMetric, String metricName);
5555

56+
/**
57+
* Categorize {@link Metric} based on the metric name
58+
*
59+
* @param dropwizardMetric the {@link Metric} to be exported
60+
* @param metricName Dropwizard metric name
61+
*/
62+
public abstract SolrMetric categorizeMetric(Metric dropwizardMetric, String metricName);
63+
5664
/**
5765
* Export {@link Meter} to {@link
5866
* io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot} and collect
@@ -99,6 +107,21 @@ public void exportTimer(String metricName, Timer dropwizardMetric, Labels labels
99107
collectGaugeDatapoint(metricName, dataPoint);
100108
}
101109

110+
/**
111+
* Export {@link Timer} ands its Count to {@link
112+
* io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot} and collect
113+
* datapoint
114+
*
115+
* @param metricName name of prometheus metric
116+
* @param dropwizardMetric the {@link Timer} to be exported
117+
* @param labels label names and values to record
118+
*/
119+
public void exportTimerCount(String metricName, Timer dropwizardMetric, Labels labels) {
120+
CounterSnapshot.CounterDataPointSnapshot dataPoint =
121+
createCounterDatapoint(dropwizardMetric.getCount(), labels);
122+
collectCounterDatapoint(metricName, dataPoint);
123+
}
124+
102125
/**
103126
* Export {@link com.codahale.metrics.Gauge} to {@link
104127
* io.prometheus.metrics.model.snapshots.GaugeSnapshot.GaugeDataPointSnapshot} and collect to

solr/core/src/java/org/apache/solr/metrics/prometheus/PrometheusCoreExporterInfo.java renamed to solr/core/src/java/org/apache/solr/metrics/prometheus/core/PrometheusCoreExporterInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.solr.metrics.prometheus;
17+
package org.apache.solr.metrics.prometheus.core;
1818

1919
import java.util.regex.Pattern;
2020

solr/core/src/java/org/apache/solr/metrics/prometheus/core/SolrCoreCacheMetric.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.codahale.metrics.Gauge;
2020
import com.codahale.metrics.Metric;
21-
import org.apache.solr.metrics.prometheus.SolrPrometheusCoreExporter;
21+
import org.apache.solr.metrics.prometheus.SolrPrometheusExporter;
2222

2323
/** Dropwizard metrics of name CACHE.* */
2424
public class SolrCoreCacheMetric extends SolrCoreMetric {
@@ -39,7 +39,7 @@ public SolrCoreMetric parseLabels() {
3939
}
4040

4141
@Override
42-
public void toPrometheus(SolrPrometheusCoreExporter exporter) {
42+
public void toPrometheus(SolrPrometheusExporter exporter) {
4343
if (dropwizardMetric instanceof Gauge) {
4444
exporter.exportGauge(CORE_CACHE_SEARCHER_METRICS, (Gauge<?>) dropwizardMetric, getLabels());
4545
}

solr/core/src/java/org/apache/solr/metrics/prometheus/core/SolrCoreHandlerMetric.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.codahale.metrics.Meter;
2222
import com.codahale.metrics.Metric;
2323
import com.codahale.metrics.Timer;
24-
import org.apache.solr.metrics.prometheus.SolrPrometheusCoreExporter;
24+
import org.apache.solr.metrics.prometheus.SolrPrometheusExporter;
2525

2626
/** Dropwizard metrics of name ADMIN/QUERY/UPDATE/REPLICATION.* */
2727
public class SolrCoreHandlerMetric extends SolrCoreMetric {
@@ -45,7 +45,7 @@ public SolrCoreMetric parseLabels() {
4545
}
4646

4747
@Override
48-
public void toPrometheus(SolrPrometheusCoreExporter exporter) {
48+
public void toPrometheus(SolrPrometheusExporter exporter) {
4949
if (dropwizardMetric instanceof Meter) {
5050
exporter.exportMeter(CORE_REQUESTS_TOTAL, (Meter) dropwizardMetric, getLabels());
5151
} else if (dropwizardMetric instanceof Counter) {

solr/core/src/java/org/apache/solr/metrics/prometheus/core/SolrCoreHighlighterMetric.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.codahale.metrics.Counter;
2020
import com.codahale.metrics.Metric;
21-
import org.apache.solr.metrics.prometheus.SolrPrometheusCoreExporter;
21+
import org.apache.solr.metrics.prometheus.SolrPrometheusExporter;
2222

2323
/** Dropwizard metrics of name HIGHLIGHTER.* */
2424
public class SolrCoreHighlighterMetric extends SolrCoreMetric {
@@ -38,7 +38,7 @@ public SolrCoreMetric parseLabels() {
3838
}
3939

4040
@Override
41-
public void toPrometheus(SolrPrometheusCoreExporter exporter) {
41+
public void toPrometheus(SolrPrometheusExporter exporter) {
4242
if (dropwizardMetric instanceof Counter) {
4343
exporter.exportCounter(CORE_HIGHLIGHER_METRICS, (Counter) dropwizardMetric, getLabels());
4444
}

solr/core/src/java/org/apache/solr/metrics/prometheus/core/SolrCoreIndexMetric.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.codahale.metrics.Gauge;
2020
import com.codahale.metrics.Metric;
21-
import org.apache.solr.metrics.prometheus.SolrPrometheusCoreExporter;
21+
import org.apache.solr.metrics.prometheus.SolrPrometheusExporter;
2222

2323
/** Dropwizard metrics of name INDEX.* */
2424
public class SolrCoreIndexMetric extends SolrCoreMetric {
@@ -35,7 +35,7 @@ public SolrCoreMetric parseLabels() {
3535
}
3636

3737
@Override
38-
public void toPrometheus(SolrPrometheusCoreExporter exporter) {
38+
public void toPrometheus(SolrPrometheusExporter exporter) {
3939
if (dropwizardMetric instanceof Gauge) {
4040
if (metricName.endsWith("sizeInBytes")) {
4141
exporter.exportGauge(CORE_INDEX_METRICS, (Gauge<?>) dropwizardMetric, getLabels());

solr/core/src/java/org/apache/solr/metrics/prometheus/core/SolrCoreMetric.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,27 @@
1616
*/
1717
package org.apache.solr.metrics.prometheus.core;
1818

19-
import static org.apache.solr.metrics.prometheus.PrometheusCoreExporterInfo.CLOUD_CORE_PATTERN;
19+
import static org.apache.solr.metrics.prometheus.core.PrometheusCoreExporterInfo.CLOUD_CORE_PATTERN;
2020

2121
import com.codahale.metrics.Metric;
22-
import io.prometheus.metrics.model.snapshots.Labels;
23-
import java.util.ArrayList;
24-
import java.util.HashMap;
25-
import java.util.Map;
2622
import java.util.regex.Matcher;
2723
import org.apache.solr.common.SolrException;
28-
import org.apache.solr.metrics.prometheus.SolrPrometheusCoreExporter;
24+
import org.apache.solr.metrics.prometheus.SolrMetric;
2925

30-
/**
31-
* Base class is a wrapper to categorize and export {@link com.codahale.metrics.Metric} to {@link
32-
* io.prometheus.metrics.model.snapshots.DataPointSnapshot} and register to a {@link
33-
* SolrPrometheusCoreExporter}. {@link com.codahale.metrics.MetricRegistry} does not support tags
34-
* unlike prometheus. Metrics registered to the registry need to be parsed out from the metric name
35-
* to be exported to {@link io.prometheus.metrics.model.snapshots.DataPointSnapshot}
36-
*/
37-
public abstract class SolrCoreMetric {
38-
public Metric dropwizardMetric;
26+
/** Base class is a wrapper to export a solr.core {@link com.codahale.metrics.Metric} */
27+
public abstract class SolrCoreMetric extends SolrMetric {
3928
public String coreName;
40-
public String metricName;
41-
public Map<String, String> labels = new HashMap<>();
4229

4330
public SolrCoreMetric(
4431
Metric dropwizardMetric, String coreName, String metricName, boolean cloudMode) {
45-
this.dropwizardMetric = dropwizardMetric;
32+
super(dropwizardMetric, metricName);
4633
this.coreName = coreName;
47-
this.metricName = metricName;
4834
labels.put("core", coreName);
4935
if (cloudMode) {
5036
appendCloudModeLabels();
5137
}
5238
}
5339

54-
public Labels getLabels() {
55-
return Labels.of(new ArrayList<>(labels.keySet()), new ArrayList<>(labels.values()));
56-
}
57-
58-
public abstract SolrCoreMetric parseLabels();
59-
60-
public abstract void toPrometheus(SolrPrometheusCoreExporter exporter);
61-
6240
private void appendCloudModeLabels() {
6341
Matcher m = CLOUD_CORE_PATTERN.matcher(coreName);
6442
if (m.find()) {

0 commit comments

Comments
 (0)