diff --git a/cns/configuration/cns_config.json b/cns/configuration/cns_config.json index 0cc1797962..16f72ef2f0 100644 --- a/cns/configuration/cns_config.json +++ b/cns/configuration/cns_config.json @@ -31,7 +31,6 @@ }, "MellanoxMonitorIntervalSecs": 30, "AZRSettings": { - "EnableAZR": false, "PopulateHomeAzCacheRetryIntervalSecs": 60 } } diff --git a/cns/configuration/configuration.go b/cns/configuration/configuration.go index dfff508051..b31ae0c7f0 100644 --- a/cns/configuration/configuration.go +++ b/cns/configuration/configuration.go @@ -93,7 +93,6 @@ type ManagedSettings struct { } type AZRSettings struct { - EnableAZR bool PopulateHomeAzCacheRetryIntervalSecs int } diff --git a/cns/configuration/configuration_test.go b/cns/configuration/configuration_test.go index 7de2d9bc1b..24f49c5701 100644 --- a/cns/configuration/configuration_test.go +++ b/cns/configuration/configuration_test.go @@ -84,7 +84,6 @@ func TestReadConfigFromFile(t *testing.T) { TelemetryBatchSizeBytes: 16384, }, AZRSettings: AZRSettings{ - EnableAZR: true, PopulateHomeAzCacheRetryIntervalSecs: 60, }, UseHTTPS: true, @@ -238,7 +237,6 @@ func TestSetCNSConfigDefaults(t *testing.T) { RefreshIntervalInHrs: 3, }, AZRSettings: AZRSettings{ - EnableAZR: true, PopulateHomeAzCacheRetryIntervalSecs: 10, }, }, @@ -261,7 +259,6 @@ func TestSetCNSConfigDefaults(t *testing.T) { RefreshIntervalInHrs: 3, }, AZRSettings: AZRSettings{ - EnableAZR: true, PopulateHomeAzCacheRetryIntervalSecs: 10, }, WireserverIP: "168.63.129.16", diff --git a/cns/configuration/testdata/good.json b/cns/configuration/testdata/good.json index a84c563792..ddc8cfb175 100644 --- a/cns/configuration/testdata/good.json +++ b/cns/configuration/testdata/good.json @@ -32,7 +32,6 @@ "UseHTTPS": true, "WireserverIP": "168.63.129.16", "AZRSettings": { - "EnableAZR": true, "PopulateHomeAzCacheRetryIntervalSecs": 60 } } diff --git a/cns/restserver/homeazmonitor.go b/cns/restserver/homeazmonitor.go index 84b1eb6676..3fb21e590f 100644 --- a/cns/restserver/homeazmonitor.go +++ b/cns/restserver/homeazmonitor.go @@ -16,7 +16,7 @@ import ( const ( GetHomeAzAPIName = "GetHomeAz" - ContextTimeOut = 2 * time.Second + ContextTimeOut = 5 * time.Second homeAzCacheKey = "HomeAz" ) @@ -62,6 +62,7 @@ func (h *HomeAzMonitor) readCacheValue() cns.GetHomeAzResponse { // Start starts a new thread to refresh home az cache func (h *HomeAzMonitor) Start() { + logger.Printf("[HomeAzMonitor] start the goroutine for refreshing homeAz") go h.refresh() } @@ -165,8 +166,12 @@ func (h *HomeAzMonitor) update(code types.ResponseCode, msg string, homeAzRespon }, HomeAzResponse: homeAzResponse, } - logger.Printf("[HomeAzMonitor] updating home az cache value: %+v", resp) - h.updateCacheValue(resp) + + // log the response and update the cache if it doesn't match with the current cached value + if h.readCacheValue() != resp { + logger.Printf("[HomeAzMonitor] updating home az cache value: %+v", resp) + h.updateCacheValue(resp) + } } // isAPISupportedByNMAgent checks if a nmagent client api slice contains a given api diff --git a/cns/service/main.go b/cns/service/main.go index 43af60290d..8958ae2021 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -650,12 +650,6 @@ func main() { return } - homeAzMonitor := restserver.NewHomeAzMonitor(nmaClient, time.Duration(cnsconfig.AZRSettings.PopulateHomeAzCacheRetryIntervalSecs)*time.Second) - if cnsconfig.AZRSettings.EnableAZR { - logger.Printf("start the goroutine for refreshing homeAz") - homeAzMonitor.Start() - } - if cnsconfig.ChannelMode == cns.Managed { config.ChannelMode = cns.Managed privateEndpoint = cnsconfig.ManagedSettings.PrivateEndpoint @@ -669,6 +663,14 @@ func main() { config.ChannelMode = cns.Managed } + homeAzMonitor := restserver.NewHomeAzMonitor(nmaClient, time.Duration(cnsconfig.AZRSettings.PopulateHomeAzCacheRetryIntervalSecs)*time.Second) + // homeAz monitor is only required when there is a direct channel between DNC and CNS. + // This will prevent the monitor from unnecessarily calling NMA APIs for other scenarios such as AKS-swift, swiftv2 + if cnsconfig.ChannelMode == cns.Direct { + homeAzMonitor.Start() + defer homeAzMonitor.Stop() + } + if telemetryDaemonEnabled { log.Printf("CNI Telemtry is enabled") go startTelemetryService(rootCtx) @@ -1015,11 +1017,6 @@ func main() { } } - if cnsconfig.AZRSettings.EnableAZR { - logger.Printf("end the goroutine for refreshing homeAz") - homeAzMonitor.Stop() - } - logger.Printf("stop cns service") // Cleanup. if httpRestService != nil {