You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Igor Stepanov (JIRA)" <ji...@apache.org> on 2016/07/01 10:29:11 UTC

[jira] [Commented] (KAFKA-3923) MetricReporter interface depends on final class KafkaMetric instead of Metric interface

    [ https://issues.apache.org/jira/browse/KAFKA-3923?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15358761#comment-15358761 ] 

Igor Stepanov commented on KAFKA-3923:
--------------------------------------

If you consider this worth to be improved, let me share what I've found already.
1. Tried to "generify" MetricsReporter:
{code:java}
public interface MetricsReporter<T extends Metric> extends Configurable {

    public void init(List<T> metrics);

    public void metricChange(T metric);

    ...

}
{code}
This approach affected only MetricsReporter & JmxReporter and looked very promising, but I've got an error in Scala code:
{quote}
/Users/igorstepanov/git/github/kafka/core/src/main/scala/kafka/server/KafkaConfig.scala:887: trait MetricsReporter takes type parameters
  val metricReporterClasses: java.util.List[MetricsReporter] = getConfiguredInstances(KafkaConfig.MetricReporterClassesProp, classOf[MetricsReporter])
                                            ^
/Users/igorstepanov/git/github/kafka/core/src/main/scala/kafka/server/KafkaConfig.scala:887: trait MetricsReporter takes type parameters
  val metricReporterClasses: java.util.List[MetricsReporter] = getConfiguredInstances(KafkaConfig.MetricReporterClassesProp, classOf[MetricsReporter])
                                                                                                                                     ^
/Users/igorstepanov/git/github/kafka/core/src/main/scala/kafka/server/KafkaServer.scala:99: trait MetricsReporter takes type parameters
  private val reporters: java.util.List[MetricsReporter] = config.metricReporterClasses
{quote}
2. Tried just replacing KafkaMetric with Metric in most cases - this affected also Metrics class (in addition to MetricsReporter & JmxReporter), but again got error in Scala:
{quote}
/Users/igorstepanov/git/github/kafka/core/src/main/scala/kafka/server/ClientQuotaManager.scala:121: type mismatch;
 found   : org.apache.kafka.common.Metric
 required: org.apache.kafka.common.metrics.KafkaMetric
        throttleTimeMs = throttleTime(clientMetric, getQuotaMetricConfig(quota(clientId)))
{quote}

As I don't have the required experience with Scala, I've decided to stop at this point and consult with you.

> MetricReporter interface depends on final class KafkaMetric instead of Metric interface
> ---------------------------------------------------------------------------------------
>
>                 Key: KAFKA-3923
>                 URL: https://issues.apache.org/jira/browse/KAFKA-3923
>             Project: Kafka
>          Issue Type: Improvement
>          Components: clients
>            Reporter: Igor Stepanov
>
> Hello,
> I'm working on exposing Kafka's consumer/producer metrics to Spring Actuator.
> To achieve this, I've implemented Kafka's MetricReporter interface to allow injecting it into the appropriate consumer/producer. No issues with implementation itself, fine for me.
> But now I've moved to writing unit tests for this implementation and decided to use mocked KafkaMetric instances for this. But mocking of KafkaMetric itself is not so plain - the class is final. The logical step is to use Metric interface for mocking, but MetricReporter accepts only KafkaMetric.
> I know that technically I can use PowerMock and most probably it will work fine in this case, but talking about Kafka itself, is it a good approach to depend on the exact implementation when interface fulfils most of the needs?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)