Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add azr metrics in heartbeats #2735

Merged
merged 10 commits into from
Jun 5, 2024
41 changes: 41 additions & 0 deletions cns/internal/heartbeat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2018 Microsoft. All rights reserved.
// MIT License

package internal
ZetaoZhuang marked this conversation as resolved.
Show resolved Hide resolved

import (
"context"
"strconv"
"time"

"github.com/Azure/azure-container-networking/aitelemetry"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/restserver"
"github.com/Azure/azure-container-networking/cns/types"
)

smittal22 marked this conversation as resolved.
Show resolved Hide resolved
// SendHeartBeat emits node metrics periodically
func SendHeartBeat(ctx context.Context, heartbeatInterval time.Duration, homeAzMonitor *restserver.HomeAzMonitor) {
ticker := time.NewTicker(heartbeatInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
metric := aitelemetry.Metric{
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),
}
getHomeAzResp := homeAzMonitor.GetHomeAz(ctx)
ZetaoZhuang marked this conversation as resolved.
Show resolved Hide resolved
if getHomeAzResp.Response.ReturnCode == types.Success {
metric.CustomDimensions[logger.IsAZRSupportedStr] = strconv.FormatBool(getHomeAzResp.HomeAzResponse.IsSupported)
metric.CustomDimensions[logger.HomeAZStr] = strconv.FormatUint(uint64(getHomeAzResp.HomeAzResponse.HomeAz), 10)
}

logger.SendMetric(metric)
smittal22 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
2 changes: 2 additions & 0 deletions cns/logger/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const (
// Dimensions
OrchestratorTypeStr = "OrchestratorType"
NodeIDStr = "NodeID"
HomeAZStr = "HomeAZ"
IsAZRSupportedStr = "IsAZRSupported"
// CNS Snspshot properties
CnsNCSnapshotEventStr = "CNSNCSnapshot"
IpConfigurationStr = "IPConfiguration"
Expand Down
30 changes: 0 additions & 30 deletions cns/logger/heartbeat.go

This file was deleted.

3 changes: 2 additions & 1 deletion cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/Azure/azure-container-networking/cns/healthserver"
"github.com/Azure/azure-container-networking/cns/hnsclient"
"github.com/Azure/azure-container-networking/cns/imds"
"github.com/Azure/azure-container-networking/cns/internal"
"github.com/Azure/azure-container-networking/cns/ipampool"
ipampoolv2 "github.com/Azure/azure-container-networking/cns/ipampool/v2"
cssctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/clustersubnetstate"
Expand Down Expand Up @@ -932,7 +933,7 @@ func main() {
}

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

Expand Down
Loading