From 0dde03511f08b958528a48650b9ee127258b0017 Mon Sep 17 00:00:00 2001 From: Donal Hurley Date: Thu, 21 Sep 2023 13:20:24 +0100 Subject: [PATCH] Add error log if duplicate NGINX IDs are found due to multiple NGINX instances running. (#477) --- src/core/nginx.go | 11 +++++++++++ .../github.com/nginx/agent/v2/src/core/nginx.go | 11 +++++++++++ .../github.com/nginx/agent/v2/src/core/nginx.go | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/core/nginx.go b/src/core/nginx.go index f29f410ee..a1dda677e 100644 --- a/src/core/nginx.go +++ b/src/core/nginx.go @@ -123,14 +123,25 @@ func (n *NginxBinaryType) UpdateNginxDetailsFromProcesses(nginxProcesses []*Proc n.statusUrls = map[string]string{} n.statusUrlMutex.Unlock() + numberOfMasterProcesses := 0 + for _, process := range nginxProcesses { nginxDetails := n.GetNginxDetailsFromProcess(process) if process.IsMaster { + numberOfMasterProcesses++ n.nginxDetailsMap[nginxDetails.GetNginxId()] = nginxDetails } else { n.nginxWorkersMap[nginxDetails.GetNginxId()] = append(n.nginxWorkersMap[nginxDetails.GetNginxId()], nginxDetails) } } + + if len(n.nginxDetailsMap) != numberOfMasterProcesses { + log.Errorf( + "Multiple NGINX master processes detected with the same NGINX ID. Number of master processes is %d. Number of unique NGINX IDs is %d.", + numberOfMasterProcesses, + len(n.nginxDetailsMap), + ) + } } func (n *NginxBinaryType) GetChildProcesses() map[string][]*proto.NginxDetails { diff --git a/test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go b/test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go index f29f410ee..a1dda677e 100644 --- a/test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go +++ b/test/integration/vendor/github.com/nginx/agent/v2/src/core/nginx.go @@ -123,14 +123,25 @@ func (n *NginxBinaryType) UpdateNginxDetailsFromProcesses(nginxProcesses []*Proc n.statusUrls = map[string]string{} n.statusUrlMutex.Unlock() + numberOfMasterProcesses := 0 + for _, process := range nginxProcesses { nginxDetails := n.GetNginxDetailsFromProcess(process) if process.IsMaster { + numberOfMasterProcesses++ n.nginxDetailsMap[nginxDetails.GetNginxId()] = nginxDetails } else { n.nginxWorkersMap[nginxDetails.GetNginxId()] = append(n.nginxWorkersMap[nginxDetails.GetNginxId()], nginxDetails) } } + + if len(n.nginxDetailsMap) != numberOfMasterProcesses { + log.Errorf( + "Multiple NGINX master processes detected with the same NGINX ID. Number of master processes is %d. Number of unique NGINX IDs is %d.", + numberOfMasterProcesses, + len(n.nginxDetailsMap), + ) + } } func (n *NginxBinaryType) GetChildProcesses() map[string][]*proto.NginxDetails { diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go b/test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go index f29f410ee..a1dda677e 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/core/nginx.go @@ -123,14 +123,25 @@ func (n *NginxBinaryType) UpdateNginxDetailsFromProcesses(nginxProcesses []*Proc n.statusUrls = map[string]string{} n.statusUrlMutex.Unlock() + numberOfMasterProcesses := 0 + for _, process := range nginxProcesses { nginxDetails := n.GetNginxDetailsFromProcess(process) if process.IsMaster { + numberOfMasterProcesses++ n.nginxDetailsMap[nginxDetails.GetNginxId()] = nginxDetails } else { n.nginxWorkersMap[nginxDetails.GetNginxId()] = append(n.nginxWorkersMap[nginxDetails.GetNginxId()], nginxDetails) } } + + if len(n.nginxDetailsMap) != numberOfMasterProcesses { + log.Errorf( + "Multiple NGINX master processes detected with the same NGINX ID. Number of master processes is %d. Number of unique NGINX IDs is %d.", + numberOfMasterProcesses, + len(n.nginxDetailsMap), + ) + } } func (n *NginxBinaryType) GetChildProcesses() map[string][]*proto.NginxDetails {