chore: Remove registry based perfdata collector (#1742)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2024-11-17 21:51:12 +01:00
committed by GitHub
parent 6206b695c6
commit e6a15d4ec4
213 changed files with 8079 additions and 12405 deletions

View File

@@ -1,28 +0,0 @@
//go:build windows
package utils
import (
"strings"
"github.com/prometheus-community/windows_exporter/internal/types"
)
func ExpandEnabledCollectors(enabled string) []string {
expanded := strings.ReplaceAll(enabled, types.DefaultCollectorsPlaceholder, types.DefaultCollectors)
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
}

View File

@@ -1,55 +0,0 @@
package utils_test
import (
"sort"
"strings"
"testing"
"github.com/prometheus-community/windows_exporter/internal/types"
"github.com/prometheus-community/windows_exporter/internal/utils"
)
func TestExpandEnabled(t *testing.T) {
t.Parallel()
expansionTests := []struct {
input string
expectedOutput []string
}{
{"", []string{}},
// Default case
{"cs,os", []string{"cs", "os"}},
// Placeholder expansion
{types.DefaultCollectorsPlaceholder, strings.Split(types.DefaultCollectors, ",")},
// De-duplication
{"cs,cs", []string{"cs"}},
// De-duplicate placeholder
{types.DefaultCollectorsPlaceholder + "," + types.DefaultCollectorsPlaceholder, strings.Split(types.DefaultCollectors, ",")},
// Composite case
{"foo," + types.DefaultCollectorsPlaceholder + ",bar", append(strings.Split(types.DefaultCollectors, ","), "foo", "bar")},
}
for _, testCase := range expansionTests {
output := utils.ExpandEnabledCollectors(testCase.input)
sort.Strings(output)
success := true
if len(output) != len(testCase.expectedOutput) {
success = false
} else {
sort.Strings(testCase.expectedOutput)
for idx := range output {
if output[idx] != testCase.expectedOutput[idx] {
success = false
break
}
}
}
if !success {
t.Error("For", testCase.input, "expected", testCase.expectedOutput, "got", output)
}
}
}

View File

@@ -1,3 +1,5 @@
//go:build windows
package utils
type Counter struct {

View File

@@ -1,3 +1,5 @@
//go:build windows
package utils_test
import (

View File

@@ -0,0 +1,87 @@
//go:build windows
package testutils
import (
"io"
"log/slog"
"sync"
"testing"
"time"
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus-community/windows_exporter/internal/mi"
"github.com/prometheus-community/windows_exporter/pkg/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
)
func FuncBenchmarkCollector[C collector.Collector](b *testing.B, name string, collectFunc collector.BuilderWithFlags[C]) {
b.Helper()
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
c := collectFunc(kingpin.CommandLine)
collectors := collector.New(map[string]collector.Collector{name: c})
require.NoError(b, collectors.Build(logger))
metrics := make(chan prometheus.Metric)
go func() {
for {
<-metrics
}
}()
for i := 0; i < b.N; i++ {
require.NoError(b, c.Collect(metrics))
}
}
func TestCollector[C collector.Collector, V interface{}](t *testing.T, fn func(*V) C, conf *V) {
t.Helper()
var (
metrics []prometheus.Metric
err error
)
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
c := fn(conf)
ch := make(chan prometheus.Metric, 10000)
miApp, err := mi.Application_Initialize()
require.NoError(t, err)
miSession, err := miApp.NewSession(nil)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, c.Close())
require.NoError(t, miSession.Close())
require.NoError(t, miApp.Close())
})
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
for metric := range ch {
metrics = append(metrics, metric)
}
}()
require.NoError(t, c.Build(logger, miSession))
time.Sleep(1 * time.Second)
require.NoError(t, c.Collect(ch))
close(ch)
wg.Wait()
require.NotEmpty(t, metrics)
}