You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Chia-Ping Tsai (Jira)" <ji...@apache.org> on 2025/09/07 22:20:00 UTC
[jira] [Commented] (KAFKA-19684) Move Gauge#value to MetricValueProvider
[ https://issues.apache.org/jira/browse/KAFKA-19684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18018689#comment-18018689 ]
Chia-Ping Tsai commented on KAFKA-19684:
----------------------------------------
the main benefit is to remove the type check from `KafkaMetric`
{code:java}
// before
public Object metricValue() {
long now = time.milliseconds();
synchronized (this.lock) {
if (isMeasurable())
return ((Measurable) metricValueProvider).measure(config, now);
else if (this.metricValueProvider instanceof Gauge)
return ((Gauge<?>) metricValueProvider).value(config, now);
else
throw new IllegalStateException("Not a valid metric: " + this.metricValueProvider.getClass());
}
}
{code}
{code:java}
// after
public Object metricValue() {
long now = time.milliseconds();
synchronized (this.lock) {
return metricValueProvider.value(config, now);
}
}
{code}
Also, the following code could be removed
{code:java}
if (!(valueProvider instanceof Measurable) && !(valueProvider instanceof Gauge))
throw new IllegalArgumentException("Unsupported metric value provider of class " + valueProvider.getClass());
{code}
> Move Gauge#value to MetricValueProvider
> ---------------------------------------
>
> Key: KAFKA-19684
> URL: https://issues.apache.org/jira/browse/KAFKA-19684
> Project: Kafka
> Issue Type: Improvement
> Reporter: Chia-Ping Tsai
> Assignee: Chia-Ping Tsai
> Priority: Minor
> Labels: need-kip
>
> from: https://github.com/apache/kafka/pull/3705#discussion_r140830112
--
This message was sent by Atlassian Jira
(v8.20.10#820010)