Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-17153

KafkaMetricsGroup#newGauge should accept functional interface instead of `com.yammer.metrics.core.Gague`

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 3.9.0
    • None
    • None

    Description

      This is a kind of syntactic sugar. Java disallow lambdas to implement abstract classes, and hence there are many ugly impl of Gague in code base [0][1][2][3]. Those bad looking code will spring up as we migrate more and more scala code to java.

      Hence, we should offer a variety to accept functional interface for java code. For example:

          public final <T> Gauge<T> newGauge(String name, Supplier<T> metric) {
              return newGauge(name, new Gauge<T>() {
                  @Override
                  public T value() {
                      return metric.get();
                  }
              }, Collections.emptyMap());
          }
      

      [0] https://github.com/apache/kafka/blob/b015a83f6d286965af999c39c0902584fb6fb9de/server/src/main/java/org/apache/kafka/server/AssignmentsManager.java#L109
      [1] https://github.com/apache/kafka/blob/b015a83f6d286965af999c39c0902584fb6fb9de/metadata/src/main/java/org/apache/kafka/image/loader/metrics/MetadataLoaderMetrics.java#L73
      [2] https://github.com/apache/kafka/blob/b015a83f6d286965af999c39c0902584fb6fb9de/metadata/src/main/java/org/apache/kafka/controller/metrics/ControllerMetadataMetrics.java#L106
      [3] https://github.com/apache/kafka/blob/b015a83f6d286965af999c39c0902584fb6fb9de/storage/src/main/java/org/apache/kafka/storage/internals/log/RemoteStorageThreadPool.java#L54

      Attachments

        Issue Links

          Activity

            People

              brandboat Kuan Po Tseng
              chia7712 Chia-Ping Tsai
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: