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
5 changes: 5 additions & 0 deletions cns/logger/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const (
// Dimensions
OrchestratorTypeStr = "OrchestratorType"
NodeIDStr = "NodeID"
HomeAZStr = "HomeAZ"
IsAZRSupportedStr = "IsAZRSupported"
HomeAZErrorCodeStr = "HomeAZErrorCode"
HomeAZErrorMsgStr = "HomeAZErrorMsg"

// CNS Snspshot properties
CnsNCSnapshotEventStr = "CNSNCSnapshot"
IpConfigurationStr = "IPConfiguration"
Expand Down
30 changes: 0 additions & 30 deletions cns/logger/heartbeat.go

This file was deleted.

50 changes: 50 additions & 0 deletions cns/metric/heartbeat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2018 Microsoft. All rights reserved.
// MIT License

package metric
ramiro-gamarra 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"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/restserver"
"github.com/Azure/azure-container-networking/cns/types"
)

// SendHeartBeat emits node metrics periodically
func SendHeartBeat(ctx context.Context, heartbeatInterval time.Duration, homeAzMonitor *restserver.HomeAzMonitor, channelMode string) {
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),
}

// add azr metrics when channel mode is direct
if channelMode == cns.Direct {
getHomeAzResp := homeAzMonitor.GetHomeAz(ctx)
switch getHomeAzResp.Response.ReturnCode { //nolint:exhaustive // ignore exhaustive types check
case types.Success:
metric.CustomDimensions[logger.IsAZRSupportedStr] = strconv.FormatBool(getHomeAzResp.HomeAzResponse.IsSupported)
metric.CustomDimensions[logger.HomeAZStr] = strconv.FormatUint(uint64(getHomeAzResp.HomeAzResponse.HomeAz), 10)
default:
metric.CustomDimensions[logger.HomeAZErrorCodeStr] = getHomeAzResp.Response.ReturnCode.String()
metric.CustomDimensions[logger.HomeAZErrorMsgStr] = getHomeAzResp.Response.Message

}
}
logger.SendMetric(metric)
}
}
}
3 changes: 2 additions & 1 deletion cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
nncctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/nodenetworkconfig"
podctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/pod"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/metric"
"github.com/Azure/azure-container-networking/cns/middlewares"
"github.com/Azure/azure-container-networking/cns/multitenantcontroller"
"github.com/Azure/azure-container-networking/cns/multitenantcontroller/multitenantoperator"
Expand Down Expand Up @@ -932,7 +933,7 @@ func main() {
}

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

Expand Down
Loading