windows_exporter/pkg/utils/collector.go
Jan-Otto Kröpke 0711268d3c
Refactor collectors
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
2023-11-12 13:51:59 +01:00

37 lines
939 B
Go

//go:build windows
package utils
import (
"slices"
"sort"
"strings"
"github.com/prometheus-community/windows_exporter/pkg/types"
)
// ExpandEnabledChildCollectors used by more complex Collectors where user input specifies enabled child Collectors.
// Splits provided child Collectors and deduplicate.
func ExpandEnabledChildCollectors(enabled string) []string {
result := slices.Compact(strings.Split(enabled, ","))
// Ensure result is ordered, to prevent test failure
sort.Strings(result)
return result
}
func ExpandEnabledCollectors(enabled string) []string {
expanded := strings.Replace(enabled, types.DefaultCollectorsPlaceholder, types.DefaultCollectors, -1)
separated := strings.Split(expanded, ",")
unique := map[string]bool{}
for _, s := range separated {
if s != "" {
unique[s] = true
}
}
result := make([]string, 0, len(unique))
for s := range unique {
result = append(result, s)
}
return result
}