emitskevich-blp commented on code in PR #15889:
URL: https://github.com/apache/kafka/pull/15889#discussion_r1593310007


##########
clients/src/main/java/org/apache/kafka/common/metrics/stats/SampledStat.java:
##########
@@ -106,44 +106,55 @@ public String toString() {
 
     public abstract double combine(List<Sample> samples, MetricConfig config, 
long now);
 
-    /* Timeout any windows that have expired in the absence of any events */
-    protected void purgeObsoleteSamples(MetricConfig config, long now) {
+    /**
+     * Purges any windows that started before the configured period.
+     * Returns the end of the latest purged window.
+     */
+    protected long purgeObsoleteSamples(MetricConfig config, long now) {
         long expireAge = config.samples() * config.timeWindowMs();
+        long purgedUpToMs = 0;
         for (Sample sample : samples) {
-            if (now - sample.lastWindowMs >= expireAge)
+            if (now - sample.startTimeMs >= expireAge) {
+                purgedUpToMs = Math.max(purgedUpToMs, 
sample.endTimeMs(config));
                 sample.reset(now);
+            }
         }
+        return purgedUpToMs;
     }
 
     protected static class Sample {
         public double initialValue;
         public long eventCount;
-        public long lastWindowMs;
+        public long startTimeMs;

Review Comment:
   It always played a role of start time. Not a functional change.



-- 
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

Reply via email to