Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sanitize metric type prefixes (#319)
* 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 Signed-off-by: Edwin Mackenzie-Owen <[email protected]> * Remove condition that will never be true In alphanumerically sorted list of strings, abcdef will never come before abc. Signed-off-by: Edwin Mackenzie-Owen <[email protected]> * Add test for metrics prefix sanitization Signed-off-by: Edwin Mackenzie-Owen <[email protected]> * Use slices.Compact() for initial deduplication Signed-off-by: Edwin Mackenzie-Owen <[email protected]> * Improve comments Signed-off-by: Edwin Mackenzie-Owen <[email protected]> * Always initialize return slice Signed-off-by: Edwin Mackenzie-Owen <[email protected]> * Improve if condition Signed-off-by: Edwin Mackenzie-Owen <[email protected]> --------- Signed-off-by: Edwin Mackenzie-Owen <[email protected]>
- Loading branch information