shirshanka commented on a change in pull request #2730: GOBBLIN-876: Expose 
metrics() API in GobblinKafkaConsumerClient to al…
URL: https://github.com/apache/incubator-gobblin/pull/2730#discussion_r322486643
 
 

 ##########
 File path: 
gobblin-modules/gobblin-kafka-09/src/main/java/org/apache/gobblin/kafka/client/Kafka09ConsumerClient.java
 ##########
 @@ -162,6 +170,35 @@ public KafkaConsumerRecord apply(ConsumerRecord<K, V> 
input) {
     });
   }
 
+  @Override
+  public Map<String, Metric> metrics() {
+    Map<MetricName, KafkaMetric> kafkaMetrics = (Map<MetricName, KafkaMetric>) 
this.consumer.metrics();
+    Map<String, Metric> codaHaleMetricMap = new HashMap<>();
+
+    kafkaMetrics
+        .forEach((key, value) -> 
codaHaleMetricMap.put(canonicalMerticName(value), 
kafkaToCodaHaleMetric(value)));
+    return codaHaleMetricMap;
+  }
+
+  /**
+   * Convert a {@link KafkaMetric} instance to a {@link Metric}.
+   * @param kafkaMetric
+   * @return
+   */
+  private Metric kafkaToCodaHaleMetric(final KafkaMetric kafkaMetric) {
+    if (log.isDebugEnabled()) {
+      log.debug("Processing a metric change for {}", 
kafkaMetric.metricName().toString());
+    }
+    Gauge<Double> gauge = () -> kafkaMetric.value();
+    return gauge;
+  }
+
+  private String canonicalMerticName(KafkaMetric kafkaMetric) {
+    MetricName name = kafkaMetric.metricName();
+    return canonicalMetricName(name.group(), name.tags().values(), 
name.name());
 
 Review comment:
   since this method will be called repeatedly with the same input values (the 
Kafka Metric Names) over the lifetime of the process, does it make sense to 
cache the mapping of KafkaMetricName -> canonicalMetricName and re-use it? 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to