Skip to content

Commit

Permalink
KAFKA-9219: prevent NullPointerException in Kafka Connect metrics (#7652
Browse files Browse the repository at this point in the history
)

`assignmentSnapshot` may take a moment to get initialized in some cases, especially when
Kafka Connect is started from scratch. While `assignmentSnapshot` is not initialized, return 0 in both `measure()` methods.

Reviewers: Mickael Maison <mickael.maison@gmail.com>, Edoardo Comar <ecomar@uk.ibm.com>
  • Loading branch information
ning2008wisc authored and mimaison committed Nov 27, 2019
1 parent d38b844 commit 88448f6
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 88448f6

Please sign in to comment.