Skip to content
Closed
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
22 changes: 16 additions & 6 deletions cns/restserver/homeazmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/types"
"github.com/Azure/azure-container-networking/nmagent"
"github.com/patrickmn/go-cache"
"github.com/pkg/errors"
)

Expand All @@ -22,7 +21,7 @@

type HomeAzMonitor struct {
nmagentClient
values *cache.Cache

Check failure on line 24 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

undefined: cache

Check failure on line 24 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

undefined: cache

Check failure on line 24 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

undefined: cache

Check failure on line 24 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

undefined: cache

Check failure on line 24 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

undefined: cache

Check failure on line 24 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

undefined: cache
// channel used as signal to end of the goroutine for populating home az cache
closing chan struct{}
cacheRefreshIntervalSecs time.Duration
Expand All @@ -33,7 +32,7 @@
return &HomeAzMonitor{
nmagentClient: client,
cacheRefreshIntervalSecs: cacheRefreshIntervalSecs,
values: cache.New(cache.NoExpiration, cache.NoExpiration),

Check failure on line 35 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

undefined: cache

Check failure on line 35 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

undefined: cache

Check failure on line 35 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

undefined: cache

Check failure on line 35 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

undefined: cache
closing: make(chan struct{}),
}
}
Expand All @@ -45,19 +44,30 @@

// updateCacheValue updates home az cache value
func (h *HomeAzMonitor) updateCacheValue(resp cns.GetHomeAzResponse) {
h.values.Set(homeAzCacheKey, resp, cache.NoExpiration)

Check failure on line 47 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

undefined: cache) (typecheck)

Check failure on line 47 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, ubuntu-latest)

undefined: cache) (typecheck)

Check failure on line 47 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

undefined: cache) (typecheck)

Check failure on line 47 in cns/restserver/homeazmonitor.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, ubuntu-latest)

undefined: cache) (typecheck)
}

// readCacheValue reads home az cache value
func (h *HomeAzMonitor) readCacheValue() cns.GetHomeAzResponse {
cachedResp, found := h.values.Get(homeAzCacheKey)
if !found {
return cns.GetHomeAzResponse{Response: cns.Response{
if cachedResp, found := h.values.Get(homeAzCacheKey); found {
return cachedResp.(cns.GetHomeAzResponse)
}

ctx, cancel := context.WithTimeout(context.Background(), ContextTimeOut)
defer cancel()
h.Populate(ctx)

if cachedResp, found := h.values.Get(homeAzCacheKey); found {
return cachedResp.(cns.GetHomeAzResponse)
}

return cns.GetHomeAzResponse{
Response: cns.Response{
ReturnCode: types.NotFound,
Message: "HomeAz Cache is unavailable",
}, HomeAzResponse: cns.HomeAzResponse{IsSupported: false}}
},
HomeAzResponse: cns.HomeAzResponse{IsSupported: false},
}
return cachedResp.(cns.GetHomeAzResponse)
}

// Start starts a new thread to refresh home az cache
Expand Down
Loading