Skip to content

Commit

Permalink
tcp: fix panic on collector (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke authored Oct 17, 2024
1 parent 92b7e44 commit ce2df38
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/collector/tcp/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ import (
func BenchmarkCollector(b *testing.B) {
testutils.FuncBenchmarkCollector(b, tcp.Name, tcp.NewWithFlags)
}

func TestCollector(t *testing.T) {
testutils.TestCollector(t, tcp.New, nil)
}
2 changes: 1 addition & 1 deletion internal/perfdata/v1/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *Collector) Collect() (map[string]map[string]perftypes.CounterValues, er
return nil, fmt.Errorf("QueryPerformanceData: %w", err)
}

if len(perfObjects) == 0 {
if len(perfObjects) == 0 || perfObjects[0] == nil || len(perfObjects[0].Instances) == 0 {
return map[string]map[string]perftypes.CounterValues{}, nil
}

Expand Down
4 changes: 4 additions & 0 deletions internal/perfdata/v1/perflib.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ func QueryPerformanceData(query string, counterName string) ([]*PerfObject, erro
}
}

if counterName != "" {
return objects[i : i+1], nil
}

// Next perfObjectType
objOffset += int64(obj.TotalByteLength)
numFilteredObjects++
Expand Down

0 comments on commit ce2df38

Please sign in to comment.