From b1a9c05cdd2c086e7bf9f3a9a825ede87589bb6b Mon Sep 17 00:00:00 2001 From: Aphral Griffin Date: Mon, 25 Sep 2023 14:03:43 +0100 Subject: [PATCH 1/4] fix memory metrics --- sdk/config_helpers_test.go | 3 +-- src/core/metrics/sources/mem.go | 4 ++-- .../github.com/nginx/agent/v2/src/core/metrics/sources/mem.go | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sdk/config_helpers_test.go b/sdk/config_helpers_test.go index 4cae45d43..086a49243 100644 --- a/sdk/config_helpers_test.go +++ b/sdk/config_helpers_test.go @@ -2104,7 +2104,7 @@ func TestSslDirectives(t *testing.T) { }` // preparing test cases as well as expected results - var tests = []struct { + tests := []struct { algoName string config string expected struct { @@ -2251,6 +2251,5 @@ func TestSslDirectives(t *testing.T) { assert.Equal(t, certMeta.PublicKeyAlgorithm, cert.PublicKeyAlgorithm) } }) - } } diff --git a/src/core/metrics/sources/mem.go b/src/core/metrics/sources/mem.go index c208ec026..6531b8b7c 100644 --- a/src/core/metrics/sources/mem.go +++ b/src/core/metrics/sources/mem.go @@ -52,8 +52,8 @@ func (c *VirtualMemory) Collect(ctx context.Context, wg *sync.WaitGroup, m chan< simpleMetrics := c.convertSamplesToSimpleMetrics(map[string]float64{ "total": float64(memstats.Total), - "used": float64(memstats.Total - memstats.Available), - "used.all": float64(memstats.Used), + "used": float64(memstats.Used), + "used.all": float64(memstats.Total - memstats.Available), "cached": float64(memstats.Cached), "buffered": float64(memstats.Buffers), "shared": float64(memstats.Shared), diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/mem.go b/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/mem.go index c208ec026..6531b8b7c 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/mem.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/mem.go @@ -52,8 +52,8 @@ func (c *VirtualMemory) Collect(ctx context.Context, wg *sync.WaitGroup, m chan< simpleMetrics := c.convertSamplesToSimpleMetrics(map[string]float64{ "total": float64(memstats.Total), - "used": float64(memstats.Total - memstats.Available), - "used.all": float64(memstats.Used), + "used": float64(memstats.Used), + "used.all": float64(memstats.Total - memstats.Available), "cached": float64(memstats.Cached), "buffered": float64(memstats.Buffers), "shared": float64(memstats.Shared), From 7c16ba2be2311b25705d39518bd5c0921bf7a499 Mon Sep 17 00:00:00 2001 From: Aphral Griffin Date: Mon, 25 Sep 2023 17:13:37 +0100 Subject: [PATCH 2/4] log test --- test/integration/grpc/grpc_config_apply_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/integration/grpc/grpc_config_apply_test.go b/test/integration/grpc/grpc_config_apply_test.go index 426dc0b90..87b8bec3e 100644 --- a/test/integration/grpc/grpc_config_apply_test.go +++ b/test/integration/grpc/grpc_config_apply_test.go @@ -150,8 +150,11 @@ messageLoop: for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Send config apply message - - err := commandService.SendConfigApply(nginxId, tt.nginxConfigFileName, tt.messageId) + response, err:= utils.ExecuteCommand(testContainer, []string{"ps","-ef","|","grep","nginx"}) + log.Info("=====================================") + log.Info(response) + log.Info(err) + err = commandService.SendConfigApply(nginxId, tt.nginxConfigFileName, tt.messageId) assert.NoError(t, err) // Validate that the config apply is successful From 53232e786026da150ac8c01701514b50f1b6d5fc Mon Sep 17 00:00:00 2001 From: Aphral Griffin Date: Tue, 26 Sep 2023 09:08:41 +0100 Subject: [PATCH 3/4] clean up --- test/integration/grpc/grpc_config_apply_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/integration/grpc/grpc_config_apply_test.go b/test/integration/grpc/grpc_config_apply_test.go index 87b8bec3e..dd68e186c 100644 --- a/test/integration/grpc/grpc_config_apply_test.go +++ b/test/integration/grpc/grpc_config_apply_test.go @@ -150,10 +150,8 @@ messageLoop: for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Send config apply message - response, err:= utils.ExecuteCommand(testContainer, []string{"ps","-ef","|","grep","nginx"}) - log.Info("=====================================") - log.Info(response) - log.Info(err) + response, err := utils.ExecuteCommand(testContainer, []string{"ps", "-ef", "|", "grep", "nginx"}) + t.Logf("response: %v", response) err = commandService.SendConfigApply(nginxId, tt.nginxConfigFileName, tt.messageId) assert.NoError(t, err) From c6a86eb174bb62a86b12ca14ae053ffbb2af177c Mon Sep 17 00:00:00 2001 From: Aphral Griffin Date: Tue, 3 Oct 2023 11:09:05 +0100 Subject: [PATCH 4/4] deprecate used all metric --- src/core/metrics/metrics_util.go | 1 - src/core/metrics/sources/mem.go | 1 - src/core/metrics/sources/mem_test.go | 1 - test/integration/api/api_test.go | 4 ---- .../nginx/agent/v2/src/core/metrics/metrics_util.go | 1 - .../github.com/nginx/agent/v2/src/core/metrics/sources/mem.go | 1 - 6 files changed, 9 deletions(-) diff --git a/src/core/metrics/metrics_util.go b/src/core/metrics/metrics_util.go index 288cca013..43b2ea738 100644 --- a/src/core/metrics/metrics_util.go +++ b/src/core/metrics/metrics_util.go @@ -140,7 +140,6 @@ func GetCalculationMap() map[string]string { "system.mem.shared": "avg", "system.mem.total": "avg", "system.mem.used": "avg", - "system.mem.used.all": "avg", "system.load.1": "avg", "system.load.15": "avg", "system.load.5": "avg", diff --git a/src/core/metrics/sources/mem.go b/src/core/metrics/sources/mem.go index 6531b8b7c..77e801ca8 100644 --- a/src/core/metrics/sources/mem.go +++ b/src/core/metrics/sources/mem.go @@ -53,7 +53,6 @@ func (c *VirtualMemory) Collect(ctx context.Context, wg *sync.WaitGroup, m chan< simpleMetrics := c.convertSamplesToSimpleMetrics(map[string]float64{ "total": float64(memstats.Total), "used": float64(memstats.Used), - "used.all": float64(memstats.Total - memstats.Available), "cached": float64(memstats.Cached), "buffered": float64(memstats.Buffers), "shared": float64(memstats.Shared), diff --git a/src/core/metrics/sources/mem_test.go b/src/core/metrics/sources/mem_test.go index 901819d33..1847f453f 100644 --- a/src/core/metrics/sources/mem_test.go +++ b/src/core/metrics/sources/mem_test.go @@ -79,7 +79,6 @@ func TestVirtualMemoryCollect(t *testing.T) { "test.mem.shared", "test.mem.total", "test.mem.used", - "test.mem.used.all", } assert.Equal(t, expected, actualMetricNames) diff --git a/test/integration/api/api_test.go b/test/integration/api/api_test.go index 1f648d9b5..8536683b5 100644 --- a/test/integration/api/api_test.go +++ b/test/integration/api/api_test.go @@ -90,10 +90,6 @@ func TestAPI_Metrics(t *testing.T) { value, _ := strconv.ParseFloat(metric[1], 64) assert.Greater(t, value, float64(0)) - case strings.Contains(metric[0], "system_mem_used_all"): - value, _ := strconv.ParseFloat(metric[1], 64) - assert.Greater(t, value, float64(0)) - case strings.Contains(metric[0], "container_cpu_cores"): value, _ := strconv.ParseFloat(metric[1], 64) assert.Greater(t, value, float64(0)) diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/metrics_util.go b/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/metrics_util.go index 288cca013..43b2ea738 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/metrics_util.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/metrics_util.go @@ -140,7 +140,6 @@ func GetCalculationMap() map[string]string { "system.mem.shared": "avg", "system.mem.total": "avg", "system.mem.used": "avg", - "system.mem.used.all": "avg", "system.load.1": "avg", "system.load.15": "avg", "system.load.5": "avg", diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/mem.go b/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/mem.go index 6531b8b7c..77e801ca8 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/mem.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/core/metrics/sources/mem.go @@ -53,7 +53,6 @@ func (c *VirtualMemory) Collect(ctx context.Context, wg *sync.WaitGroup, m chan< simpleMetrics := c.convertSamplesToSimpleMetrics(map[string]float64{ "total": float64(memstats.Total), "used": float64(memstats.Used), - "used.all": float64(memstats.Total - memstats.Available), "cached": float64(memstats.Cached), "buffered": float64(memstats.Buffers), "shared": float64(memstats.Shared),