Skip to content

Unexpected text output of metric name containing : and broken histogram name output #1666

Description

@gavin-nia

This was tested using v1.4.2 of prometheus-metrics-exposition-text-formats.

Issue 1:
If a metric name contains a : it is being output in curly brackets. This seems unexpected and is a behavior change from older versions.

Issue 2:
The "le" label is not separated from the metric name in the case of histograms with no other labels. This is a bug.

Test code (still using the pre 1.0 artifacts here)

Counter
    .build()
    .name("mytest:withcolon_total")
    .help("test counter")
    .register();

Histogram
    .build()
    .name("myhistogram:withcolon")
    .help("test histogram")
    .buckets(new double[]{2, 10, 50, 200, 1_000, 5_000, 10_000})
    .register();

These are output as follows:

{mytest:withcolon_total} 0.0
{myhistogram:withcolon_bucketle="2.0"} 0

Looking at the code, PrometheusTextFormatWriter.writeNameAndLabels has:

    // If the name does not pass the legacy validity check, we must put the
    // metric name inside the braces.
    if (!PrometheusNaming.isValidLegacyLabelName(name)) {
      metricInsideBraces = true;
      writer.write('{');
    }

I feel that this should be calling isValidLegacyMetricName rather than isValidLegacyLabelName. The former does allow : in the name.

For the issue with the histogram, TextFormatUtil.writeLabels should probably be checking metricInsideBraces if an additionalName is present.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions