This is an automated email from the ASF dual-hosted git repository. wuzhiguo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ambari-metrics.git
The following commit(s) were added to refs/heads/master by this push: new e45ef8a AMBARI-25582: Change the way AMS Grafana datasource discovers the Kafka topics (#66) e45ef8a is described below commit e45ef8a199f64ffd4a01283a808e0e9d2742b630 Author: lucasbak <lucas.bakal...@gmail.com> AuthorDate: Tue Nov 15 10:37:21 2022 +0100 AMBARI-25582: Change the way AMS Grafana datasource discovers the Kafka topics (#66) --- .../ambari-metrics/datasource.js | 31 +++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/ambari-metrics-grafana/ambari-metrics/datasource.js b/ambari-metrics-grafana/ambari-metrics/datasource.js index f46fe00..decf67a 100644 --- a/ambari-metrics-grafana/ambari-metrics/datasource.js +++ b/ambari-metrics-grafana/ambari-metrics/datasource.js @@ -872,17 +872,28 @@ define([ if (interpolated === "kafka-topics") { return this.initMetricAppidMapping() .then(function () { - var kafkaTopics = getMetrics(allMetrics, "kafka_broker"); - var extractTopics = kafkaTopics.filter(/./.test.bind(new RegExp("\\b.log.Log.\\b", 'g'))); - var topics = _.map(extractTopics, function (topic) { - var topicPrefix = "topic."; - return topic.substring(topic.lastIndexOf(topicPrefix) + topicPrefix.length, topic.length); + // patterns to check possible kafka topics + var kafkaTopicPatterns = ['^kafka\\.server.*\\.topic\\.(.*)\\.[\\d\\w]*$', + '^kafka\\.log\\.Log\\..*.topic\\.(.*)$', + '^kafka\\.cluster.*\\.topic\\.(.*)$']; + + var kafkaMetrics = getMetrics(allMetrics, "kafka_broker"); + var topics = [] + + // filter metrics that can contain topic name + var topicMetrics = kafkaMetrics.filter(function(metric) { + return metric.indexOf(".topic.") > 0; }); - topics = _.sortBy(_.uniq(topics)); - var i = topics.indexOf("ambari_kafka_service_check"); - if (i != -1) { - topics.splice(i, 1); - } + + _.forEach(kafkaTopicPatterns, function(topicPattern) { + _.forEach(topicMetrics, function(checkTopic) { + var topicMatch = checkTopic.match(RegExp(topicPattern)); + var topicName = topicMatch ? topicMatch[1] : null; + if (topicName && topicName != "ambari_kafka_service_check" && topics.indexOf(topicName) < 0) { + topics.push(topicName); + } + }) + }) return _.map(topics, function (topics) { return { text: topics --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@ambari.apache.org For additional commands, e-mail: commits-h...@ambari.apache.org