Skip to content

Commit

Permalink
addressing Keith's comments
Browse files Browse the repository at this point in the history
Signed-off-by: Owen <[email protected]>
  • Loading branch information
OwenCorrigan76 committed Jun 18, 2024
1 parent 232c363 commit 20f10a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
20 changes: 10 additions & 10 deletions src/main/java/io/strimzi/kafka/metrics/KafkaMetricsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public List<MetricFamilySamples> collect() {
KafkaMetric kafkaMetric = entry.getValue();
LOG.trace("Collecting Kafka metric {}", metricName);

String name = metricName(metricName);
String prometheusMetricName = metricName(metricName);
// TODO Filtering should take labels into account
if (!config.isAllowed(name)) {
LOG.info("Kafka metric {} is not allowed", name);
if (!config.isAllowed(prometheusMetricName)) {
LOG.info("Kafka metric {} is not allowed", prometheusMetricName);
continue;
}
LOG.info("Kafka metric {} is allowed", name);
MetricFamilySamples sample = convert(name, metricName.description(), kafkaMetric, metricName.tags(), metricName);
LOG.info("Kafka metric {} is allowed", prometheusMetricName);
MetricFamilySamples sample = convert(prometheusMetricName, kafkaMetric, metricName);
if (sample != null) {
samples.add(sample);
}
Expand Down Expand Up @@ -108,13 +108,13 @@ String metricName(MetricName metricName) {
return prefix + '_' + group + '_' + name;
}

static MetricFamilySamples convert(String name, String help, KafkaMetric metric, Map<String, String> labels, MetricName metricName) {
Map<String, String> sanitizedLabels = labels.entrySet().stream()
private static MetricFamilySamples convert(String prometheusMetricName, KafkaMetric metric, MetricName metricName) {
Map<String, String> sanitizedLabels = metricName.tags().entrySet().stream()
.collect(Collectors.toMap(
e -> Collector.sanitizeMetricName(e.getKey()),
Map.Entry::getValue,
(v1, v2) -> {
LOG.warn("Unexpected duplicate key" + v1);
LOG.warn("Ignoring metric value duplicate key {}", v1);
return v1;
},
LinkedHashMap::new));
Expand All @@ -128,8 +128,8 @@ static MetricFamilySamples convert(String name, String help, KafkaMetric metric,
sanitizedLabels.put(attributeName, String.valueOf(valueObj));
}

return new MetricFamilySamplesBuilder(Type.GAUGE, help)
.addSample(name, value, sanitizedLabels)
return new MetricFamilySamplesBuilder(Type.GAUGE, metric.metricName().description())
.addSample(prometheusMetricName, value, sanitizedLabels)
.build();
}
}
44 changes: 22 additions & 22 deletions src/main/java/io/strimzi/kafka/metrics/YammerMetricsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,27 @@ public List<MetricFamilySamples> collect() {
Metric metric = entry.getValue();
LOG.trace("Collecting Yammer metric {}", metricName);

String name = metricName(metricName);
String prometheusMetricName = metricName(metricName);
// TODO Filtering should take labels into account
if (!config.isAllowed(name)) {
LOG.info("Yammer metric {} is not allowed", name);
if (!config.isAllowed(prometheusMetricName)) {
LOG.info("Yammer metric {} is not allowed", prometheusMetricName);
continue;
}
LOG.info("Yammer metric {} is allowed", name);
LOG.info("Yammer metric {} is allowed", prometheusMetricName);
Map<String, String> labels = labelsFromScope(metricName.getScope());
LOG.info("labels " + labels);

MetricFamilySamples sample = null;
if (metric instanceof Counter) {
sample = convert(name, (Counter) metric, labels);
sample = convert(prometheusMetricName, (Counter) metric, labels);
} else if (metric instanceof Gauge) {
sample = convert(name, (Gauge<?>) metric, labels, metricName);
sample = convert(prometheusMetricName, (Gauge<?>) metric, labels, metricName);
} else if (metric instanceof Histogram) {
sample = convert(name, (Histogram) metric, labels);
sample = convert(prometheusMetricName, (Histogram) metric, labels);
} else if (metric instanceof Meter) {
sample = convert(name, (Meter) metric, labels);
sample = convert(prometheusMetricName, (Meter) metric, labels);
} else if (metric instanceof Timer) {
sample = convert(name, (Timer) metric, labels);
sample = convert(prometheusMetricName, (Timer) metric, labels);
} else {
LOG.error("The metric " + metric.getClass().getName() + " has an unexpected type.");
}
Expand Down Expand Up @@ -115,19 +115,19 @@ static Map<String, String> labelsFromScope(String scope) {
return Collections.emptyMap();
}

static MetricFamilySamples convert(String name, Counter counter, Map<String, String> labels) {
static MetricFamilySamples convert(String prometheusMetricName, Counter counter, Map<String, String> labels) {
return new MetricFamilySamplesBuilder(Type.GAUGE, "")
.addSample(name + "_count", counter.count(), labels)
.addSample(prometheusMetricName + "_count", counter.count(), labels)
.build();
}

static MetricFamilySamples convert(String name, Gauge<?> gauge, Map<String, String> labels, MetricName metricName) {
private static MetricFamilySamples convert(String prometheusMetricName, Gauge<?> gauge, Map<String, String> labels, MetricName metricName) {
Map<String, String> sanitizedLabels = labels.entrySet().stream()
.collect(Collectors.toMap(
e -> Collector.sanitizeMetricName(e.getKey()),
Map.Entry::getValue,
(v1, v2) -> {
LOG.warn("Unexpected duplicate key " + v1);
LOG.warn("Ignoring metric value duplicate key {}", v1);
return v1;
},
LinkedHashMap::new));
Expand All @@ -142,27 +142,27 @@ static MetricFamilySamples convert(String name, Gauge<?> gauge, Map<String, Stri
}

return new MetricFamilySamplesBuilder(Type.GAUGE, "")
.addSample(name, value, sanitizedLabels)
.addSample(prometheusMetricName, value, sanitizedLabels)
.build();
}

static MetricFamilySamples convert(String name, Meter meter, Map<String, String> labels) {
static MetricFamilySamples convert(String prometheusMetricName, Meter meter, Map<String, String> labels) {
return new MetricFamilySamplesBuilder(Type.COUNTER, "")
.addSample(name + "_count", meter.count(), labels)
.addSample(prometheusMetricName + "_count", meter.count(), labels)
.build();
}

static MetricFamilySamples convert(String name, Histogram histogram, Map<String, String> labels) {
static MetricFamilySamples convert(String prometheusMetricName, Histogram histogram, Map<String, String> labels) {
return new MetricFamilySamplesBuilder(Type.SUMMARY, "")
.addSample(name + "_count", histogram.count(), labels)
.addQuantileSamples(name, histogram.getSnapshot(), labels)
.addSample(prometheusMetricName + "_count", histogram.count(), labels)
.addQuantileSamples(prometheusMetricName, histogram.getSnapshot(), labels)
.build();
}

static MetricFamilySamples convert(String name, Timer metric, Map<String, String> labels) {
static MetricFamilySamples convert(String prometheusMetricName, Timer metric, Map<String, String> labels) {
return new MetricFamilySamplesBuilder(Type.SUMMARY, "")
.addSample(name + "_count", metric.count(), labels)
.addQuantileSamples(name, metric.getSnapshot(), labels)
.addSample(prometheusMetricName + "_count", metric.count(), labels)
.addQuantileSamples(prometheusMetricName, metric.getSnapshot(), labels)
.build();
}
}

0 comments on commit 20f10a9

Please sign in to comment.