7
7
"bufio"
8
8
"context"
9
9
"encoding/json"
10
- "fmt"
11
10
"net"
12
11
"os"
13
12
"path/filepath"
@@ -305,9 +304,14 @@ func ReadConfigFile(filePath string) (TelemetryConfig, error) {
305
304
func (tb * TelemetryBuffer ) ConnectToTelemetryService (telemetryNumRetries , telemetryWaitTimeInMilliseconds int ) {
306
305
path , dir := getTelemetryServiceDirectory ()
307
306
args := []string {"-d" , dir }
307
+
308
308
for attempt := 0 ; attempt < 2 ; attempt ++ {
309
309
if err := tb .Connect (); err != nil {
310
310
log .Logf ("Connection to telemetry socket failed: %v" , err )
311
+ if _ , exists := os .Stat (path ); exists != nil {
312
+ log .Logf ("Skip starting telemetry service as file didn't exist" )
313
+ return
314
+ }
311
315
tb .Cleanup (FdName )
312
316
StartTelemetryService (path , args )
313
317
WaitForTelemetrySocket (telemetryNumRetries , time .Duration (telemetryWaitTimeInMilliseconds ))
@@ -319,20 +323,17 @@ func (tb *TelemetryBuffer) ConnectToTelemetryService(telemetryNumRetries, teleme
319
323
}
320
324
}
321
325
326
+ // getTelemetryServiceDirectory - check CNI install directory and Executable location for telemetry binary
322
327
func getTelemetryServiceDirectory () (path string , dir string ) {
323
- path = fmt .Sprintf ("%v/%v" , CniInstallDir , TelemetryServiceProcessName )
324
- if exists , _ := platform .CheckIfFileExists (path ); ! exists {
328
+ path = filepath .Join (CniInstallDir , TelemetryServiceProcessName )
329
+
330
+ if _ , exists := os .Stat (path ); exists != nil {
325
331
ex , _ := os .Executable ()
326
332
exDir := filepath .Dir (ex )
327
- path = fmt .Sprintf ("%v/%v" , exDir , TelemetryServiceProcessName )
328
- if exists , _ = platform .CheckIfFileExists (path ); ! exists {
329
- log .Logf ("Skip starting telemetry service as file didn't exist" )
330
- return
331
- }
333
+ path = filepath .Join (exDir , TelemetryServiceProcessName )
332
334
dir = exDir
333
335
} else {
334
336
dir = CniInstallDir
335
337
}
336
-
337
338
return
338
339
}
0 commit comments