This is an automated email from the ASF dual-hosted git repository.
frankchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new c5fcc03bdf PrometheusEmitter NullPointerException fix (#13286)
c5fcc03bdf is described below
commit c5fcc03bdfd50f2624ba0a3d39f0d5e5e856deef
Author: DENNIS <[email protected]>
AuthorDate: Thu Nov 3 18:50:27 2022 +0800
PrometheusEmitter NullPointerException fix (#13286)
* PrometheusEmitter NullPointerException fix
* Improved null value judgment in pushMetric
* Delete meaningless judgments about namespace
* Delete unnecessary @Nullable above namespace attribute
---
.../emitter/prometheus/PrometheusEmitter.java | 25 +++++++++++-----------
.../prometheus/PrometheusEmitterConfig.java | 1 -
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
index 8a9840191d..c2909ec319 100644
---
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
+++
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
@@ -57,7 +57,7 @@ public class PrometheusEmitter implements Emitter
private HTTPServer server;
private PushGateway pushGateway;
- private String identifier;
+ private volatile String identifier;
private ScheduledExecutorService exec;
static PrometheusEmitter of(PrometheusEmitterConfig config)
@@ -170,27 +170,26 @@ public class PrometheusEmitter implements Emitter
private void pushMetric()
{
+ if (pushGateway == null || identifier == null) {
+ return;
+ }
Map<String, DimensionsAndCollector> map = metrics.getRegisteredMetrics();
CollectorRegistry metrics = new CollectorRegistry();
- if (config.getNamespace() != null) {
- try {
- for (DimensionsAndCollector collector : map.values()) {
- metrics.register(collector.getCollector());
- }
- pushGateway.push(metrics, config.getNamespace(),
ImmutableMap.of(config.getNamespace(), identifier));
- }
- catch (IOException e) {
- log.error(e, "Unable to push prometheus metrics to pushGateway");
+ try {
+ for (DimensionsAndCollector collector : map.values()) {
+ metrics.register(collector.getCollector());
}
+ pushGateway.push(metrics, config.getNamespace(),
ImmutableMap.of(config.getNamespace(), identifier));
+ }
+ catch (IOException e) {
+ log.error(e, "Unable to push prometheus metrics to pushGateway");
}
}
@Override
public void flush()
{
- if (pushGateway != null) {
- pushMetric();
- }
+ pushMetric();
}
@Override
diff --git
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitterConfig.java
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitterConfig.java
index ac4e15355a..2dbbe5662b 100644
---
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitterConfig.java
+++
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitterConfig.java
@@ -39,7 +39,6 @@ public class PrometheusEmitterConfig
private final Strategy strategy;
@JsonProperty
- @Nullable
private final String namespace;
@JsonProperty
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]