forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-13229: add total blocked time metric to streams (KIP-761) (apac…
…he#11149) * Add the following producer metrics: flush-time-total: cumulative sum of time elapsed during in flush. txn-init-time-total: cumulative sum of time elapsed during in initTransactions. txn-begin-time-total: cumulative sum of time elapsed during in beginTransaction. txn-send-offsets-time-total: cumulative sum of time elapsed during in sendOffsetsToTransaction. txn-commit-time-total: cumulative sum of time elapsed during in commitTransaction. txn-abort-time-total: cumulative sum of time elapsed during in abortTransaction. * Add the following consumer metrics: commited-time-total: cumulative sum of time elapsed during in committed. commit-sync-time-total: cumulative sum of time elapsed during in commitSync. * Add a total-blocked-time metric to streams that is the sum of: consumer’s io-waittime-total consumer’s iotime-total consumer’s committed-time-total consumer’s commit-sync-time-total restore consumer’s io-waittime-total restore consumer’s iotime-total admin client’s io-waittime-total admin client’s iotime-total producer’s bufferpool-wait-time-total producer's flush-time-total producer's txn-init-time-total producer's txn-begin-time-total producer's txn-send-offsets-time-total producer's txn-commit-time-total producer's txn-abort-time-total Reviewers: Bruno Cadonna <cadonna@confluent.io>, Guozhang Wang <wangguoz@gmail.com>
- Loading branch information
Showing
29 changed files
with
1,302 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
clients/src/main/java/org/apache/kafka/clients/producer/internals/KafkaProducerMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.kafka.clients.producer.internals; | ||
|
||
import org.apache.kafka.common.MetricName; | ||
import org.apache.kafka.common.metrics.Metrics; | ||
import org.apache.kafka.common.metrics.Sensor; | ||
import org.apache.kafka.common.metrics.stats.CumulativeSum; | ||
|
||
import java.util.Map; | ||
|
||
public class KafkaProducerMetrics implements AutoCloseable { | ||
|
||
public static final String GROUP = "producer-metrics"; | ||
private static final String FLUSH = "flush"; | ||
private static final String TXN_INIT = "txn-init"; | ||
private static final String TXN_BEGIN = "txn-begin"; | ||
private static final String TXN_SEND_OFFSETS = "txn-send-offsets"; | ||
private static final String TXN_COMMIT = "txn-commit"; | ||
private static final String TXN_ABORT = "txn-abort"; | ||
private static final String TOTAL_TIME_SUFFIX = "-time-ns-total"; | ||
|
||
private final Map<String, String> tags; | ||
private final Metrics metrics; | ||
private final Sensor initTimeSensor; | ||
private final Sensor beginTxnTimeSensor; | ||
private final Sensor flushTimeSensor; | ||
private final Sensor sendOffsetsSensor; | ||
private final Sensor commitTxnSensor; | ||
private final Sensor abortTxnSensor; | ||
|
||
public KafkaProducerMetrics(Metrics metrics) { | ||
this.metrics = metrics; | ||
tags = this.metrics.config().tags(); | ||
flushTimeSensor = newLatencySensor( | ||
FLUSH, | ||
"Total time producer has spent in flush in nanoseconds." | ||
); | ||
initTimeSensor = newLatencySensor( | ||
TXN_INIT, | ||
"Total time producer has spent in initTransactions in nanoseconds." | ||
); | ||
beginTxnTimeSensor = newLatencySensor( | ||
TXN_BEGIN, | ||
"Total time producer has spent in beginTransaction in nanoseconds." | ||
); | ||
sendOffsetsSensor = newLatencySensor( | ||
TXN_SEND_OFFSETS, | ||
"Total time producer has spent in sendOffsetsToTransaction." | ||
); | ||
commitTxnSensor = newLatencySensor( | ||
TXN_COMMIT, | ||
"Total time producer has spent in commitTransaction." | ||
); | ||
abortTxnSensor = newLatencySensor( | ||
TXN_ABORT, | ||
"Total time producer has spent in abortTransaction." | ||
); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
removeMetric(FLUSH); | ||
removeMetric(TXN_INIT); | ||
removeMetric(TXN_BEGIN); | ||
removeMetric(TXN_SEND_OFFSETS); | ||
removeMetric(TXN_COMMIT); | ||
removeMetric(TXN_ABORT); | ||
} | ||
|
||
public void recordFlush(long duration) { | ||
flushTimeSensor.record(duration); | ||
} | ||
|
||
public void recordInit(long duration) { | ||
initTimeSensor.record(duration); | ||
} | ||
|
||
public void recordBeginTxn(long duration) { | ||
beginTxnTimeSensor.record(duration); | ||
} | ||
|
||
public void recordSendOffsets(long duration) { | ||
sendOffsetsSensor.record(duration); | ||
} | ||
|
||
public void recordCommitTxn(long duration) { | ||
commitTxnSensor.record(duration); | ||
} | ||
|
||
public void recordAbortTxn(long duration) { | ||
abortTxnSensor.record(duration); | ||
} | ||
|
||
private Sensor newLatencySensor(String name, String description) { | ||
Sensor sensor = metrics.sensor(name + TOTAL_TIME_SUFFIX); | ||
sensor.add(metricName(name, description), new CumulativeSum()); | ||
return sensor; | ||
} | ||
|
||
private MetricName metricName(final String name, final String description) { | ||
return metrics.metricName(name + TOTAL_TIME_SUFFIX, GROUP, description, tags); | ||
} | ||
|
||
private void removeMetric(final String name) { | ||
metrics.removeSensor(name + TOTAL_TIME_SUFFIX); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.