hachikuji commented on code in PR #13207:
URL: https://github.com/apache/kafka/pull/13207#discussion_r1099065953
##########
raft/src/main/java/org/apache/kafka/raft/internals/KafkaRaftMetrics.java:
##########
@@ -133,26 +131,27 @@ public KafkaRaftMetrics(Metrics metrics, String
metricGrpPrefix, QuorumState sta
"The average number of records appended per sec as the leader
of the raft quorum."),
new Rate(TimeUnit.SECONDS, new WindowedSum()));
- this.pollIdleSensor = metrics.sensor("poll-idle-ratio");
- this.pollIdleSensor.add(metrics.metricName("poll-idle-ratio-avg",
+ this.pollDurationSensor = metrics.sensor("poll-idle-ratio");
+ this.pollDurationSensor.add(metrics.metricName(
+ "poll-idle-ratio-avg",
metricGroupName,
- "The average fraction of time the client's poll() is idle as
opposed to waiting for the user code to process records."),
- new Avg());
+ "The ratio of time the Raft IO thread is idle as opposed to " +
+ "doing work (e.g. handling requests or replicating from
the leader)"
+ ),
+ new TimeRatio(1.0)
+ );
}
public void updatePollStart(long currentTimeMs) {
- if (pollEndMs.isPresent() && pollStartMs.isPresent()) {
- long pollTimeMs = Math.max(pollEndMs.getAsLong() -
pollStartMs.getAsLong(), 0L);
- long totalTimeMs = Math.max(currentTimeMs -
pollStartMs.getAsLong(), 1L);
- this.pollIdleSensor.record(pollTimeMs / (double) totalTimeMs,
currentTimeMs);
- }
-
this.pollStartMs = OptionalLong.of(currentTimeMs);
- this.pollEndMs = OptionalLong.empty();
}
public void updatePollEnd(long currentTimeMs) {
- this.pollEndMs = OptionalLong.of(currentTimeMs);
+ if (pollStartMs.isPresent()) {
+ long pollDurationMs = Math.max(currentTimeMs -
pollStartMs.getAsLong(), 0L);
Review Comment:
The clock we rely on is not monotonic, so it is possible to go backwards. It
seems better to handle this case gracefully with a default value than to crash
the IO thread.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org