mjsax commented on code in PR #21160:
URL: https://github.com/apache/kafka/pull/21160#discussion_r2625578553
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java:
##########
@@ -887,6 +899,7 @@ public void run() {
boolean cleanRun = false;
try {
taskManager.init();
+ initLatencyWindowsIfNeeded(System.currentTimeMillis());
Review Comment:
We should never call `System.curentTimeMillis()`directly, but use
`time.milliseconds()` instead.
##########
docs/upgrade.html:
##########
@@ -66,6 +66,12 @@ <h5><a id="upgrade_420_notable"
href="#upgrade_420_notable">Notable changes in 4
<li>The behavior of
<code>org.apache.kafka.streams.KafkaStreams#removeStreamThread</code> has been
changed. The consumer has no longer remove once <code>removeStreamThread</code>
finished.
Instead, consumer would be kicked off from the group after
<code>org.apache.kafka.streams.processor.internals.StreamThread</code>
completes its <code>run</code> function.
</li>
+ <li>TThe streams thread metrics <code>commit-ratio</code>,
<code>process-ratio</code>, <code>punctuate-ratio</code>, and
<code>poll-ratio</code> have been updated.
Review Comment:
```suggestion
<li>The streams thread metrics <code>commit-ratio</code>,
<code>process-ratio</code>, <code>punctuate-ratio</code>, and
<code>poll-ratio</code> have been updated.
```
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java:
##########
@@ -2103,4 +2120,46 @@ 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);
Review Comment:
nit: remove unnecessary `this.`
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java:
##########
@@ -2103,4 +2120,46 @@ 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);
Review Comment:
as above
##########
docs/upgrade.html:
##########
@@ -66,6 +66,12 @@ <h5><a id="upgrade_420_notable"
href="#upgrade_420_notable">Notable changes in 4
<li>The behavior of
<code>org.apache.kafka.streams.KafkaStreams#removeStreamThread</code> has been
changed. The consumer has no longer remove once <code>removeStreamThread</code>
finished.
Instead, consumer would be kicked off from the group after
<code>org.apache.kafka.streams.processor.internals.StreamThread</code>
completes its <code>run</code> function.
</li>
+ <li>TThe streams thread metrics <code>commit-ratio</code>,
<code>process-ratio</code>, <code>punctuate-ratio</code>, and
<code>poll-ratio</code> have been updated.
Review Comment:
@bbejeck Did you intent `docs/upgrade.html`? Not sure if this change it too
small for top level upgrade notes and if `docs/streams/upgrade-guide.html`
would be better suited?
--
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]