Compare commits

...

1 Commits

Author SHA1 Message Date
Jan-Otto Kröpke
23397701ff pdh/registry: fix panic when T is a struct type (#2366) (#2367)
Co-authored-by: Kayla Ondracek <112117836+kondracek-nr@users.noreply.github.com>
2026-03-20 20:27:02 +01:00
2 changed files with 17 additions and 1 deletions

View File

@@ -53,7 +53,7 @@ func NewCollector[T any](object string, _ []string) (*Collector, error) {
counters: make(map[string]Counter), counters: make(map[string]Counter),
} }
valueType := reflect.TypeFor[T]().Elem() valueType := reflect.TypeFor[T]()
if f, ok := valueType.FieldByName("Name"); ok { if f, ok := valueType.FieldByName("Name"); ok {
if f.Type.Kind() == reflect.String { if f.Type.Kind() == reflect.String {

View File

@@ -21,6 +21,22 @@ import (
"testing" "testing"
) )
// TestNewCollectorStructTypeParam guards against a regression where
// reflect.TypeFor[T]().Elem() panicked when T is a plain struct (not a pointer).
// See https://github.com/prometheus-community/windows_exporter/issues/2365
func TestNewCollectorStructTypeParam(t *testing.T) {
type systemCounterValues struct {
Name string
ProcessorQueueLength float64 `perfdata:"Processor Queue Length"`
}
_, err := NewCollector[systemCounterValues]("System", nil)
if err != nil {
t.Skipf("skipping: failed to create collector: %v", err)
}
}
func BenchmarkQueryPerformanceData(b *testing.B) { func BenchmarkQueryPerformanceData(b *testing.B) {
for b.Loop() { for b.Loop() {
_, _ = QueryPerformanceData("Global", "") _, _ = QueryPerformanceData("Global", "")