Skip to content

Commit 0d6bc61

Browse files
committed
re-implement add and delete timing metrics
1 parent 067c82d commit 0d6bc61

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

cni/network/network.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
358358
epInfos []*network.EndpointInfo
359359
)
360360

361+
startTime := time.Now()
361362
logger.Info("Processing ADD command",
362363
zap.String("containerId", args.ContainerID),
363364
zap.String("netNS", args.Netns),
@@ -438,6 +439,9 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
438439
zap.Error(log.NewErrorWithoutStackTrace(err)))
439440

440441
telemetryClient.SendEvent(fmt.Sprintf("ADD command completed with [ipamAddResult]: %s [epInfos]: %s [error]: %v ", ipamAddResult.PrettyString(), network.FormatSliceOfPointersToString(epInfos), err))
442+
443+
operationTimeMs := time.Since(startTime).Milliseconds()
444+
telemetryClient.SendMetric(telemetry.CNIAddTimeMetricStr, float64(operationTimeMs), make(map[string]string))
441445
}()
442446

443447
ipamAddResult = IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
@@ -960,7 +964,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
960964
networkID string
961965
nwInfo network.EndpointInfo
962966
)
963-
967+
startTime := time.Now()
964968
logger.Info("Processing DEL command",
965969
zap.String("containerId", args.ContainerID),
966970
zap.String("netNS", args.Netns),
@@ -974,6 +978,8 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
974978
zap.String("pod", k8sPodName),
975979
zap.Error(log.NewErrorWithoutStackTrace(err)))
976980
telemetryClient.SendEvent(fmt.Sprintf("DEL command completed: [podname]: %s [namespace]: %s [error]: %v", k8sPodName, k8sNamespace, err))
981+
operationTimeMs := time.Since(startTime).Milliseconds()
982+
telemetryClient.SendMetric(telemetry.CNIDelTimeMetricStr, float64(operationTimeMs), make(map[string]string))
977983
}()
978984

979985
// Parse network configuration from stdin.

telemetry/telemetry_client.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"sync"
77

8+
"github.com/Azure/azure-container-networking/aitelemetry"
89
"go.uber.org/zap"
910
)
1011

@@ -94,11 +95,18 @@ func (c *Client) SendError(err error) {
9495
c.sendEvent(err.Error())
9596
}
9697

97-
func (c *Client) SendMetric(cniMetric *AIMetric) {
98-
if c.tb == nil || cniMetric == nil {
98+
func (c *Client) SendMetric(name string, value float64, customDims map[string]string) {
99+
if c.tb == nil {
99100
return
100101
}
101-
err := SendCNIMetric(cniMetric, c.tb)
102+
err := SendCNIMetric(&AIMetric{
103+
aitelemetry.Metric{
104+
Name: name,
105+
Value: value,
106+
AppVersion: c.Settings().Version,
107+
CustomDimensions: customDims,
108+
},
109+
}, c.tb)
102110
if err != nil {
103111
c.sendLog("Couldn't send metric: " + err.Error())
104112
}

telemetry/telemetry_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestClient(t *testing.T) {
5050
require.Equal(t, "", emptyClient.Settings().ErrorMessage)
5151

5252
// test sending aimetrics doesn't panic...
53-
require.NotPanics(t, func() { emptyClient.SendMetric(&AIMetric{}) })
53+
require.NotPanics(t, func() { emptyClient.SendMetric("", 0, nil) })
5454
// ...and doesn't affect the cni report
5555
require.Regexp(t, allowedEventMsg, emptyClient.Settings().EventMessage)
5656
require.Equal(t, "", emptyClient.Settings().ErrorMessage)

0 commit comments

Comments
 (0)