Skip to content

Commit

Permalink
Surround NPE in PscSourceReaderMetrics with try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffxiang committed Oct 30, 2024
1 parent 8c9ebbe commit 5b19053
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,18 @@ public void removeRecordsLagMetric(TopicUriPartition tp) {
*/
public void updateNumBytesInCounter() {
if (this.bytesConsumedTotalMetric != null && this.bytesConsumedTotalMetric.metricValue() != null) {
long bytesConsumedUntilNow =
((Number) this.bytesConsumedTotalMetric.metricValue()).longValue();
long bytesConsumedSinceLastUpdate = bytesConsumedUntilNow - latestBytesConsumedTotal;
this.sourceReaderMetricGroup
.getIOMetricGroup()
.getNumBytesInCounter()
.inc(bytesConsumedSinceLastUpdate);
latestBytesConsumedTotal = bytesConsumedUntilNow;
try {
long bytesConsumedUntilNow =
((Number) this.bytesConsumedTotalMetric.metricValue()).longValue();
long bytesConsumedSinceLastUpdate = bytesConsumedUntilNow - latestBytesConsumedTotal;
this.sourceReaderMetricGroup
.getIOMetricGroup()
.getNumBytesInCounter()
.inc(bytesConsumedSinceLastUpdate);
latestBytesConsumedTotal = bytesConsumedUntilNow;
} catch (Exception e) {
LOG.warn("Failed to update numBytesInCounter", e);
}
}
}

Expand Down

0 comments on commit 5b19053

Please sign in to comment.