From 0158a1c744c2203c99d768ffcb58ed08dba59f32 Mon Sep 17 00:00:00 2001 From: dhurley Date: Fri, 4 Nov 2022 16:36:51 +0000 Subject: [PATCH] Added new DataplaneSoftwareDetailsUpdated topic for all extensions to use --- src/core/topics.go | 2 +- src/plugins/dataplane_status.go | 24 ++++++++----------- src/plugins/dataplane_status_test.go | 4 ++-- src/plugins/nginx_app_protect.go | 4 ++-- .../nginx/agent/v2/src/core/topics.go | 2 +- .../agent/v2/src/plugins/dataplane_status.go | 24 ++++++++----------- .../agent/v2/src/plugins/nginx_app_protect.go | 4 ++-- 7 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/core/topics.go b/src/core/topics.go index 9c251993c..41dc95b57 100644 --- a/src/core/topics.go +++ b/src/core/topics.go @@ -43,6 +43,6 @@ const ( Events = "events" FileWatcherEnabled = "file.watcher.enabled" ConfigRollbackResponse = "config.rollback.response" - NginxAppProtectDetailsGenerated = "nap.details.generated" + DataplaneSoftwareDetailsUpdated = "dataplane.software.details.updated" EnableExtension = "enable.extension" ) diff --git a/src/plugins/dataplane_status.go b/src/plugins/dataplane_status.go index 8a8eda177..a7da42d7c 100644 --- a/src/plugins/dataplane_status.go +++ b/src/plugins/dataplane_status.go @@ -82,12 +82,17 @@ func (dps *DataPlaneStatus) Info() *core.Info { func (dps *DataPlaneStatus) Process(msg *core.Message) { switch { case msg.Exact(core.AgentConfigChanged): + log.Tracef("DataplaneStatus: %T message from topic %s received", msg.Data(), msg.Topic()) // If the agent config on disk changed update DataPlaneStatus with relevant config info dps.syncAgentConfigChange() - case msg.Exact(core.NginxAppProtectDetailsGenerated): - // If a NAP report was generated sync it - dps.syncNAPDetails(msg) + case msg.Exact(core.DataplaneSoftwareDetailsUpdated): + log.Tracef("DataplaneStatus: %T message from topic %s received", msg.Data(), msg.Topic()) + switch data := msg.Data().(type) { + case *proto.DataplaneSoftwareDetails_AppProtectWafDetails: + log.Debugf("DataplaneStatus is syncing with NAP details - %+v", data.AppProtectWafDetails) + dps.napDetails = data + } case msg.Exact(core.NginxConfigValidationPending): log.Tracef("DataplaneStatus: %T message from topic %s received", msg.Data(), msg.Topic()) @@ -97,6 +102,7 @@ func (dps *DataPlaneStatus) Process(msg *core.Message) { default: log.Errorf("Expected the type %T but got %T", &proto.AgentActivityStatus{}, data) } + case msg.Exact(core.NginxConfigApplyFailed) || msg.Exact(core.NginxConfigApplySucceeded): log.Tracef("DataplaneStatus: %T message from topic %s received", msg.Data(), msg.Topic()) switch data := msg.Data().(type) { @@ -113,7 +119,7 @@ func (dps *DataPlaneStatus) Process(msg *core.Message) { func (dps *DataPlaneStatus) Subscriptions() []string { return []string{ core.AgentConfigChanged, - core.NginxAppProtectDetailsGenerated, + core.DataplaneSoftwareDetailsUpdated, core.NginxConfigValidationPending, core.NginxConfigApplyFailed, core.NginxConfigApplySucceeded, @@ -325,13 +331,3 @@ func (dps *DataPlaneStatus) syncAgentConfigChange() { dps.tags = &conf.Tags dps.configDirs = conf.ConfigDirs } - -func (dps *DataPlaneStatus) syncNAPDetails(msg *core.Message) { - switch commandData := msg.Data().(type) { - case *proto.DataplaneSoftwareDetails_AppProtectWafDetails: - log.Debugf("DataPlaneStatus is syncing with NAP details - %+v", commandData.AppProtectWafDetails) - dps.napDetails = commandData - default: - log.Errorf("Expected the type %T but got %T", &proto.DataplaneSoftwareDetails_AppProtectWafDetails{}, commandData) - } -} diff --git a/src/plugins/dataplane_status_test.go b/src/plugins/dataplane_status_test.go index b5377ff10..898c4d19e 100644 --- a/src/plugins/dataplane_status_test.go +++ b/src/plugins/dataplane_status_test.go @@ -315,7 +315,7 @@ func TestDPSSyncNAPDetails(t *testing.T) { assert.Equal(t, tc.initialNAPDetails, dataPlaneStatus.napDetails) // Send updated NAP details message - dataPlaneStatus.Process(core.NewMessage(core.NginxAppProtectDetailsGenerated, tc.updatedNAPDetails)) + dataPlaneStatus.Process(core.NewMessage(core.DataplaneSoftwareDetailsUpdated, tc.updatedNAPDetails)) // Check if NAP details were updated assert.Equal(t, tc.updatedNAPDetails, dataPlaneStatus.napDetails) @@ -326,7 +326,7 @@ func TestDPSSyncNAPDetails(t *testing.T) { func TestDataPlaneSubscriptions(t *testing.T) { expectedSubscriptions := []string{ core.AgentConfigChanged, - core.NginxAppProtectDetailsGenerated, + core.DataplaneSoftwareDetailsUpdated, core.NginxConfigValidationPending, core.NginxConfigApplyFailed, core.NginxConfigApplySucceeded, diff --git a/src/plugins/nginx_app_protect.go b/src/plugins/nginx_app_protect.go index dd078a49c..83b455f1b 100644 --- a/src/plugins/nginx_app_protect.go +++ b/src/plugins/nginx_app_protect.go @@ -108,7 +108,7 @@ func (n *NginxAppProtect) addSoftwareDetailsToRegistration(msg *core.Message) { func (n *NginxAppProtect) monitor() { initialDetails := n.generateNAPDetailsProtoCommand() log.Infof("Initial Nginx App Protect details: %+v", initialDetails) - n.messagePipeline.Process(core.NewMessage(core.NginxAppProtectDetailsGenerated, initialDetails)) + n.messagePipeline.Process(core.NewMessage(core.DataplaneSoftwareDetailsUpdated, initialDetails)) napUpdateChannel := n.nap.Monitor(n.reportInterval) @@ -119,7 +119,7 @@ func (n *NginxAppProtect) monitor() { // Communicate the update in NAP status via message pipeline log.Infof("Change in NAP detected... Previous: %+v... Updated: %+v", updateMsg.PreviousReport, updateMsg.UpdatedReport) napReportMsg := n.generateNAPDetailsProtoCommand() - n.messagePipeline.Process(core.NewMessage(core.NginxAppProtectDetailsGenerated, napReportMsg)) + n.messagePipeline.Process(core.NewMessage(core.DataplaneSoftwareDetailsUpdated, napReportMsg)) case <-time.After(n.reportInterval): log.Infof("No NAP changes detected after %v seconds... NAP Values: %+v", n.reportInterval.Seconds(), n.nap.GenerateNAPReport()) diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/core/topics.go b/test/performance/vendor/github.com/nginx/agent/v2/src/core/topics.go index 9c251993c..41dc95b57 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/core/topics.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/core/topics.go @@ -43,6 +43,6 @@ const ( Events = "events" FileWatcherEnabled = "file.watcher.enabled" ConfigRollbackResponse = "config.rollback.response" - NginxAppProtectDetailsGenerated = "nap.details.generated" + DataplaneSoftwareDetailsUpdated = "dataplane.software.details.updated" EnableExtension = "enable.extension" ) diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/dataplane_status.go b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/dataplane_status.go index 8a8eda177..a7da42d7c 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/dataplane_status.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/dataplane_status.go @@ -82,12 +82,17 @@ func (dps *DataPlaneStatus) Info() *core.Info { func (dps *DataPlaneStatus) Process(msg *core.Message) { switch { case msg.Exact(core.AgentConfigChanged): + log.Tracef("DataplaneStatus: %T message from topic %s received", msg.Data(), msg.Topic()) // If the agent config on disk changed update DataPlaneStatus with relevant config info dps.syncAgentConfigChange() - case msg.Exact(core.NginxAppProtectDetailsGenerated): - // If a NAP report was generated sync it - dps.syncNAPDetails(msg) + case msg.Exact(core.DataplaneSoftwareDetailsUpdated): + log.Tracef("DataplaneStatus: %T message from topic %s received", msg.Data(), msg.Topic()) + switch data := msg.Data().(type) { + case *proto.DataplaneSoftwareDetails_AppProtectWafDetails: + log.Debugf("DataplaneStatus is syncing with NAP details - %+v", data.AppProtectWafDetails) + dps.napDetails = data + } case msg.Exact(core.NginxConfigValidationPending): log.Tracef("DataplaneStatus: %T message from topic %s received", msg.Data(), msg.Topic()) @@ -97,6 +102,7 @@ func (dps *DataPlaneStatus) Process(msg *core.Message) { default: log.Errorf("Expected the type %T but got %T", &proto.AgentActivityStatus{}, data) } + case msg.Exact(core.NginxConfigApplyFailed) || msg.Exact(core.NginxConfigApplySucceeded): log.Tracef("DataplaneStatus: %T message from topic %s received", msg.Data(), msg.Topic()) switch data := msg.Data().(type) { @@ -113,7 +119,7 @@ func (dps *DataPlaneStatus) Process(msg *core.Message) { func (dps *DataPlaneStatus) Subscriptions() []string { return []string{ core.AgentConfigChanged, - core.NginxAppProtectDetailsGenerated, + core.DataplaneSoftwareDetailsUpdated, core.NginxConfigValidationPending, core.NginxConfigApplyFailed, core.NginxConfigApplySucceeded, @@ -325,13 +331,3 @@ func (dps *DataPlaneStatus) syncAgentConfigChange() { dps.tags = &conf.Tags dps.configDirs = conf.ConfigDirs } - -func (dps *DataPlaneStatus) syncNAPDetails(msg *core.Message) { - switch commandData := msg.Data().(type) { - case *proto.DataplaneSoftwareDetails_AppProtectWafDetails: - log.Debugf("DataPlaneStatus is syncing with NAP details - %+v", commandData.AppProtectWafDetails) - dps.napDetails = commandData - default: - log.Errorf("Expected the type %T but got %T", &proto.DataplaneSoftwareDetails_AppProtectWafDetails{}, commandData) - } -} diff --git a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nginx_app_protect.go b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nginx_app_protect.go index dd078a49c..83b455f1b 100644 --- a/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nginx_app_protect.go +++ b/test/performance/vendor/github.com/nginx/agent/v2/src/plugins/nginx_app_protect.go @@ -108,7 +108,7 @@ func (n *NginxAppProtect) addSoftwareDetailsToRegistration(msg *core.Message) { func (n *NginxAppProtect) monitor() { initialDetails := n.generateNAPDetailsProtoCommand() log.Infof("Initial Nginx App Protect details: %+v", initialDetails) - n.messagePipeline.Process(core.NewMessage(core.NginxAppProtectDetailsGenerated, initialDetails)) + n.messagePipeline.Process(core.NewMessage(core.DataplaneSoftwareDetailsUpdated, initialDetails)) napUpdateChannel := n.nap.Monitor(n.reportInterval) @@ -119,7 +119,7 @@ func (n *NginxAppProtect) monitor() { // Communicate the update in NAP status via message pipeline log.Infof("Change in NAP detected... Previous: %+v... Updated: %+v", updateMsg.PreviousReport, updateMsg.UpdatedReport) napReportMsg := n.generateNAPDetailsProtoCommand() - n.messagePipeline.Process(core.NewMessage(core.NginxAppProtectDetailsGenerated, napReportMsg)) + n.messagePipeline.Process(core.NewMessage(core.DataplaneSoftwareDetailsUpdated, napReportMsg)) case <-time.After(n.reportInterval): log.Infof("No NAP changes detected after %v seconds... NAP Values: %+v", n.reportInterval.Seconds(), n.nap.GenerateNAPReport())