chia7712 commented on code in PR #19574: URL: https://github.com/apache/kafka/pull/19574#discussion_r2070569672
########## server/src/main/java/org/apache/kafka/server/metrics/ForwardingManagerMetrics.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.metrics; + +import org.apache.kafka.common.MetricName; +import org.apache.kafka.common.metrics.Gauge; +import org.apache.kafka.common.metrics.MetricConfig; +import org.apache.kafka.common.metrics.Metrics; +import org.apache.kafka.common.metrics.Sensor; +import org.apache.kafka.common.metrics.stats.Percentile; +import org.apache.kafka.common.metrics.stats.Percentiles; +import org.apache.kafka.common.metrics.stats.Percentiles.BucketSizing; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.LongFunction; + +public final class ForwardingManagerMetrics implements AutoCloseable { + + private final Metrics metrics; + + private static final String METRIC_GROUP_NAME = "ForwardingManager"; + private static final String QUEUE_TIME_MS_NAME = "QueueTimeMs"; + private static final String REMOTE_TIME_MS_NAME = "RemoteTimeMs"; + + /** + * A histogram describing the amount of time in milliseconds each admin request spends in the broker's forwarding manager queue, waiting to be sent to the controller. + * This does not include the time that the request spends waiting for a response from the controller. + */ + private final LatencyHistogram queueTimeMsHist; + + /** + * A histogram describing the amount of time in milliseconds each request sent by the ForwardingManager spends waiting for a response. + * This does not include the time spent in the queue. + */ + private final LatencyHistogram remoteTimeMsHist; + + public final MetricName queueLengthName; + public final AtomicInteger queueLength = new AtomicInteger(0); + + public ForwardingManagerMetrics(Metrics metrics, long timeoutMs) { + this.metrics = metrics; + + this.queueTimeMsHist = new LatencyHistogram(metrics, QUEUE_TIME_MS_NAME, METRIC_GROUP_NAME, timeoutMs); + this.remoteTimeMsHist = new LatencyHistogram(metrics, REMOTE_TIME_MS_NAME, METRIC_GROUP_NAME, timeoutMs); + + this.queueLengthName = metrics.metricName( + "QueueLength", + METRIC_GROUP_NAME, + "The current number of RPCs that are waiting in the broker's forwarding manager queue, waiting to be sent to the controller." + ); + metrics.addMetric(queueLengthName, new FuncGauge<>(now -> queueLength.get())); Review Comment: Is `FuncGauge` necessary? ########## server/src/main/java/org/apache/kafka/server/metrics/ForwardingManagerMetrics.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.metrics; + +import org.apache.kafka.common.MetricName; +import org.apache.kafka.common.metrics.Gauge; +import org.apache.kafka.common.metrics.MetricConfig; +import org.apache.kafka.common.metrics.Metrics; +import org.apache.kafka.common.metrics.Sensor; +import org.apache.kafka.common.metrics.stats.Percentile; +import org.apache.kafka.common.metrics.stats.Percentiles; +import org.apache.kafka.common.metrics.stats.Percentiles.BucketSizing; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.LongFunction; + +public final class ForwardingManagerMetrics implements AutoCloseable { + + private final Metrics metrics; + + private static final String METRIC_GROUP_NAME = "ForwardingManager"; + private static final String QUEUE_TIME_MS_NAME = "QueueTimeMs"; + private static final String REMOTE_TIME_MS_NAME = "RemoteTimeMs"; + + /** + * A histogram describing the amount of time in milliseconds each admin request spends in the broker's forwarding manager queue, waiting to be sent to the controller. + * This does not include the time that the request spends waiting for a response from the controller. + */ + private final LatencyHistogram queueTimeMsHist; + + /** + * A histogram describing the amount of time in milliseconds each request sent by the ForwardingManager spends waiting for a response. + * This does not include the time spent in the queue. + */ + private final LatencyHistogram remoteTimeMsHist; + + public final MetricName queueLengthName; Review Comment: could we avoid using public member? -- 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