[GitHub] [incubator-gobblin] sv2000 commented on a change in pull request #2730: GOBBLIN-876: Expose metrics() API in GobblinKafkaConsumerClient to al…

2019-09-09 Thread GitBox
sv2000 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_r322495008
 
 

 ##
 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 
input) {
 });
   }
 
+  @Override
+  public Map metrics() {
+Map kafkaMetrics = (Map) 
this.consumer.metrics();
+Map 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 gauge = () -> kafkaMetric.value();
+return gauge;
+  }
+
+  private String canonicalMerticName(KafkaMetric kafkaMetric) {
 
 Review comment:
   Fixed. Thanks!


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


[GitHub] [incubator-gobblin] sv2000 commented on a change in pull request #2730: GOBBLIN-876: Expose metrics() API in GobblinKafkaConsumerClient to al…

2019-09-09 Thread GitBox
sv2000 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_r322495055
 
 

 ##
 File path: 
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/kafka/client/AbstractBaseKafkaConsumerClient.java
 ##
 @@ -84,6 +83,33 @@ public boolean apply(@Nonnull KafkaTopic kafkaTopic) {
 }));
   }
 
+  /**
+   * A helper method that returns the canonical metric name for a kafka 
metric. A typical canonicalized metric name would
+   * be of the following format: "{metric-group}_{client-id}_{metric-name}".
+   * @param metricGroup the type of the Kafka metric 
e.g."consumer-fetch-manager-metrics", "consumer-coordinator-metrics" etc.
+   * @param metricTags any tags associated with the Kafka metric, typically 
include the kafka client id, topic name, partition number etc.
+   * @param metricName the name of the Kafka metric e.g. "records-lag-max", 
"fetch-throttle-time-max" etc.
+   * @return the canonicalized metric name.
+   */
+  String canonicalMetricName(String metricGroup, Collection 
metricTags, String metricName) {
 
 Review comment:
   Added a clarifying comment.


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


[GitHub] [incubator-gobblin] sv2000 commented on a change in pull request #2730: GOBBLIN-876: Expose metrics() API in GobblinKafkaConsumerClient to al…

2019-09-09 Thread GitBox
sv2000 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_r322494096
 
 

 ##
 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 
input) {
 });
   }
 
+  @Override
+  public Map metrics() {
+Map kafkaMetrics = (Map) 
this.consumer.metrics();
+Map 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 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:
   Yeah - thought about it. Even if we cache the metric name mappings, we need 
to compute the key for the map every time. It seems like the key needs to be 
derived off of metric group, metric name and tags to make the metric unique, 
which is essentially the canonical representation of the kafka metric.


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


[GitHub] [incubator-gobblin] sv2000 commented on a change in pull request #2730: GOBBLIN-876: Expose metrics() API in GobblinKafkaConsumerClient to al…

2019-09-09 Thread GitBox
sv2000 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_r322472899
 
 

 ##
 File path: 
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/kafka/client/AbstractBaseKafkaConsumerClient.java
 ##
 @@ -84,6 +83,33 @@ public boolean apply(@Nonnull KafkaTopic kafkaTopic) {
 }));
   }
 
+  /**
+   * A helper method that returns the canonical metric name for a kafka 
metric. A typical canonicalized metric name would
+   * be of the following format: "{metric-group}_{client-id}_{metric-name}".
+   * @param metricGroup the type of the Kafka metric 
e.g."consumer-fetch-manager-metrics", "consumer-coordinator-metrics" etc.
+   * @param metricTags any tags associated with the Kafka metric, typically 
include the kafka client id, topic name, partition number etc.
+   * @param metricName the name of the Kafka metric e.g. "records-lag-max", 
"fetch-throttle-time-max" etc.
+   * @return the canonicalized metric name.
+   */
+  public String canonicalMetricName(String metricGroup, Collection 
metricTags, String metricName) {
 
 Review comment:
   Will make the change.


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


[GitHub] [incubator-gobblin] sv2000 commented on a change in pull request #2730: GOBBLIN-876: Expose metrics() API in GobblinKafkaConsumerClient to al…

2019-09-09 Thread GitBox
sv2000 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_r322472813
 
 

 ##
 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 
input) {
 });
   }
 
+  @Override
+  public Map metrics() {
+Map kafkaMetrics = (Map) 
this.consumer.metrics();
+Map 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) {
 
 Review comment:
   Good point. Unfortunately, the KafkaMetric class is specific to a given 
Kafka version, making code duplication necessary. So it seems that each 
consumer client version will have its own implementation of the method. 


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