Skip to content

Commit 7b5b879

Browse files
add azr metrics in heartbeats (#2735)
* 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 <[email protected]>
1 parent ef69d47 commit 7b5b879

File tree

4 files changed

+57
-31
lines changed

4 files changed

+57
-31
lines changed

cns/logger/constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const (
88
// Dimensions
99
OrchestratorTypeStr = "OrchestratorType"
1010
NodeIDStr = "NodeID"
11+
HomeAZStr = "HomeAZ"
12+
IsAZRSupportedStr = "IsAZRSupported"
13+
HomeAZErrorCodeStr = "HomeAZErrorCode"
14+
HomeAZErrorMsgStr = "HomeAZErrorMsg"
15+
1116
// CNS Snspshot properties
1217
CnsNCSnapshotEventStr = "CNSNCSnapshot"
1318
IpConfigurationStr = "IPConfiguration"

cns/logger/heartbeat.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

cns/metric/heartbeat.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2018 Microsoft. All rights reserved.
2+
// MIT License
3+
4+
package metric
5+
6+
import (
7+
"context"
8+
"strconv"
9+
"time"
10+
11+
"github.com/Azure/azure-container-networking/aitelemetry"
12+
"github.com/Azure/azure-container-networking/cns"
13+
"github.com/Azure/azure-container-networking/cns/logger"
14+
"github.com/Azure/azure-container-networking/cns/restserver"
15+
"github.com/Azure/azure-container-networking/cns/types"
16+
)
17+
18+
// SendHeartBeat emits node metrics periodically
19+
func SendHeartBeat(ctx context.Context, heartbeatInterval time.Duration, homeAzMonitor *restserver.HomeAzMonitor, channelMode string) {
20+
ticker := time.NewTicker(heartbeatInterval)
21+
defer ticker.Stop()
22+
for {
23+
select {
24+
case <-ctx.Done():
25+
return
26+
case <-ticker.C:
27+
metric := aitelemetry.Metric{
28+
Name: logger.HeartBeatMetricStr,
29+
// This signifies 1 heartbeat is sent. Sum of this metric will give us number of heartbeats received
30+
Value: 1.0,
31+
CustomDimensions: make(map[string]string),
32+
}
33+
34+
// add azr metrics when channel mode is direct
35+
if channelMode == cns.Direct {
36+
getHomeAzResp := homeAzMonitor.GetHomeAz(ctx)
37+
switch getHomeAzResp.Response.ReturnCode { //nolint:exhaustive // ignore exhaustive types check
38+
case types.Success:
39+
metric.CustomDimensions[logger.IsAZRSupportedStr] = strconv.FormatBool(getHomeAzResp.HomeAzResponse.IsSupported)
40+
metric.CustomDimensions[logger.HomeAZStr] = strconv.FormatUint(uint64(getHomeAzResp.HomeAzResponse.HomeAz), 10)
41+
default:
42+
metric.CustomDimensions[logger.HomeAZErrorCodeStr] = getHomeAzResp.Response.ReturnCode.String()
43+
metric.CustomDimensions[logger.HomeAZErrorMsgStr] = getHomeAzResp.Response.Message
44+
45+
}
46+
}
47+
logger.SendMetric(metric)
48+
}
49+
}
50+
}

cns/service/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
nncctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/nodenetworkconfig"
4040
podctrl "github.com/Azure/azure-container-networking/cns/kubecontroller/pod"
4141
"github.com/Azure/azure-container-networking/cns/logger"
42+
"github.com/Azure/azure-container-networking/cns/metric"
4243
"github.com/Azure/azure-container-networking/cns/middlewares"
4344
"github.com/Azure/azure-container-networking/cns/multitenantcontroller"
4445
"github.com/Azure/azure-container-networking/cns/multitenantcontroller/multitenantoperator"
@@ -932,7 +933,7 @@ func main() {
932933
}
933934

934935
if !disableTelemetry {
935-
go logger.SendHeartBeat(rootCtx, cnsconfig.TelemetrySettings.HeartBeatIntervalInMins)
936+
go metric.SendHeartBeat(rootCtx, time.Minute*time.Duration(cnsconfig.TelemetrySettings.HeartBeatIntervalInMins), homeAzMonitor, cnsconfig.ChannelMode)
936937
go httpRemoteRestService.SendNCSnapShotPeriodically(rootCtx, cnsconfig.TelemetrySettings.SnapshotIntervalInMins)
937938
}
938939

0 commit comments

Comments
 (0)