From 480eb496b0c529559158e14ec339b634162604d1 Mon Sep 17 00:00:00 2001 From: riccardomodanese Date: Tue, 16 Apr 2024 09:25:44 +0200 Subject: [PATCH] :fix: count suffix for metrics names Signed-off-by: riccardomodanese --- .../commons/metric/MetricsServiceImpl.java | 29 ++----------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/commons/src/main/java/org/eclipse/kapua/commons/metric/MetricsServiceImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/metric/MetricsServiceImpl.java index 96aee8b91b0..d87cd76ba94 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/metric/MetricsServiceImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/metric/MetricsServiceImpl.java @@ -43,10 +43,6 @@ public class MetricsServiceImpl implements MetricsService { public static final String METRICS_SHORT_NAME_FORMAT = "{0}.{1}"; private static final char SEPARATOR = '.'; - enum MetricType { - count - } - private MetricRegistry metricRegistry; private JmxReporter jmxReporter; @@ -78,7 +74,7 @@ private void enableJmxSupport() { @Override public Counter getCounter(String module, String component, String... names) { - String name = getMetricName(MetricType.count, module, component, names); + String name = getMetricName(module, component, names) + SEPARATOR + "count"; Counter counter = metricRegistry.getCounters().get(name); if (counter == null) { logger.debug("Creating a Counter: {}", name); @@ -120,23 +116,7 @@ public void registerGauge(Gauge gauge, String module, String component, Strin } private String getMetricName(String module, String component, String... metricsName) { - return MessageFormat.format(METRICS_NAME_FORMAT, module, component, convertToDotNotation(null, metricsName)); - } - - /** - * Build the metric name based on module, component and metric names - * - * @param module - * @param component - * @param metricsName - * @return - */ - private String getMetricName(MetricType metricType, String module, String component, String... metricsName) { - if (metricsName == null || metricsName.length <= 0) { - return MessageFormat.format(METRICS_SHORT_NAME_FORMAT, module, component, metricType != null ? SEPARATOR + metricType.name() : ""); - } else { - return MessageFormat.format(METRICS_NAME_FORMAT, module, component, convertToDotNotation(metricType, metricsName)); - } + return MessageFormat.format(METRICS_NAME_FORMAT, module, component, convertToDotNotation(metricsName)); } /** @@ -145,7 +125,7 @@ private String getMetricName(MetricType metricType, String module, String compon * @param metricsName * @return */ - private String convertToDotNotation(MetricType metricType, String... metricsName) { + private String convertToDotNotation(String... metricsName) { StringBuilder builder = new StringBuilder(); boolean firstMetricName = true; for (String s : metricsName) { @@ -155,9 +135,6 @@ private String convertToDotNotation(MetricType metricType, String... metricsName firstMetricName = false; builder.append(s); } - if (metricType != null) { - builder.append(SEPARATOR).append(metricType.name()); - } return builder.toString(); }