mjsax commented on code in PR #21160:
URL: https://github.com/apache/kafka/pull/21160#discussion_r2621259835


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java:
##########
@@ -2142,4 +2154,80 @@ Admin adminClient() {
     Optional<StreamsRebalanceData> streamsRebalanceData() {
         return streamsRebalanceData;
     }
+
+    /**
+     * Initialize both WindowedSum instances at exactly the same timestamp so
+     * their windows are aligned from the very beginning.
+     */
+    private void initLatencyWindowsIfNeeded(final long now) {
+        if (!latencyWindowsInitialized) {
+            // Start both windows at the same instant with a zero record
+            pollLatencyWindowedSum.record(metricsConfig, 0.0, now);
+            this.totalCommitLatencyWindowedSum.record(metricsConfig, 0, now);
+            this.processLatencyWindowedSum.record(metricsConfig, 0, now);
+            this.punctuateLatencyWindowedSum.record(metricsConfig, 0, now);
+            runOnceLatencyWindowedSum.record(metricsConfig, 0.0, now);
+            latencyWindowsInitialized = true;
+        }
+    }
+
+    private void recordWindowedSum(final long now,
+                                   final double pollLatency,
+                                   final double totalCommitLatency,
+                                   final double processLatency,
+                                   final double punctuateLatency,
+                                   final double runOnceLatency) {
+        this.pollLatencyWindowedSum.record(metricsConfig, pollLatency, now);
+        this.totalCommitLatencyWindowedSum.record(metricsConfig, 
totalCommitLatency, now);
+        this.processLatencyWindowedSum.record(metricsConfig, processLatency, 
now);
+        this.punctuateLatencyWindowedSum.record(metricsConfig, 
punctuateLatency, now);
+        this.runOnceLatencyWindowedSum.record(metricsConfig, runOnceLatency, 
now);
+    }
+
+    private void recordPollRatio(final long now) {

Review Comment:
   It seems `recordPollRatio` and `recordCommitRatio` are more or less the 
exact some code, and the same code is also almost duplicated inside 
`recordAllRatios`.
   
   Would it make sense to have a single `recordRatio(long now, WindowedSum 
metric)` method to avoid code duplication, and just pass in 
`pollLatencyWindow`, or `commitLatencyWindow` etc...



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to