You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "elkkhan (via GitHub)" <gi...@apache.org> on 2023/07/23 17:49:01 UTC

[GitHub] [kafka] elkkhan opened a new pull request, #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

elkkhan opened a new pull request, #14077:
URL: https://github.com/apache/kafka/pull/14077

   The replication offset lag is the difference of the last end offset of the source partition (LEO) the last replicated  source offset (LRO), +1 (to account for zero-based offset numbering) The offset lag is a difference (LEO-LRO), and its constituents are calculated at different points of time and place:
   
   LEO shall be calculated during source task's poll loop (ready to get it from the consumer) LRO shall be kept in an in-memory "cache", that is updated during the task's producer callback The difference shall be calculated when the freshest LEO acquired in the poll loop. The calculated amount shall be defined as a MirrorMaker metric.
   
   This would describe to amount of "to be replicated" number of records for a certain topic-partition.
   
   - Add missing test for replication-latency metric
   - Add missing test for record-byte metric
   - Add missing test for record-age metric
   - Add the metric logic to MirrorSourceTask
   - Add metric calculation &  reporting to MirrorSourceTask
   - Add tests for the new metric
   
   *More detailed description of your change,
   if necessary. The PR title and PR message become
   the squashed commit message, so use a separate
   comment to ping reviewers.*
   
   *Summary of testing strategy (including rationale)
   for the feature or bug fix. Unit and/or integration
   tests are expected for any behaviour change and
   system tests should be considered for larger changes.*
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KIP-971: Expose replication-offset-lag Mirror metric [kafka]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-2614791103

   This PR has been closed since it has not had any activity in 120 days. If you feel like this
   was a mistake, or you would like to continue working on it, please feel free to re-open the 
   PR and ask for a review.


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] C0urante commented on pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "C0urante (via GitHub)" <gi...@apache.org>.
C0urante commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-1647838883

   @elkkhan I think it was mentioned on the [Jira ticket](https://issues.apache.org/jira/browse/KAFKA-14112) that a KIP is required for new metrics; have you published a KIP for this 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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KIP-971: Expose replication-offset-lag Mirror metric [kafka]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-2563280598

   This PR is being marked as stale since it has not had any activity in 90 days. If you
   would like to keep this PR alive, please leave a comment asking for a review. If the PR has 
   merge conflicts, update it with the latest from the base branch.
   <p>
   If you are having difficulty finding a reviewer, please reach out on the 
   [mailing list](https://kafka.apache.org/contact).
   <p>
   If this PR is no longer valid or desired, please feel free to close it. If no activity
   occurs in the next 30 days, it will be automatically closed.


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KIP-971: Expose replication-offset-lag Mirror metric [kafka]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #14077: KIP-971: Expose replication-offset-lag Mirror metric
URL: https://github.com/apache/kafka/pull/14077


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] elkkhan commented on pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "elkkhan (via GitHub)" <gi...@apache.org>.
elkkhan commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-1663002964

   > @elkkhan I think it was mentioned on the [Jira ticket](https://issues.apache.org/jira/browse/KAFKA-14112) that a KIP is required for new metrics; have you published a KIP for this change?
   
   @C0urante nope, It completely skipped my mind. will publish the KIP soon - should I keep the PR here in the meantime or should I draft it for now?


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] elkkhan commented on a diff in pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "elkkhan (via GitHub)" <gi...@apache.org>.
elkkhan commented on code in PR #14077:
URL: https://github.com/apache/kafka/pull/14077#discussion_r1282447173


##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/AbstractWorkerSourceTask.java:
##########
@@ -108,7 +108,7 @@ public abstract class AbstractWorkerSourceTask extends WorkerTask {
 
     /**
      * Invoked when a record is about to be dispatched to the producer. May be invoked multiple times for the same
-     * record if retriable errors are encountered.
+     * record if retryable errors are encountered.

Review Comment:
   got it, i got fooled by intellij :)



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KIP-971: Expose replication-offset-lag Mirror metric [kafka]

Posted by "dinesh-murugiah (via GitHub)" <gi...@apache.org>.
dinesh-murugiah commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-3206037867

   @elkkhan @C0urante @hudeqi why this PR is closed , this would be a helpful feature to have 
   is it safe to cherry pick this PR for our use ?


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-14112: Expose replication-offset-lag Mirror metric [kafka]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-1872660155

   This PR is being marked as stale since it has not had any activity in 90 days. If you would like to keep this PR alive, please ask a committer for review. If the PR has  merge conflicts, please update it with the latest from trunk (or appropriate release branch) <p> If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed.


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] elkkhan commented on a diff in pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "elkkhan (via GitHub)" <gi...@apache.org>.
elkkhan commented on code in PR #14077:
URL: https://github.com/apache/kafka/pull/14077#discussion_r1314605208


##########
connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorSourceMetrics.java:
##########
@@ -104,12 +108,25 @@ class MirrorSourceMetrics implements AutoCloseable {
         replicationLatencyAvg = new MetricNameTemplate(
                 "replication-latency-ms-avg", SOURCE_CONNECTOR_GROUP,
                 "Average time it takes records to replicate from source to target cluster.", partitionTags);
+        replicationOffsetLag = new MetricNameTemplate(

Review Comment:
   @hudeqi I hear you now - we do have a disagreement about the lag definition and it was an oversight on my end. I will copy your reply over to the mailing thread and will answer there to keep the discussion in one place



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-14112: Expose replication-offset-lag Mirror metric [kafka]

Posted by "elkkhan (via GitHub)" <gi...@apache.org>.
elkkhan commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-1879907574

   Dropping the [vote link for KIP](https://lists.apache.org/thread/ftlnolcrh858dry89sjg06mdcdj9mrqv) here to keep the PR alive


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] C0urante commented on pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "C0urante (via GitHub)" <gi...@apache.org>.
C0urante commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-1664041929

   It's fine to leave the PR as-is :) 
   I won't personally be reviewing it until/unless a KIP gets approved, though.


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] elkkhan commented on pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "elkkhan (via GitHub)" <gi...@apache.org>.
elkkhan commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-1694346035

   hi @C0urante @viktorsomogyi!
   just FYI, here is the [KIP](https://cwiki.apache.org/confluence/display/KAFKA/KIP-971%3A+Expose+replication-offset-lag+MirrorMaker2+metric)


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KIP-971: Expose replication-offset-lag Mirror metric [kafka]

Posted by "elkkhan (via GitHub)" <gi...@apache.org>.
elkkhan commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-3215851828

   > @elkkhan @C0urante @hudeqi why this PR is closed , this would be a helpful feature to have is it safe to cherry pick this PR for our use ?
   
   @dinesh-murugiah I ended up abandoning this PR - I might get back at it at some point, but if you want to cherry pick this in the meantime, I'd recommend reading through [KIP-971](https://cwiki.apache.org/confluence/display/KAFKA/KIP-971%3A+Expose+replication-record-lag+MirrorMaker2+metric) and it's discussion thread as some performance concerns were raised there by @mimaison 


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] elkkhan commented on pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "elkkhan (via GitHub)" <gi...@apache.org>.
elkkhan commented on PR #14077:
URL: https://github.com/apache/kafka/pull/14077#issuecomment-1647429228

   @C0urante @viktorsomogyi - could you please take a look? thanks!


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] C0urante commented on a diff in pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "C0urante (via GitHub)" <gi...@apache.org>.
C0urante commented on code in PR #14077:
URL: https://github.com/apache/kafka/pull/14077#discussion_r1272212887


##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/AbstractWorkerSourceTask.java:
##########
@@ -108,7 +108,7 @@ public abstract class AbstractWorkerSourceTask extends WorkerTask {
 
     /**
      * Invoked when a record is about to be dispatched to the producer. May be invoked multiple times for the same
-     * record if retriable errors are encountered.
+     * record if retryable errors are encountered.

Review Comment:
   "Retriable" is correct and is used all over the code base ([here](https://github.com/apache/kafka/blob/4981fa939d588645401619bfc3e321dc523d10e7/clients/src/main/java/org/apache/kafka/common/errors/RetriableException.java) and [here](https://github.com/apache/kafka/blob/4981fa939d588645401619bfc3e321dc523d10e7/connect/api/src/main/java/org/apache/kafka/connect/errors/RetriableException.java), for example).



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] hudeqi commented on a diff in pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "hudeqi (via GitHub)" <gi...@apache.org>.
hudeqi commented on code in PR #14077:
URL: https://github.com/apache/kafka/pull/14077#discussion_r1314592488


##########
connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorSourceMetrics.java:
##########
@@ -104,12 +108,25 @@ class MirrorSourceMetrics implements AutoCloseable {
         replicationLatencyAvg = new MetricNameTemplate(
                 "replication-latency-ms-avg", SOURCE_CONNECTOR_GROUP,
                 "Average time it takes records to replicate from source to target cluster.", partitionTags);
+        replicationOffsetLag = new MetricNameTemplate(

Review Comment:
   I guess we have a disagreement about lag? My understanding of lag is: the real LEO of the source cluster partition minus the LEO that has been written to the target cluster. It seems that your definition of lag is: the lag between the mirror task getting data from consumption and writing it to the target cluster?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] hudeqi commented on a diff in pull request #14077: KAFKA-14112: Expose replication-offset-lag Mirror metric

Posted by "hudeqi (via GitHub)" <gi...@apache.org>.
hudeqi commented on code in PR #14077:
URL: https://github.com/apache/kafka/pull/14077#discussion_r1314583243


##########
connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorSourceTask.java:
##########
@@ -282,6 +285,38 @@ SourceRecord convertRecord(ConsumerRecord<byte[], byte[]> record) {
                 record.timestamp(), headers);
     }
 
+    //visible for testing
+    void reportReplicationOffsetLag(ConsumerRecords<byte[], byte[]> lastPolledRecords) {
+        Set<TopicPartition> partitions = lastPolledRecords.partitions();
+        partitions.forEach(p -> {
+            try {
+                long replicationOffsetLag = getReplicationOffsetLagForPartition(p, lastPolledRecords.records(p));
+                if (replicationOffsetLag < 0) {
+                    log.warn("Replication offset lag for partition {} is negative({}) - " +
+                            "skipping metric reporting for this partition.", p, replicationOffsetLag);
+                    return;
+                }
+                metrics.replicationOffsetLag(p, replicationOffsetLag + 1); //+1 to account for zero-based offset numbering
+            } catch (UnsupportedOperationException e) {
+                log.error("Failed to calculate replication offset lag for partition {}.", p, e);
+            }
+        });
+    }
+
+    private long getReplicationOffsetLagForPartition(TopicPartition partition,
+                                                     List<ConsumerRecord<byte[], byte[]>> lastPolledRecordsForPartition) {
+        ConsumerRecord<byte[], byte[]> lastPolledRecord =
+                lastPolledRecordsForPartition.get(lastPolledRecordsForPartition.size() - 1);
+        if (!lastPolledRecord.topic().equals(partition.topic()) || lastPolledRecord.partition() != partition.partition()) {
+            String error = String.format(
+                    "Unexpected topic/partition mismatch while calculating replication-offset-lag. Expected: %s, got: %s-%s.",
+                    partition, lastPolledRecord.topic(), lastPolledRecord.partition());
+            throw new UnsupportedOperationException(error);
+        }
+        long endOffsetForPartition = lastPolledRecord.offset();

Review Comment:
   My doubts are here: I think the LEO of the partition should be the log end offset of the partition in the source cluster, but the `lastPolledRecord.offset()` here represents only the offset in the source cluster of the last record polled by the task on the partition, that is to say, maybe the log end offset of the source cluster has reached 100, but due to the poor consumer performance of the task, it is actually only polled to the position where the offset is equal to 80, so the lag must be greater than 20 (the reason why it is greater than this is because it has just been polled data, not yet written to the target cluster, I think we agree on this). But if you follow the logic here in the PR, LEO will be 80, but in fact the offset of the source cluster has been written to 100.



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org