Skip to content

Commit

Permalink
MINOR: prevent NullPointerException of polling two metrics in Kafka C…
Browse files Browse the repository at this point in the history
…onnect

`assignmentSnapshot` may not always get initialized in some cases, especially when
Kafka connect is started from scratch. If `assignmentSnapshot` is not initialized,
blindly resgistering `assigned-connectors` and `assigned-tasks` metrics will cause
NullPointerException when the two metrics are polled.

the proposed fix is to return 0 in both measure() method if `assignmentSnapshot` is null
  • Loading branch information
Ning Zhang committed Nov 25, 2019
1 parent e58401b commit f70454e
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -306,13 +306,19 @@ public WorkerCoordinatorMetrics(Metrics metrics, String metricGrpPrefix) {
Measurable numConnectors = new Measurable() {
@Override
public double measure(MetricConfig config, long now) {
if (assignmentSnapshot == null) {
return 0.0;
}
return assignmentSnapshot.connectors().size();
}
};

Measurable numTasks = new Measurable() {
@Override
public double measure(MetricConfig config, long now) {
if (assignmentSnapshot == null) {
return 0.0;
}
return assignmentSnapshot.tasks().size();
}
};
Expand Down

0 comments on commit f70454e

Please sign in to comment.