mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-12 16:06:37 +00:00
*: avoid using default wmi client. (#1590)
This commit is contained in:
@@ -3,24 +3,11 @@
|
||||
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, ","))
|
||||
|
||||
// Result must order, to prevent test failures.
|
||||
sort.Strings(result)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func ExpandEnabledCollectors(enabled string) []string {
|
||||
expanded := strings.ReplaceAll(enabled, types.DefaultCollectorsPlaceholder, types.DefaultCollectors)
|
||||
separated := strings.Split(expanded, ",")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -10,38 +9,6 @@ import (
|
||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||
)
|
||||
|
||||
func TestExpandChildCollectors(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
input string
|
||||
expectedOutput []string
|
||||
}{
|
||||
{
|
||||
name: "simple",
|
||||
input: "testing1,testing2,testing3",
|
||||
expectedOutput: []string{"testing1", "testing2", "testing3"},
|
||||
},
|
||||
{
|
||||
name: "duplicate",
|
||||
input: "testing1,testing2,testing2,testing3",
|
||||
expectedOutput: []string{"testing1", "testing2", "testing3"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
output := utils.ExpandEnabledChildCollectors(c.input)
|
||||
if !reflect.DeepEqual(output, c.expectedOutput) {
|
||||
t.Errorf("Output mismatch, expected %+v, got %+v", c.expectedOutput, output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandEnabled(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -13,10 +13,6 @@ func BoolToFloat(b bool) float64 {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
func HasValue(v *string) bool {
|
||||
return !IsEmpty(v)
|
||||
}
|
||||
|
||||
func IsEmpty(v *string) bool {
|
||||
return v == nil || *v == ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user