Skip to content

Commit

Permalink
move _total to a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Aug 31, 2023
1 parent 4086ffa commit 83780c4
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/** A class that maps a raw metric name to Prometheus equivalent name. */
class PrometheusMetricNameMapper implements BiFunction<MetricData, PrometheusType, String> {

private static final String TOTAL_SUFFIX = "_total";
static final PrometheusMetricNameMapper INSTANCE = new PrometheusMetricNameMapper();

private final Map<ImmutableMappingKey, String> cache = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -46,8 +46,8 @@ private static String mapToPrometheusName(MetricData rawMetric, PrometheusType p
!StringUtils.isNullOrEmpty(prometheusEquivalentUnit)
&& !name.contains(prometheusEquivalentUnit);
// trim counter's _total suffix so the unit is placed before it.
if (prometheusType == PrometheusType.COUNTER && name.endsWith("_total")) {
name = name.substring(0, name.length() - "_total".length());
if (prometheusType == PrometheusType.COUNTER && name.endsWith(TOTAL_SUFFIX)) {
name = name.substring(0, name.length() - TOTAL_SUFFIX.length());
}
// append prometheus unit if not null or empty.
if (shouldAppendUnit) {
Expand All @@ -56,7 +56,7 @@ private static String mapToPrometheusName(MetricData rawMetric, PrometheusType p

// replace _total suffix, or add if it wasn't already present.
if (prometheusType == PrometheusType.COUNTER) {
name = name + "_total";
name = name + TOTAL_SUFFIX;
}
// special case - gauge
if (rawMetric.getUnit().equals("1")
Expand Down

0 comments on commit 83780c4

Please sign in to comment.