Skip to content

Commit 0f8a2e5

Browse files
committed
Prototyping of OpenTelemetry metric plugin
1 parent 2188ca2 commit 0f8a2e5

File tree

31 files changed

+1352
-22
lines changed

31 files changed

+1352
-22
lines changed

pinot-common/src/main/java/org/apache/pinot/common/metrics/AbstractMetrics.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ public void addCallbackGaugeIfNeeded(final String metricName, final Callable<Lon
603603
public void addCallbackGauge(final String metricName, final Callable<Long> valueCallback) {
604604
PinotMetricUtils
605605
.makeGauge(_metricsRegistry, PinotMetricUtils.makePinotMetricName(_clazz, _metricPrefix + metricName),
606-
PinotMetricUtils.makePinotGauge(avoid -> {
606+
PinotMetricUtils.makePinotGauge(_metricPrefix + metricName, avoid -> {
607607
try {
608608
return valueCallback.call();
609609
} catch (Exception e) {
@@ -680,7 +680,7 @@ public void setOrUpdateTableGauge(final String tableName, final G gauge,
680680
public void setOrUpdateGauge(final String metricName, long value) {
681681
PinotGauge<Long> pinotGauge = PinotMetricUtils.makeGauge(_metricsRegistry,
682682
PinotMetricUtils.makePinotMetricName(_clazz, _metricPrefix + metricName),
683-
PinotMetricUtils.makePinotGauge(avoid -> value));
683+
PinotMetricUtils.makePinotGauge(_metricPrefix + metricName, avoid -> value));
684684
pinotGauge.setValue(value);
685685
}
686686

@@ -694,7 +694,7 @@ public void setOrUpdateGauge(final String metricName, long value) {
694694
public void setOrUpdateGauge(final String metricName, final Supplier<Long> valueSupplier) {
695695
PinotGauge<Long> pinotGauge = PinotMetricUtils.makeGauge(_metricsRegistry,
696696
PinotMetricUtils.makePinotMetricName(_clazz, _metricPrefix + metricName),
697-
PinotMetricUtils.makePinotGauge(avoid -> valueSupplier.get()));
697+
PinotMetricUtils.makePinotGauge(_metricPrefix + metricName, avoid -> valueSupplier.get()));
698698
pinotGauge.setValueSupplier(valueSupplier);
699699
}
700700

@@ -704,7 +704,7 @@ public void setOrUpdateGauge(final String metricName, final Supplier<Long> value
704704
public void setOrUpdateGauge(final String metricName, final LongSupplier valueSupplier) {
705705
PinotGauge<Long> pinotGauge = PinotMetricUtils.makeGauge(_metricsRegistry,
706706
PinotMetricUtils.makePinotMetricName(_clazz, _metricPrefix + metricName),
707-
PinotMetricUtils.makePinotGauge(avoid -> valueSupplier.getAsLong()));
707+
PinotMetricUtils.makePinotGauge(_metricPrefix + metricName, avoid -> valueSupplier.getAsLong()));
708708
pinotGauge.setValueSupplier((Supplier<Long>) () -> (Long) valueSupplier.getAsLong());
709709
}
710710

pinot-common/src/main/java/org/apache/pinot/common/metrics/ValidationMetrics.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Long value() {
5757

5858
@Override
5959
public Object getGauge() {
60-
return PinotMetricUtils.makePinotGauge(avoid -> value()).getGauge();
60+
return PinotMetricUtils.makePinotGauge(_key, avoid -> value()).getGauge();
6161
}
6262

6363
@Override
@@ -92,10 +92,9 @@ public Double value() {
9292
public Object getMetric() {
9393
return getGauge();
9494
}
95-
9695
@Override
9796
public Object getGauge() {
98-
return PinotMetricUtils.makePinotGauge(avoid -> value()).getGauge();
97+
return PinotMetricUtils.makePinotGauge(_key, avoid -> value()).getGauge();
9998
}
10099
}
101100

pinot-common/src/test/java/org/apache/pinot/common/metrics/prometheus/PinotPrometheusMetricsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void setupTest() {
9797
_pinotMetricsFactory.getClass().getCanonicalName());
9898
PinotMetricUtils.init(pinotConfiguration);
9999

100-
_pinotMetricsFactory.makePinotJmxReporter(_pinotMetricsFactory.getPinotMetricsRegistry()).start();
100+
_pinotMetricsFactory.makePinotMetricReporter(_pinotMetricsFactory.getPinotMetricsRegistry()).start();
101101
_httpClient = new HttpClient();
102102
_httpServer = startExporter();
103103
}

pinot-plugins/pinot-metrics/pinot-compound-metrics/src/main/java/org/apache/pinot/plugin/metrics/compound/CompoundPinotJmxReporter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
import org.apache.pinot.spi.metrics.PinotJmxReporter;
2323

2424

25+
/**
26+
* CompoundPinotJmxReporter is a composite reporter that aggregates multiple PinotJmxReporters.
27+
* @deprecated Use {@link org.apache.pinot.plugin.metrics.compound.CompoundPinotMetricReporter} instead.
28+
*/
29+
@Deprecated
2530
public class CompoundPinotJmxReporter implements PinotJmxReporter {
2631
private final List<PinotJmxReporter> _reporters;
2732

pinot-plugins/pinot-metrics/pinot-compound-metrics/src/main/java/org/apache/pinot/plugin/metrics/compound/CompoundPinotMetricRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public <T> PinotGauge<T> newGauge(PinotMetricName name, PinotGauge<T> gauge) {
7272
return (PinotGauge<T>) _allMetrics.computeIfAbsent(name,
7373
key -> new CompoundPinotGauge<>(map(key, (reg, subName) -> reg.newGauge(subName, null))));
7474
} else {
75-
CompoundPinotGauge<T> compoundGauge =
76-
(CompoundPinotGauge<T>) PinotMetricUtils.makePinotGauge(avoid -> gauge.value());
75+
CompoundPinotGauge<T> compoundGauge = (CompoundPinotGauge<T>) PinotMetricUtils
76+
.makePinotGauge(name.getMetricName().toString(), avoid -> gauge.value());
7777

7878
Function<PinotMetricName, CompoundPinotGauge<?>> creator = key -> {
7979
CompoundPinotMetricName compoundName = (CompoundPinotMetricName) key;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.apache.pinot.plugin.metrics.compound;
2+
3+
import java.util.List;
4+
import org.apache.pinot.spi.metrics.PinotMetricReporter;
5+
6+
7+
/**
8+
* CompoundPinotMetricReporter delegates metric reporting to each of the reporters in the list.
9+
*/
10+
public class CompoundPinotMetricReporter implements PinotMetricReporter {
11+
private final List<PinotMetricReporter> _reporters;
12+
13+
public CompoundPinotMetricReporter(List<PinotMetricReporter> reporters) {
14+
_reporters = reporters;
15+
}
16+
17+
@Override
18+
public void start() {
19+
for (PinotMetricReporter reporter : _reporters) {
20+
reporter.start();
21+
}
22+
}
23+
}

pinot-plugins/pinot-metrics/pinot-compound-metrics/src/main/java/org/apache/pinot/plugin/metrics/compound/CompoundPinotMetricsFactory.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.pinot.spi.metrics.PinotGauge;
3636
import org.apache.pinot.spi.metrics.PinotJmxReporter;
3737
import org.apache.pinot.spi.metrics.PinotMetricName;
38+
import org.apache.pinot.spi.metrics.PinotMetricReporter;
3839
import org.apache.pinot.spi.metrics.PinotMetricUtils;
3940
import org.apache.pinot.spi.metrics.PinotMetricsRegistry;
4041
import org.apache.pinot.spi.plugin.PluginManager;
@@ -144,6 +145,7 @@ public PinotMetricName makePinotMetricName(Class<?> klass, String name) {
144145
}
145146

146147
@Override
148+
@Deprecated
147149
public <T> PinotGauge<T> makePinotGauge(Function<Void, T> condition) {
148150
List<PinotGauge<T>> gauges = _factories.stream()
149151
.map(factory -> factory.makePinotGauge(condition))
@@ -152,6 +154,18 @@ public <T> PinotGauge<T> makePinotGauge(Function<Void, T> condition) {
152154
}
153155

154156
@Override
157+
public <T> PinotGauge<T> makePinotGauge(String metricName, Function<Void, T> condition) {
158+
List<PinotGauge<T>> gauges = _factories.stream()
159+
.map(factory -> factory.makePinotGauge(metricName, condition))
160+
.collect(Collectors.toList());
161+
return new CompoundPinotGauge<T>(gauges);
162+
}
163+
164+
/**
165+
* @deprecated Use {@link #makePinotMetricReporter(PinotMetricsRegistry)} instead.
166+
*/
167+
@Override
168+
@Deprecated
155169
public PinotJmxReporter makePinotJmxReporter(PinotMetricsRegistry metricsRegistry) {
156170
CompoundPinotMetricRegistry registry = (CompoundPinotMetricRegistry) metricsRegistry;
157171
List<PinotMetricsRegistry> subRegistries = registry.getRegistries();
@@ -164,12 +178,30 @@ public PinotJmxReporter makePinotJmxReporter(PinotMetricsRegistry metricsRegistr
164178
PinotMetricsFactory subFactory = _factories.get(i);
165179
PinotMetricsRegistry subRegistry = subRegistries.get(i);
166180

167-
subJmx.add(subFactory.makePinotJmxReporter(subRegistry));
181+
subJmx.add(subFactory.makePinotMetricReporter(subRegistry));
168182
}
169183

170184
return new CompoundPinotJmxReporter(subJmx);
171185
}
172186

187+
public PinotMetricReporter makePinotMetricReporter(PinotMetricsRegistry metricsRegistry) {
188+
CompoundPinotMetricRegistry registry = (CompoundPinotMetricRegistry) metricsRegistry;
189+
List<PinotMetricsRegistry> subRegistries = registry.getRegistries();
190+
Preconditions.checkState(subRegistries.size() == _factories.size(),
191+
"Number of registries ({}) should be the same than the number of factories ({})",
192+
subRegistries.size(), _factories.size());
193+
194+
ArrayList<PinotMetricReporter> subReporter = new ArrayList<>(_factories.size());
195+
for (int i = 0; i < _factories.size(); i++) {
196+
PinotMetricsFactory subFactory = _factories.get(i);
197+
PinotMetricsRegistry subRegistry = subRegistries.get(i);
198+
199+
subReporter.add(subFactory.makePinotMetricReporter(subRegistry));
200+
}
201+
202+
return new CompoundPinotMetricReporter(subReporter);
203+
}
204+
173205
@Override
174206
public String getMetricsFactoryName() {
175207
return "Compound";

pinot-plugins/pinot-metrics/pinot-dropwizard/src/main/java/org/apache/pinot/plugin/metrics/dropwizard/DropwizardJmxReporter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
import com.codahale.metrics.MetricRegistry;
2222
import com.codahale.metrics.jmx.JmxReporter;
23-
import org.apache.pinot.spi.metrics.PinotJmxReporter;
23+
import org.apache.pinot.spi.metrics.PinotMetricReporter;
2424
import org.apache.pinot.spi.metrics.PinotMetricsRegistry;
2525

26-
27-
public class DropwizardJmxReporter implements PinotJmxReporter {
26+
/**
27+
* DropwizardJmxReporter is a metric reporter that exposes metrics to JMX using Dropwizard's JmxReporter.
28+
*/
29+
public class DropwizardJmxReporter implements PinotMetricReporter {
2830
private final JmxReporter _jmxReporter;
2931

3032
public DropwizardJmxReporter(PinotMetricsRegistry metricsRegistry, String domainName) {

pinot-plugins/pinot-metrics/pinot-dropwizard/src/main/java/org/apache/pinot/plugin/metrics/dropwizard/DropwizardMetricsFactory.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.pinot.spi.metrics.PinotGauge;
2727
import org.apache.pinot.spi.metrics.PinotJmxReporter;
2828
import org.apache.pinot.spi.metrics.PinotMetricName;
29+
import org.apache.pinot.spi.metrics.PinotMetricReporter;
2930
import org.apache.pinot.spi.metrics.PinotMetricsRegistry;
3031

3132

@@ -57,15 +58,28 @@ public PinotMetricName makePinotMetricName(Class<?> klass, String name) {
5758
}
5859

5960
@Override
61+
@Deprecated
6062
public <T> PinotGauge<T> makePinotGauge(Function<Void, T> condition) {
6163
return new DropwizardGauge<T>(condition);
6264
}
6365

66+
@Override
67+
public <T> PinotGauge<T> makePinotGauge(String metricName, Function<Void, T> condition) {
68+
return new DropwizardGauge<T>(condition);
69+
}
70+
71+
/**
72+
* @deprecated Use {@link #makePinotMetricReporter(PinotMetricsRegistry)} instead.
73+
*/
6474
@Override
6575
public PinotJmxReporter makePinotJmxReporter(PinotMetricsRegistry metricsRegistry) {
6676
return new DropwizardJmxReporter(metricsRegistry, _domainName);
6777
}
6878

79+
public PinotMetricReporter makePinotMetricReporter(PinotMetricsRegistry metricsRegistry) {
80+
return new DropwizardJmxReporter(metricsRegistry, _domainName);
81+
}
82+
6983
@Override
7084
public String getMetricsFactoryName() {
7185
return "Dropwizard";
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
<parent>
25+
<artifactId>pinot-metrics</artifactId>
26+
<groupId>org.apache.pinot</groupId>
27+
<version>1.4.0-SNAPSHOT</version>
28+
</parent>
29+
30+
<artifactId>pinot-open-telemetry</artifactId>
31+
<name>Pinot OpenTelemetry Metrics</name>
32+
<url>https://pinot.apache.org/</url>
33+
<properties>
34+
<pinot.root>${basedir}/../../..</pinot.root>
35+
<shade.phase.prop>package</shade.phase.prop>
36+
</properties>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>com.google.auto.service</groupId>
41+
<artifactId>auto-service-annotations</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>io.opentelemetry</groupId>
45+
<artifactId>opentelemetry-api</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>io.opentelemetry</groupId>
49+
<artifactId>opentelemetry-sdk</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>io.opentelemetry</groupId>
53+
<artifactId>opentelemetry-exporter-common</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>io.opentelemetry</groupId>
57+
<artifactId>opentelemetry-exporter-logging</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>io.opentelemetry</groupId>
61+
<artifactId>opentelemetry-exporter-otlp</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.apache.pinot</groupId>
65+
<artifactId>pinot-common</artifactId>
66+
</dependency>
67+
</dependencies>
68+
69+
<profiles>
70+
<profile>
71+
<id>pinot-fastdev</id>
72+
<properties>
73+
<shade.phase.prop>none</shade.phase.prop>
74+
</properties>
75+
</profile>
76+
</profiles>
77+
78+
</project>

0 commit comments

Comments
 (0)