From ea4805a8aea36b772369931862b938d9143be518 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Tue, 10 Dec 2024 13:28:06 +0530 Subject: [PATCH 1/3] fix: fix performance counters --- metric/cpu/cpu_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metric/cpu/cpu_windows.go b/metric/cpu/cpu_windows.go index c1de79cad..71cbfd83b 100644 --- a/metric/cpu/cpu_windows.go +++ b/metric/cpu/cpu_windows.go @@ -50,7 +50,7 @@ func New(hostfs resolve.Resolver, opts ...OptionFunc) (*Monitor, error) { for _, o := range opts { o(&op) } - if !op.usePerformanceCounter { + if op.usePerformanceCounter { if query, err = buildQuery(); err != nil { return nil, err } From 2815f4fc40ca14ffb8a1a98ba16d7b1fbe77c0ac Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Tue, 10 Dec 2024 13:37:43 +0530 Subject: [PATCH 2/3] fix: update tests --- metric/cpu/metric_windows_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/metric/cpu/metric_windows_test.go b/metric/cpu/metric_windows_test.go index 3cfaf75cc..a9aab4925 100644 --- a/metric/cpu/metric_windows_test.go +++ b/metric/cpu/metric_windows_test.go @@ -28,7 +28,7 @@ import ( ) func TestCounterLength(t *testing.T) { - monitor, err := New(systemtests.DockerTestResolver()) + monitor, err := New(systemtests.DockerTestResolver(), WithWindowsPerformanceCounter()) require.NoError(t, err) require.NoError(t, monitor.query.CollectData()) @@ -52,3 +52,9 @@ func TestCounterLength(t *testing.T) { require.Equal(t, kernelRawData[i].InstanceName, idleRawData[i].InstanceName, "InstanceName should be equal") } } + +func TestCounterDisabled(t *testing.T) { + monitor, err := New(systemtests.DockerTestResolver(), WithWindowsPerformanceCounter()) + require.NoError(t, err) + require.Nil(t, monitor.query) +} From a5688eb9ec958680acf8f52c4a4272ea5098ac12 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Tue, 10 Dec 2024 13:49:24 +0530 Subject: [PATCH 3/3] fix: tests --- metric/cpu/metric_windows_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metric/cpu/metric_windows_test.go b/metric/cpu/metric_windows_test.go index a9aab4925..3ddce0b70 100644 --- a/metric/cpu/metric_windows_test.go +++ b/metric/cpu/metric_windows_test.go @@ -54,7 +54,7 @@ func TestCounterLength(t *testing.T) { } func TestCounterDisabled(t *testing.T) { - monitor, err := New(systemtests.DockerTestResolver(), WithWindowsPerformanceCounter()) + monitor, err := New(systemtests.DockerTestResolver()) require.NoError(t, err) require.Nil(t, monitor.query) }