Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cns/configuration/cns_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
},
"MellanoxMonitorIntervalSecs": 30,
"AZRSettings": {
"EnableAZR": false,
"PopulateHomeAzCacheRetryIntervalSecs": 60
}
}
1 change: 0 additions & 1 deletion cns/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ type ManagedSettings struct {
}

type AZRSettings struct {
EnableAZR bool
PopulateHomeAzCacheRetryIntervalSecs int
}

Expand Down
3 changes: 0 additions & 3 deletions cns/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func TestReadConfigFromFile(t *testing.T) {
TelemetryBatchSizeBytes: 16384,
},
AZRSettings: AZRSettings{
EnableAZR: true,
PopulateHomeAzCacheRetryIntervalSecs: 60,
},
UseHTTPS: true,
Expand Down Expand Up @@ -238,7 +237,6 @@ func TestSetCNSConfigDefaults(t *testing.T) {
RefreshIntervalInHrs: 3,
},
AZRSettings: AZRSettings{
EnableAZR: true,
PopulateHomeAzCacheRetryIntervalSecs: 10,
},
},
Expand All @@ -261,7 +259,6 @@ func TestSetCNSConfigDefaults(t *testing.T) {
RefreshIntervalInHrs: 3,
},
AZRSettings: AZRSettings{
EnableAZR: true,
PopulateHomeAzCacheRetryIntervalSecs: 10,
},
WireserverIP: "168.63.129.16",
Expand Down
1 change: 0 additions & 1 deletion cns/configuration/testdata/good.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"UseHTTPS": true,
"WireserverIP": "168.63.129.16",
"AZRSettings": {
"EnableAZR": true,
"PopulateHomeAzCacheRetryIntervalSecs": 60
}
}
11 changes: 8 additions & 3 deletions cns/restserver/homeazmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

const (
GetHomeAzAPIName = "GetHomeAz"
ContextTimeOut = 2 * time.Second
ContextTimeOut = 5 * time.Second
homeAzCacheKey = "HomeAz"
)

Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down