-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <111590532+smittal22@users.noreply.github.com>
- Loading branch information
1 parent
ef69d47
commit 7b5b879
Showing
4 changed files
with
57 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters