mirror of https://github.com/apache/druid.git
PrometheusEmitter NullPointerException fix (#13286)
* PrometheusEmitter NullPointerException fix * Improved null value judgment in pushMetric * Delete meaningless judgments about namespace * Delete unnecessary @Nullable above namespace attribute
This commit is contained in:
parent
ccc55ef899
commit
c5fcc03bdf
|
@ -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
|
||||
|
|
|
@ -39,7 +39,6 @@ public class PrometheusEmitterConfig
|
|||
private final Strategy strategy;
|
||||
|
||||
@JsonProperty
|
||||
@Nullable
|
||||
private final String namespace;
|
||||
|
||||
@JsonProperty
|
||||
|
|
Loading…
Reference in New Issue