Skip to content

Commit f020f50

Browse files
Use slices.Compact() for initial deduplication
Signed-off-by: Edwin Mackenzie-Owen <[email protected]>
1 parent 4d76015 commit f020f50

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

stackdriver_exporter.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,12 @@ func main() {
356356
}
357357

358358
func parseMetricTypePrefixes(inputPrefixes []string) (metricTypePrefixes []string) {
359-
// only keep unique prefixes
360-
uniqueKeys := make(map[string]bool)
361-
uniquePrefixes := []string{}
362-
for _, prefix := range inputPrefixes {
363-
if _, ok := uniqueKeys[prefix]; !ok {
364-
uniqueKeys[prefix] = true
365-
uniquePrefixes = append(uniquePrefixes, prefix)
366-
}
367-
}
359+
// drop duplicate prefixes
360+
slices.Sort(inputPrefixes)
361+
uniquePrefixes := slices.Compact(inputPrefixes)
368362

369363
// drop prefixes that start with another existing prefix to avoid error:
370364
// "collected metric xxx was collected before with the same name and label values"
371-
slices.Sort(uniquePrefixes)
372365
for i, prefix := range uniquePrefixes {
373366
if i == 0 {
374367
metricTypePrefixes = []string{prefix}

0 commit comments

Comments
 (0)