stackdriver_exporter
stackdriver_exporter copied to clipboard
Sanitize metric type prefixes
When more than one prefix matches the same metric descriptor, this will throw the error collected metric xxx was collected before with the same name and label values.
For example, using the metric type prefixes
foo.googleapis.com/bar (a prefix)
and
foo.googleapis.com/bar/baz (a metric)
will result in an error because both match the metric
foo.googleapis.com/bar/baz.
Further, using the metric type prefixes
foo.googleapis.com/bar/baz (a metric)
and
foo.googleapis.com/bar/baz_count (a metric)
will result in an error because both match the metric
foo.googleapis.com/bar/baz_count.
While the first pitfall could be expected by the user, the latter will come as a complete surprise to anyone who is not aware that stackdriver-exporter internally uses an MQL query in the form of
metric.type = starts_with("<prefix>")
to filter the metrics.
Avoid this by sanitizing the provided metric type prefixes in the following way:
- Drop any duplicate prefixes
- Sort the prefixes (required by the next step)
- Drop any prefixes that start with another prefix present in the input
Fixes https://github.com/prometheus-community/stackdriver_exporter/issues/103