@@ -6,7 +6,6 @@ package main
66import (
77 "fmt"
88 "os"
9- "reflect"
109 "time"
1110
1211 "github.com/Azure/azure-container-networking/aitelemetry"
@@ -25,7 +24,6 @@ import (
2524)
2625
2726const (
28- hostNetAgentURL = "http://168.63.129.16/machine/plugins?comp=netagent&type=cnireport"
2927 ipamQueryURL = "http://168.63.129.16/machine/plugins?comp=nmagent&type=getinterfaceinfov1"
3028 pluginName = "CNI"
3129 telemetryNumRetries = 5
@@ -54,27 +52,14 @@ func printVersion() {
5452 fmt .Printf ("Azure CNI Version %v\n " , version )
5553}
5654
57- // send error report to hostnetagent if CNI encounters any error.
58- func reportPluginError (reportManager * telemetry.ReportManager , tb * telemetry.TelemetryBuffer , err error ) {
59- logger .Error ("Report plugin error" )
60- reflect .ValueOf (reportManager .Report ).Elem ().FieldByName ("ErrorMessage" ).SetString (err .Error ())
61-
62- if err := reportManager .SendReport (tb ); err != nil {
63- logger .Error ("SendReport failed" , zap .Error (err ))
64- }
65- }
66-
6755func rootExecute () error {
6856 var (
6957 config common.PluginConfig
70- tb * telemetry.TelemetryBuffer
7158 )
7259
7360 config .Version = version
7461
7562 reportManager := & telemetry.ReportManager {
76- HostNetAgentURL : hostNetAgentURL ,
77- ContentType : telemetry .ContentType ,
7863 Report : & telemetry.CNIReport {
7964 Context : "AzureCNI" ,
8065 SystemDetails : telemetry.SystemInfo {},
@@ -111,17 +96,21 @@ func rootExecute() error {
11196 cniReport .VMUptime = upTime .Format ("2006-01-02 15:04:05" )
11297 }
11398
99+ // Start telemetry process if not already started. This should be done inside lock, otherwise multiple process
100+ // end up creating/killing telemetry process results in undesired state.
101+ telemetryclient .Telemetry .StartAndConnectTelemetry (logger )
102+ defer telemetryclient .Telemetry .DisconnectTelemetry ()
103+ telemetryclient .Telemetry .SetSettings (cniReport )
104+
114105 // CNI Acquires lock
115106 if err = netPlugin .Plugin .InitializeKeyValueStore (& config ); err != nil {
116107 network .PrintCNIError (fmt .Sprintf ("Failed to initialize key-value store of network plugin: %v" , err ))
117108
118- tb = telemetry .NewTelemetryBuffer (logger )
119- if tberr := tb .Connect (); tberr != nil {
120- logger .Error ("Cannot connect to telemetry service" , zap .Error (tberr ))
109+ if telemetryclient .Telemetry .IsConnected () {
110+ logger .Error ("Not connected to telemetry service" )
121111 return errors .Wrap (err , "lock acquire error" )
122112 }
123-
124- reportPluginError (reportManager , tb , err )
113+ telemetryclient .Telemetry .SendError (err )
125114
126115 if errors .Is (err , store .ErrTimeoutLockingStore ) {
127116 var cniMetric telemetry.AIMetric
@@ -130,13 +119,8 @@ func rootExecute() error {
130119 Value : 1.0 ,
131120 CustomDimensions : make (map [string ]string ),
132121 }
133- sendErr := telemetry .SendCNIMetric (& cniMetric , tb )
134- if sendErr != nil {
135- logger .Error ("Couldn't send cnilocktimeout metric" , zap .Error (sendErr ))
136- }
122+ telemetryclient .Telemetry .SendMetric (& cniMetric )
137123 }
138-
139- tb .Close ()
140124 return errors .Wrap (err , "lock acquire error" )
141125 }
142126
@@ -150,19 +134,12 @@ func rootExecute() error {
150134 }
151135 }()
152136
153- // Start telemetry process if not already started. This should be done inside lock, otherwise multiple process
154- // end up creating/killing telemetry process results in undesired state.
155- telemetryclient .Telemetry .StartAndConnectTelemetry (logger )
156- defer telemetryclient .Telemetry .DisconnectTelemetry ()
157-
158- telemetryclient .Telemetry .CNIReportSettings = cniReport
159-
160137 t := time .Now ()
161138 cniReport .Timestamp = t .Format ("2006-01-02 15:04:05" )
162139
163140 if err = netPlugin .Start (& config ); err != nil {
164141 network .PrintCNIError (fmt .Sprintf ("Failed to start network plugin, err:%v.\n " , err ))
165- reportPluginError ( reportManager , tb , err )
142+ telemetryclient . Telemetry . SendError ( err )
166143 panic ("network plugin start fatal error" )
167144 }
168145
@@ -199,7 +176,7 @@ func rootExecute() error {
199176 netPlugin .Stop ()
200177
201178 if err != nil {
202- reportPluginError ( reportManager , tb , err )
179+ telemetryclient . Telemetry . SendError ( err )
203180 }
204181
205182 return errors .Wrap (err , "Execute netplugin failure" )
0 commit comments