Skip to content

Commit

Permalink
add azr metrics in heartbeats (#2735)
Browse files Browse the repository at this point in the history
* add azr metrics in heartbeats

* fix bug

* address comment

* address comment

* move heartbeat.go under metric folder

* emit error infos for getHomeAZ failures

* ignore exhuastive check

---------

Co-authored-by: Saksham Mittal <111590532+smittal22@users.noreply.github.com>
  • Loading branch information
ZetaoZhuang and smittal22 authored Jun 5, 2024
1 parent ef69d47 commit 7b5b879
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 deletions.
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

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

0 comments on commit 7b5b879

Please sign in to comment.