Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:fix: count suffix for metrics names #4020

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading