Skip to content

Commit

Permalink
Rename uptime description for Prometheus in rename filter
Browse files Browse the repository at this point in the history
Prometheus prescribes what the description of the uptime metric should be[1], and while it does not enforce this on the server, the pushgateway complains.

[1] https://prometheus.io/docs/instrumenting/writing_clientlibs/#process-metrics

Closes micrometer-metricsgh-5290
  • Loading branch information
shakuzen committed Sep 3, 2024
1 parent 2cf4cb1 commit 5cb8706
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.micrometer.prometheusmetrics;

import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.config.MeterFilter;

import java.util.HashMap;
Expand All @@ -39,6 +40,10 @@ public class PrometheusRenameFilter implements MeterFilter {

@Override
public Meter.Id map(Meter.Id id) {
if (id.getName().equals("process.start.time")) {
return new Meter.Id(id.getName(), Tags.of(id.getTagsAsIterable()), id.getBaseUnit(),
"Start time of the process since unix epoch in seconds.", id.getType());
}
String convertedName = MICROMETER_TO_PROMETHEUS_NAMES.get(id.getName());
return convertedName == null ? id : id.withName(convertedName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package io.micrometer.prometheusmetrics;

import io.micrometer.core.Issue;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -49,4 +51,13 @@ void doesChangeApplicableMeter() {
assertThat(actual.getName()).isEqualTo("process.open.fds");
}

@Test
@Issue("#5290")
void processStartTimeDescriptionMatchesPrometheusHelpString() {
registry.config().meterFilter(filter);
new UptimeMetrics().bindTo(registry);
assertThat(registry.get("process.start.time").meter().getId().getDescription())
.isEqualTo("Start time of the process since unix epoch in seconds.");
}

}

0 comments on commit 5cb8706

Please sign in to comment.