Skip to content

Commit

Permalink
Remove the instrumentation library name from the prometheus metric na…
Browse files Browse the repository at this point in the history
…mes (#1510)

* Remove the instrumentation library name from the prometheus metric names.

* fix the other test
  • Loading branch information
jkwatson authored Aug 6, 2020
1 parent 66c5054 commit d6d804e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,18 @@ final class MetricAdapter {
// Converts a MetricData to a Prometheus MetricFamilySamples.
static MetricFamilySamples toMetricFamilySamples(MetricData metricData) {
Descriptor descriptor = metricData.getDescriptor();
String fullName =
toMetricFullName(
descriptor.getName(), metricData.getInstrumentationLibraryInfo().getName());
String cleanMetricName = cleanMetricName(descriptor.getName());
Collector.Type type = toMetricFamilyType(descriptor.getType());

return new MetricFamilySamples(
fullName,
cleanMetricName,
type,
descriptor.getDescription(),
toSamples(fullName, descriptor, metricData.getPoints()));
toSamples(cleanMetricName, descriptor, metricData.getPoints()));
}

private static String toMetricFullName(
String descriptorMetricName, String instrumentationLibraryName) {
if (instrumentationLibraryName.isEmpty()) {
return Collector.sanitizeMetricName(descriptorMetricName);
}

// Use "_" here even though the right way would be to use "." in general, but "." will be
// replaced with "_" anyway so one less replace call.
return Collector.sanitizeMetricName(instrumentationLibraryName + "_" + descriptorMetricName);
private static String cleanMetricName(String descriptorMetricName) {
return Collector.sanitizeMetricName(descriptorMetricName);
}

static Collector.Type toMetricFamilyType(MetricData.Descriptor.Type type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ void toSamples_SummaryPoints() {
void toMetricFamilySamples() {
Descriptor descriptor =
Descriptor.create(
"name", "description", "1", Descriptor.Type.MONOTONIC_DOUBLE, Labels.of("kc", "vc"));
"instrument.name",
"description",
"1",
Descriptor.Type.MONOTONIC_DOUBLE,
Labels.of("kc", "vc"));

MetricData metricData =
MetricData.create(
Expand All @@ -226,12 +230,12 @@ void toMetricFamilySamples() {
assertThat(MetricAdapter.toMetricFamilySamples(metricData))
.isEqualTo(
new MetricFamilySamples(
"full_name",
"instrument_name",
Collector.Type.COUNTER,
descriptor.getDescription(),
ImmutableList.of(
new Sample(
"full_name",
"instrument_name",
ImmutableList.of("kc", "kp"),
ImmutableList.of("vc", "vp"),
5))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static ImmutableList<MetricData> generateTestData() {
return ImmutableList.of(
MetricData.create(
Descriptor.create(
"name",
"grpc.name",
"long_description",
"1",
Descriptor.Type.MONOTONIC_LONG,
Expand All @@ -79,7 +79,7 @@ private static ImmutableList<MetricData> generateTestData() {
MetricData.LongPoint.create(123, 456, Labels.of("kp", "vp"), 5))),
MetricData.create(
Descriptor.create(
"name",
"http.name",
"double_description",
"1",
Descriptor.Type.MONOTONIC_DOUBLE,
Expand Down

0 comments on commit d6d804e

Please sign in to comment.