PrometheusEmitter NullPointerException fix#13286
Conversation
| private HTTPServer server; | ||
| private PushGateway pushGateway; | ||
| private String identifier; | ||
| private volatile String identifier; |
There was a problem hiding this comment.
Curious to understand the race here.
There was a problem hiding this comment.
The existence of multiple threads calling emitMetric will modify the identifier. Even if the identifier is modified countless times, there will always be only one result, which is an idempotent design.
Currently only the thread of PrometheusPushGatewayEmitter will read the value of identifier. In order to guarantee the visibility of the reading thread, I use volatile to decorate the identifier.
In addition, there is an inefficient way to use LinkedBlockingQueue to achieve safe publishing. This is how InfluxdbEmitter is implemented.
|
Thanks for the fix. From the assignment statement, I don't understand how could identifier = (userDims.get("task") == null ? metricEvent.getHost() : (String) userDims.get("task")); |
|
I realized that there are two conditions that may lead to
|
There was a problem hiding this comment.
LGTM. @FrankChen021 Please let me know if it's okay from your side as well.
Yeah, the 2nd case is the reason. private void pushMetric()
{
if ( pushGateway == null || identifier == null) {
return ;
}
...Another point(not relevant to this PR) is, checking if namespace is null is meaningless since it's guaranteed it won't be null. @JsonCreator
public PrometheusEmitterConfig(
...
)
{
...
this.namespace = namespace != null ? namespace : "druid"; |
|
@FrankChen021 I debugged. If |
|
Thanks for the cleanup. |
FrankChen021
left a comment
There was a problem hiding this comment.
LGTM. Let's wait for the CI to complete.
Fixes #13285.
Description
PrometheusEmitter NullPointerException fix
Key changed/added classes in this PR
PrometheusEmitterThis PR has: