Compare commits

..

2 Commits

Author SHA1 Message Date
Jan-Otto Kröpke
20762588b3 container: fix deserialize HNS response in GetHNSEndpointStats (#2379) (#2380)
Co-authored-by: Stefan L. <116070569+slab-msft@users.noreply.github.com>
2026-04-01 16:39:59 +02:00
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
3 changed files with 28 additions and 4 deletions

View File

@@ -75,13 +75,21 @@ func GetHNSEndpointStats(endpointID string) (EndpointStats, error) {
return EndpointStats{}, err return EndpointStats{}, err
} }
var stats EndpointStats var response struct {
Success bool `json:"Success"`
Error string `json:"Error"`
Output EndpointStats `json:"Output"`
}
if err := json.Unmarshal([]byte(result), &stats); err != nil { if err := json.Unmarshal([]byte(result), &response); err != nil {
return EndpointStats{}, fmt.Errorf("failed to unmarshal JSON %s: %w", result, err) return EndpointStats{}, fmt.Errorf("failed to unmarshal JSON %s: %w", result, err)
} }
return stats, nil if !response.Success {
return EndpointStats{}, fmt.Errorf("HNSCall failed: %s", response.Error)
}
return response.Output, nil
} }
func hnsCall(method, path, body *uint16) (string, error) { func hnsCall(method, path, body *uint16) (string, error) {

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", "")