@@ -8,15 +8,13 @@ import (
8
8
"os"
9
9
"time"
10
10
11
- "github.com/Azure/azure-container-networking/aitelemetry"
12
11
"github.com/Azure/azure-container-networking/cni"
13
12
"github.com/Azure/azure-container-networking/cni/api"
14
13
zaplog "github.com/Azure/azure-container-networking/cni/log"
15
14
"github.com/Azure/azure-container-networking/cni/network"
16
15
"github.com/Azure/azure-container-networking/common"
17
16
"github.com/Azure/azure-container-networking/nns"
18
17
"github.com/Azure/azure-container-networking/platform"
19
- "github.com/Azure/azure-container-networking/store"
20
18
"github.com/Azure/azure-container-networking/telemetry"
21
19
"github.com/pkg/errors"
22
20
"go.uber.org/zap"
@@ -93,30 +91,19 @@ func rootExecute() error {
93
91
cniReport .VMUptime = upTime .Format ("2006-01-02 15:04:05" )
94
92
}
95
93
96
- // Start telemetry process if not already started. This should be done inside lock, otherwise multiple process
97
- // end up creating/killing telemetry process results in undesired state.
98
- telemetry .AIClient .StartAndConnectTelemetry (logger )
99
- defer telemetry .AIClient .DisconnectTelemetry ()
100
- telemetry .AIClient .SetSettings (cniReport )
101
-
102
- // CNI Acquires lock
94
+ // CNI attempts to acquire lock
103
95
if err = netPlugin .Plugin .InitializeKeyValueStore (& config ); err != nil {
96
+ // Error acquiring lock
104
97
network .PrintCNIError (fmt .Sprintf ("Failed to initialize key-value store of network plugin: %v" , err ))
105
98
106
- if ! telemetry .AIClient .IsConnected () {
107
- logger .Error ("Not connected to telemetry service, skipping sending error to application insights" )
108
- return errors .Wrap (err , "lock acquire error" )
109
- }
110
- telemetry .AIClient .SendError (err )
99
+ // Connect to telemetry service if it is running, otherwise skips telemetry
100
+ telemetry .AIClient .ConnectTelemetry (logger )
101
+ defer telemetry .AIClient .DisconnectTelemetry ()
111
102
112
- if errors .Is (err , store .ErrTimeoutLockingStore ) {
113
- var cniMetric telemetry.AIMetric
114
- cniMetric .Metric = aitelemetry.Metric {
115
- Name : telemetry .CNILockTimeoutStr ,
116
- Value : 1.0 ,
117
- CustomDimensions : make (map [string ]string ),
118
- }
119
- telemetry .AIClient .SendMetric (& cniMetric )
103
+ if telemetry .AIClient .IsConnected () {
104
+ telemetry .AIClient .SendError (err )
105
+ } else {
106
+ logger .Error ("Not connected to telemetry service, skipping sending error to application insights" )
120
107
}
121
108
return errors .Wrap (err , "lock acquire error" )
122
109
}
@@ -130,6 +117,12 @@ func rootExecute() error {
130
117
os .Exit (1 )
131
118
}
132
119
}()
120
+ // At this point, lock is acquired
121
+ // Start telemetry process if not already started. This should be done inside lock, otherwise multiple process
122
+ // end up creating/killing telemetry process results in undesired state.
123
+ telemetry .AIClient .StartAndConnectTelemetry (logger )
124
+ defer telemetry .AIClient .DisconnectTelemetry ()
125
+ telemetry .AIClient .SetSettings (cniReport )
133
126
134
127
t := time .Now ()
135
128
cniReport .Timestamp = t .Format ("2006-01-02 15:04:05" )
0 commit comments