Skip to content

Commit

Permalink
resolve import cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
ZetaoZhuang committed May 9, 2024
1 parent 2544e04 commit b100cdf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
15 changes: 8 additions & 7 deletions cns/logger/heartbeat.go → cns/internal/heartbeat.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
// Copyright 2018 Microsoft. All rights reserved.
// MIT License

package logger
package internal

import (
"context"

Check failure on line 7 in cns/internal/heartbeat.go

View workflow job for this annotation

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

File is not `gofumpt`-ed (gofumpt)

Check failure on line 7 in cns/internal/heartbeat.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

File is not `gofumpt`-ed (gofumpt)
"github.com/Azure/azure-container-networking/cns/monitor"
"github.com/Azure/azure-container-networking/cns/logger"

Check failure on line 8 in cns/internal/heartbeat.go

View workflow job for this annotation

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

File is not `gci`-ed with --skip-generated -s standard -s default (gci)

Check failure on line 8 in cns/internal/heartbeat.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
"github.com/Azure/azure-container-networking/cns/restserver"
"github.com/Azure/azure-container-networking/cns/types"
"strconv"

Check failure on line 11 in cns/internal/heartbeat.go

View workflow job for this annotation

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

File is not `gofumpt`-ed (gofumpt)

Check failure on line 11 in cns/internal/heartbeat.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

File is not `gofumpt`-ed (gofumpt)
"time"

"github.com/Azure/azure-container-networking/aitelemetry"

Check failure on line 14 in cns/internal/heartbeat.go

View workflow job for this annotation

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

File is not `gci`-ed with --skip-generated -s standard -s default (gci)

Check failure on line 14 in cns/internal/heartbeat.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
)

func SendHeartBeat(ctx context.Context, heartbeatIntervalInMins int, homeAzMonitor *monitor.HomeAzMonitor) {
func SendHeartBeat(ctx context.Context, heartbeatIntervalInMins int, homeAzMonitor *restserver.HomeAzMonitor) {
ticker := time.NewTicker(time.Minute * time.Duration(heartbeatIntervalInMins))
defer ticker.Stop()
metric := aitelemetry.Metric{
Name: HeartBeatMetricStr,
Name: logger.HeartBeatMetricStr,
// This signifies 1 heartbeat is sent. Sum of this metric will give us number of heartbeats received
Value: 1.0,
CustomDimensions: make(map[string]string),
Expand All @@ -29,11 +30,11 @@ func SendHeartBeat(ctx context.Context, heartbeatIntervalInMins int, homeAzMonit
case <-ticker.C:
getHomeAzResp := homeAzMonitor.GetHomeAz(ctx)
if getHomeAzResp.Response.ReturnCode == types.Success {
metric.CustomDimensions[IsAZRSupportedStr] = strconv.FormatBool(getHomeAzResp.HomeAzResponse.IsSupported)
metric.CustomDimensions[HomeAZStr] = strconv.FormatUint(uint64(getHomeAzResp.HomeAzResponse.HomeAz), 10)
metric.CustomDimensions[logger.IsAZRSupportedStr] = strconv.FormatBool(getHomeAzResp.HomeAzResponse.IsSupported)
metric.CustomDimensions[logger.HomeAZStr] = strconv.FormatUint(uint64(getHomeAzResp.HomeAzResponse.HomeAz), 10)
}

SendMetric(metric)
logger.SendMetric(metric)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package monitor
package restserver

import (
"context"
"fmt"
"github.com/Azure/azure-container-networking/cns/restserver"
"net/http"
"time"

Expand All @@ -22,15 +21,15 @@ const (
)

type HomeAzMonitor struct {
restserver.nmagentClient
nmagentClient
values *cache.Cache
// channel used as signal to end of the goroutine for populating home az cache
closing chan struct{}
cacheRefreshIntervalSecs time.Duration
}

// NewHomeAzMonitor creates a new HomeAzMonitor object
func NewHomeAzMonitor(client restserver.nmagentClient, cacheRefreshIntervalSecs time.Duration) *HomeAzMonitor {
func NewHomeAzMonitor(client nmagentClient, cacheRefreshIntervalSecs time.Duration) *HomeAzMonitor {
return &HomeAzMonitor{
nmagentClient: client,
cacheRefreshIntervalSecs: cacheRefreshIntervalSecs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package monitor
package restserver

import (
"context"
Expand Down
5 changes: 2 additions & 3 deletions cns/restserver/restserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package restserver

import (
"context"
"github.com/Azure/azure-container-networking/cns/monitor"
"net"
"net/http"
"net/http/pprof"
Expand Down Expand Up @@ -58,7 +57,7 @@ type HTTPRestService struct {
ipamClient *ipamclient.IpamClient
nma nmagentClient
wsproxy wireserverProxy
homeAzMonitor *monitor.HomeAzMonitor
homeAzMonitor *HomeAzMonitor
networkContainer *networkcontainers.NetworkContainers
PodIPIDByPodInterfaceKey map[string][]string // PodInterfaceId is key and value is slice of Pod IP (SecondaryIP) uuids.
PodIPConfigState map[string]cns.IPConfigurationStatus // Secondary IP ID(uuid) is key
Expand Down Expand Up @@ -159,7 +158,7 @@ type networkInfo struct {

// NewHTTPRestService creates a new HTTP Service object.
func NewHTTPRestService(config *common.ServiceConfig, wscli interfaceGetter, wsproxy wireserverProxy, nmagentClient nmagentClient,
endpointStateStore store.KeyValueStore, gen CNIConflistGenerator, homeAzMonitor *monitor.HomeAzMonitor,
endpointStateStore store.KeyValueStore, gen CNIConflistGenerator, homeAzMonitor *HomeAzMonitor,
) (*HTTPRestService, error) {
service, err := cns.NewService(config.Name, config.Version, config.ChannelMode, config.Store)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/Azure/azure-container-networking/cns/monitor"
"github.com/Azure/azure-container-networking/cns/internal"

Check failure on line 11 in cns/service/main.go

View workflow job for this annotation

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

File is not `gci`-ed with --skip-generated -s standard -s default (gci)

Check failure on line 11 in cns/service/main.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
"io/fs"
"net/http"
"os"
Expand Down Expand Up @@ -675,7 +675,7 @@ func main() {
config.ChannelMode = cns.Managed
}

homeAzMonitor := monitor.NewHomeAzMonitor(nmaClient, time.Duration(cnsconfig.AZRSettings.PopulateHomeAzCacheRetryIntervalSecs)*time.Second)
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 {
Expand Down Expand Up @@ -933,7 +933,7 @@ func main() {
}

if !disableTelemetry {
go logger.SendHeartBeat(rootCtx, cnsconfig.TelemetrySettings.HeartBeatIntervalInMins, homeAzMonitor)
go internal.SendHeartBeat(rootCtx, cnsconfig.TelemetrySettings.HeartBeatIntervalInMins, homeAzMonitor)
go httpRemoteRestService.SendNCSnapShotPeriodically(rootCtx, cnsconfig.TelemetrySettings.SnapshotIntervalInMins)
}

Expand Down

0 comments on commit b100cdf

Please sign in to comment.