Skip to content

Commit

Permalink
:fix: count suffix for metrics names
Browse files Browse the repository at this point in the history
Signed-off-by: riccardomodanese <[email protected]>
  • Loading branch information
riccardomodanese committed Apr 16, 2024
1 parent 67f1718 commit 3d082ec
Showing 1 changed file with 3 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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) {
Expand All @@ -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();
}

Expand Down

0 comments on commit 3d082ec

Please sign in to comment.