Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,20 @@ project(':core') {
standardOutput = new File(generatedDocsDir, "producer_metrics.html").newOutputStream()
}

task genShareGroupMetricsDocs(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'org.apache.kafka.server.share.metrics.ShareGroupMetrics'
if( !generatedDocsDir.exists() ) { generatedDocsDir.mkdirs() }
standardOutput = new File(generatedDocsDir, "share_group_metrics.html").newOutputStream()
}

task genShareConsumerMetricsDocs(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'org.apache.kafka.clients.consumer.internals.ShareConsumerMetrics'
if( !generatedDocsDir.exists() ) { generatedDocsDir.mkdirs() }
standardOutput = new File(generatedDocsDir, "share_consumer_metrics.html").newOutputStream()
}

task siteDocsTar(dependsOn: ['genProtocolErrorDocs', 'genProtocolTypesDocs', 'genProtocolApiKeyDocs', 'genProtocolMessageDocs',
'genAdminClientConfigDocs', 'genProducerConfigDocs', 'genConsumerConfigDocs',
'genKafkaConfigDocs', 'genTopicConfigDocs', 'genGroupConfigDocs',
Expand All @@ -1231,7 +1245,8 @@ project(':core') {
':connect:runtime:genConnectMetricsDocs', ':connect:runtime:genConnectOpenAPIDocs',
':connect:mirror:genMirrorSourceConfigDocs', ':connect:mirror:genMirrorCheckpointConfigDocs',
':connect:mirror:genMirrorHeartbeatConfigDocs', ':connect:mirror:genMirrorConnectorConfigDocs',
':storage:genRemoteLogManagerConfigDoc', ':storage:genRemoteLogMetadataManagerConfigDoc'], type: Tar) {
':storage:genRemoteLogManagerConfigDoc', ':storage:genRemoteLogMetadataManagerConfigDoc',
'genShareGroupMetricsDocs', 'genShareConsumerMetricsDocs'], type: Tar) {
archiveClassifier = 'site-docs'
compression = Compression.GZIP
from project.file("$rootDir/docs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
*/
package org.apache.kafka.clients.consumer.internals;

import org.apache.kafka.common.MetricNameTemplate;
import org.apache.kafka.common.metrics.Metrics;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.apache.kafka.clients.consumer.internals.ConsumerUtils.CONSUMER_SHARE_METRIC_GROUP_PREFIX;
Expand All @@ -31,4 +36,15 @@ public ShareConsumerMetrics(Set<String> metricsTags, String metricGrpPrefix) {
public ShareConsumerMetrics() {
this(new HashSet<>(), CONSUMER_SHARE_METRIC_GROUP_PREFIX);
}

private List<MetricNameTemplate> getAllTemplates() {
return new ArrayList<>(this.shareFetchMetrics.getAllTemplates());
}

public static void main(String[] args) {
Set<String> tags = new HashSet<>();
tags.add("client-id");
ShareConsumerMetrics metrics = new ShareConsumerMetrics(tags, CONSUMER_SHARE_METRIC_GROUP_PREFIX);
System.out.println(Metrics.toHtmlTable("kafka.consumer", metrics.getAllTemplates()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.kafka.common.MetricNameTemplate;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ShareFetchMetricsRegistry {
Expand Down Expand Up @@ -98,4 +99,27 @@ public ShareFetchMetricsRegistry(Set<String> tags, String metricGrpPrefix) {
this.fetchThrottleTimeMax = new MetricNameTemplate("fetch-throttle-time-max", groupName,
"The maximum throttle time in ms", tags);
}

public List<MetricNameTemplate> getAllTemplates() {
return List.of(
fetchSizeAvg,
fetchSizeMax,
bytesFetchedRate,
bytesFetchedTotal,
recordsPerRequestAvg,
recordsPerRequestMax,
recordsFetchedRate,
recordsFetchedTotal,
acknowledgementSendRate,
acknowledgementSendTotal,
acknowledgementErrorRate,
acknowledgementErrorTotal,
fetchLatencyAvg,
fetchLatencyMax,
fetchRequestRate,
fetchRequestTotal,
fetchThrottleTimeAvg,
fetchThrottleTimeMax
);
}
}
12 changes: 10 additions & 2 deletions docs/ops.html
Original file line number Diff line number Diff line change
Expand Up @@ -1927,8 +1927,8 @@ <h4 class="anchor-heading"><a id="group_coordinator_monitoring" class="anchor-li
</tr>
<tr>
<td>Group Count, per group type</td>
<td>kafka.server:type=group-coordinator-metrics,name=group-count,protocol={consumer|classic}</td>
<td>Total number of group per group type: Classic or Consumer</td>
<td>kafka.server:type=group-coordinator-metrics,name=group-count,protocol={consumer|classic|share}</td>
<td>Total number of group per group type: Classic, Consumer or Share</td>
</tr>
<tr>
<td>Consumer Group Count, per state</td>
Expand Down Expand Up @@ -3980,6 +3980,14 @@ <h5 class="anchor-heading"><a id="kafka_streams_cache_monitoring" class="anchor-
</tbody>
</table>

<h4 class="anchor-heading"><a id="kafka_share_group_monitoring" class="anchor-link"></a><a href="#kafka_share_group_monitoring">Share Group Monitoring</a></h4>
The following set of metrics are available for monitoring the share group:<br/><br/>
<!--#include virtual="generated/share_group_metrics.html" -->

<h5 class="anchor-heading"><a id="kafka_share_client_monitoring" class="anchor-link"></a><a href="#kafka_share_client_monitoring">Client Metrics</a></h5>
The following metrics are available on share consumer instances:<br/><br/>
<!--#include virtual="generated/share_consumer_metrics.html" -->

<h4 class="anchor-heading"><a id="others_monitoring" class="anchor-link"></a><a href="#others_monitoring">Others</a></h4>

We recommend monitoring GC time and other stats and various server stats such as CPU utilization, I/O service time, etc.
Expand Down
1 change: 1 addition & 0 deletions docs/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<li><a href="#consumer_monitoring">Consumer Monitoring</a>
<li><a href="#connect_monitoring">Connect Monitoring</a>
<li><a href="#kafka_streams_monitoring">Streams Monitoring</a>
<li><a href="#kafka_share_group_monitoring">Share Group Monitoring</a>
<li><a href="#others_monitoring">Others</a>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.kafka.server.share.metrics;

import org.apache.kafka.clients.consumer.AcknowledgeType;
import org.apache.kafka.common.metrics.Metrics;
import org.apache.kafka.common.utils.Time;
import org.apache.kafka.server.metrics.KafkaMetricsGroup;

Expand Down Expand Up @@ -142,4 +143,9 @@ private static String capitalize(String string) {
}
return string.substring(0, 1).toUpperCase(Locale.ROOT) + string.substring(1);
}

public static void main(String[] args) {
ShareGroupMetricsRegistry metrics = new ShareGroupMetricsRegistry();
System.out.println(Metrics.toHtmlTable("kafka.server", metrics.getAllTemplates()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/*
* 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.server.share.metrics;

import org.apache.kafka.common.MetricNameTemplate;
import org.apache.kafka.common.metrics.Metrics;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class ShareGroupMetricsRegistry {

public final MetricNameTemplate shareGroupCount;
public final MetricNameTemplate writeRate;
public final MetricNameTemplate writeTotal;
public final MetricNameTemplate writeLatencyAvg;
public final MetricNameTemplate writeLatencyMax;
public final MetricNameTemplate lastPrunedOffset;
public final MetricNameTemplate totalShareFetchRequestsPerSec;
public final MetricNameTemplate failedShareFetchRequestsPerSec;
public final MetricNameTemplate totalShareAcknowledgementRequestsPerSec;
public final MetricNameTemplate failedShareAcknowledgementRequestsPerSec;
public final MetricNameTemplate recordAcknowledgementsPerSec;
public final MetricNameTemplate partitionLoadTimeMs;
public final MetricNameTemplate requestTopicPartitionsFetchRatio;
public final MetricNameTemplate topicPartitionsAcquireTimeMs;
public final MetricNameTemplate acquisitionLockTimeoutPerSec;
public final MetricNameTemplate inFlightMessageCount;
public final MetricNameTemplate inFlightBatchCount;
public final MetricNameTemplate inFlightBatchMessageCount;
public final MetricNameTemplate fetchLockTimeMs;
public final MetricNameTemplate fetchLockRatio;
public final MetricNameTemplate shareSessionEvictionsPerSec;
public final MetricNameTemplate sharePartitionsCount;
public final MetricNameTemplate shareSessionsCount;
public final MetricNameTemplate delayedShareFetchExpiresPerSec;
public final MetricNameTemplate shareFetchPurgatorySize;
public final MetricNameTemplate shareFetchNumDelayedOperations;

public ShareGroupMetricsRegistry() {
this(new HashSet<>(), "");
}

public ShareGroupMetricsRegistry(Set<String> tags, String metricGrpPrefix) {

/* BrokerTopicMetrics */
String brokerTopicGroupName = "BrokerTopicMetrics";
Set<String> topicTags = Set.of("topic");

this.totalShareFetchRequestsPerSec = new MetricNameTemplate("TotalShareFetchRequestsPerSec", brokerTopicGroupName,
"The fetch request rate per second. ", topicTags);

this.failedShareFetchRequestsPerSec = new MetricNameTemplate("FailedShareFetchRequestsPerSec", brokerTopicGroupName,
"The share fetch request rate for requests that failed. ", topicTags);

this.totalShareAcknowledgementRequestsPerSec = new MetricNameTemplate("TotalShareAcknowledgementRequestsPerSec", brokerTopicGroupName,
"The acknowledgement request rate per second. ", topicTags);

this.failedShareAcknowledgementRequestsPerSec = new MetricNameTemplate("FailedShareAcknowledgementRequestsPerSec", brokerTopicGroupName,
"The share acknowledgement request rate for requests that failed. ", topicTags);

/* Group Coordinator metrics */
Set<String> state = Set.of("state");
this.shareGroupCount = new MetricNameTemplate("share-group-count", "GroupCoordinator",
"The number of share groups in respective state.", state);

/* Share Coordinator metrics */
String shareCoordinatorMetrics = "share-coordinator-metrics";
this.writeRate = new MetricNameTemplate("write-rate", shareCoordinatorMetrics,
"The number of share-group state write calls per second.", tags);

this.writeTotal = new MetricNameTemplate("write-total", shareCoordinatorMetrics,
"The total number of share-group state write calls.", tags);

this.writeLatencyAvg = new MetricNameTemplate("write-latency-avg", shareCoordinatorMetrics,
"The average time taken for a share-group state write call, including the time to write to the share-group state topic.", tags);

this.writeLatencyMax = new MetricNameTemplate("write-latency-max", shareCoordinatorMetrics,
"The maximum time taken for a share-group state write call, including the time to write to the share-group state topic.", tags);

Set<String> topicPartitionTags = Set.of("topic", "partition");
this.lastPrunedOffset = new MetricNameTemplate("last-pruned-offset", shareCoordinatorMetrics,
"The last pruned offset in the share-group state topic.", topicPartitionTags);

/* ShareGroupMetrics */
String shareGroupMetricsName = metricGrpPrefix + "ShareGroupMetrics";
Set<String> ackTypeTags = Set.of("ackType");

this.recordAcknowledgementsPerSec = new MetricNameTemplate("RecordAcknowledgementsPerSec", shareGroupMetricsName,
"The rate per second of records acknowledged per acknowledgement type.", ackTypeTags);

this.partitionLoadTimeMs = new MetricNameTemplate("PartitionLoadTimeMs", shareGroupMetricsName,
"The time taken to load the share partitions.", tags);
Set<String> groupTags = Set.of("group");

this.requestTopicPartitionsFetchRatio = new MetricNameTemplate("RequestTopicPartitionsFetchRatio", shareGroupMetricsName,
"The ratio of topic-partitions acquired to the total number of topic-partitions in share fetch request.", groupTags);

this.topicPartitionsAcquireTimeMs = new MetricNameTemplate("TopicPartitionsAcquireTimeMs", shareGroupMetricsName,
"The time elapsed (in millisecond) to acquire any topic partition for fetch.", groupTags);

/* SharePartitionMetrics - Partition level */
String sharePartitionMetricsName = "SharePartitionMetrics";
Set<String> partitionTags = Set.of("group", "topic", "partition");

this.acquisitionLockTimeoutPerSec = new MetricNameTemplate("AcquisitionLockTimeoutPerSec", sharePartitionMetricsName,
"The rate of acquisition locks for records which are not acknowledged within the timeout.", partitionTags);

this.inFlightMessageCount = new MetricNameTemplate("InFlightMessageCount", sharePartitionMetricsName,
"The number of in-flight messages for the share partition.", partitionTags);

this.inFlightBatchCount = new MetricNameTemplate("InFlightBatchCount", sharePartitionMetricsName,
"The number of in-flight batches for the share partition.", partitionTags);

this.inFlightBatchMessageCount = new MetricNameTemplate("InFlightBatchMessageCount", sharePartitionMetricsName,
"The number of messages in the in-flight batch.", partitionTags);

this.fetchLockTimeMs = new MetricNameTemplate("FetchLockTimeMs", sharePartitionMetricsName,
"The time elapsed (in milliseconds) while a share partition is held under lock for fetching messages.", partitionTags);

this.fetchLockRatio = new MetricNameTemplate("FetchLockRatio", sharePartitionMetricsName,
"The fraction of time share partition is held under lock.", partitionTags);

/* ShareSessionCache metrics */
String shareSessionCacheName = "ShareSessionCache";
this.shareSessionEvictionsPerSec = new MetricNameTemplate("ShareSessionEvictionsPerSec", shareSessionCacheName,
"The share session eviction rate per second.", tags);

this.sharePartitionsCount = new MetricNameTemplate("SharePartitionsCount", shareSessionCacheName,
"The number of cached share partitions.", tags);

this.shareSessionsCount = new MetricNameTemplate("ShareSessionsCount", shareSessionCacheName,
"The number of cached share sessions.", tags);

/* DelayedShareFetchMetrics */
String delayedShareFetchMetricsName = "DelayedShareFetchMetrics";
this.delayedShareFetchExpiresPerSec = new MetricNameTemplate("ExpiresPerSec", delayedShareFetchMetricsName,
"The expired delayed share fetch operation rate per second.", tags);

/* DelayedOperationPurgatory metrics */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure if we need to show the DelayedOperationPurgatory metrics in the documentation, as it doesn't only apply to share group.

String delayedOperationPurgatoryName = "DelayedOperationPurgatory";
Set<String> shareFetchTags = new LinkedHashSet<>(tags);
shareFetchTags.add("delayedOperation");

this.shareFetchPurgatorySize = new MetricNameTemplate("PurgatorySize", delayedOperationPurgatoryName,
"The number of requests waiting in the share fetch purgatory. This is high if share consumers use a large value for fetch.wait.max.ms", shareFetchTags);

this.shareFetchNumDelayedOperations = new MetricNameTemplate("NumDelayedOperations", delayedOperationPurgatoryName,
"The number of delayed operations for share fetch purgatory.", shareFetchTags);
}

public List<MetricNameTemplate> getAllTemplates() {
return Arrays.asList(
shareGroupCount,
writeRate,
writeTotal,
writeLatencyAvg,
writeLatencyMax,
totalShareFetchRequestsPerSec,
failedShareFetchRequestsPerSec,
totalShareAcknowledgementRequestsPerSec,
failedShareAcknowledgementRequestsPerSec,
recordAcknowledgementsPerSec,
partitionLoadTimeMs,
requestTopicPartitionsFetchRatio,
topicPartitionsAcquireTimeMs,
acquisitionLockTimeoutPerSec,
inFlightMessageCount,
inFlightBatchCount,
inFlightBatchMessageCount,
fetchLockTimeMs,
fetchLockRatio,
shareSessionEvictionsPerSec,
sharePartitionsCount,
shareSessionsCount,
delayedShareFetchExpiresPerSec,
shareFetchPurgatorySize,
shareFetchNumDelayedOperations
);
}

public static void main(String[] args) {
ShareGroupMetricsRegistry metrics = new ShareGroupMetricsRegistry();
System.out.println(Metrics.toHtmlTable("kafka.server", metrics.getAllTemplates()));
}
}