Skip to content

Commit 7546aac

Browse files
jpayne3506jpayne3506tamilmani1989
authored
fix: [Telemetry] Prevent telemetry connect if no binary path (#1883)
* Prevent telemetry connect if no binary path * agnostic calls, addressing comments * agnostic calls, addressing comments * Correcting flow, lint * Restoring aiwrapper * lint error 113 cleanup * addressing comments * cleaning up telemetry folder error calls * addressing comments * addressing comments * addressing comments --------- Co-authored-by: jpayne3506 <[email protected]> Co-authored-by: tamilmani1989 <[email protected]>
1 parent ab8858b commit 7546aac

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

telemetry/aiwrapper.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
package telemetry
33

44
import (
5-
"fmt"
5+
"errors"
6+
67
"github.com/Azure/azure-container-networking/aitelemetry"
78
"github.com/Azure/azure-container-networking/log"
89
)
910

1011
var (
11-
aiMetadata string
12-
th aitelemetry.TelemetryHandle
13-
gDisableTrace bool
14-
gDisableMetric bool
12+
aiMetadata string
13+
th aitelemetry.TelemetryHandle
14+
gDisableTrace bool
15+
gDisableMetric bool
16+
ErrTelemetryDisabled = errors.New("telemetry is disabled")
1517
)
1618

1719
const (
@@ -24,7 +26,7 @@ func CreateAITelemetryHandle(aiConfig aitelemetry.AIConfig, disableAll, disableM
2426

2527
if disableAll {
2628
log.Printf("Telemetry is disabled")
27-
return fmt.Errorf("Telmetry disabled")
29+
return ErrTelemetryDisabled
2830
}
2931

3032
th, err = aitelemetry.NewAITelemetry("", aiMetadata, aiConfig)

telemetry/telemetry_linux.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
package telemetry
55

66
import (
7-
"fmt"
87
"os/exec"
98
"runtime"
109
"strings"
1110
"syscall"
1211

1312
"github.com/Azure/azure-container-networking/platform"
13+
"github.com/pkg/errors"
1414
)
1515

1616
// Memory Info structure.
@@ -36,7 +36,7 @@ func getMemInfo() (*MemInfo, error) {
3636

3737
err := syscall.Sysinfo(info)
3838
if err != nil {
39-
return nil, fmt.Errorf("Sysinfo failed due to %v", err)
39+
return nil, errors.Wrapf(err, "Sysinfo failed due to ")
4040
}
4141

4242
unit := uint64(info.Unit) * MB // MB
@@ -51,7 +51,7 @@ func getDiskInfo(path string) (*DiskInfo, error) {
5151

5252
err := syscall.Statfs(path, &fs)
5353
if err != nil {
54-
return nil, fmt.Errorf("Statfs call failed with error %v", err)
54+
return nil, errors.Wrapf(err, "Statfs call failed with error ")
5555
}
5656

5757
total := fs.Blocks * uint64(fs.Bsize) / MB

telemetry/telemetrybuffer.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"bufio"
88
"context"
99
"encoding/json"
10-
"fmt"
1110
"net"
1211
"os"
1312
"path/filepath"
@@ -305,9 +304,14 @@ func ReadConfigFile(filePath string) (TelemetryConfig, error) {
305304
func (tb *TelemetryBuffer) ConnectToTelemetryService(telemetryNumRetries, telemetryWaitTimeInMilliseconds int) {
306305
path, dir := getTelemetryServiceDirectory()
307306
args := []string{"-d", dir}
307+
308308
for attempt := 0; attempt < 2; attempt++ {
309309
if err := tb.Connect(); err != nil {
310310
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+
}
311315
tb.Cleanup(FdName)
312316
StartTelemetryService(path, args)
313317
WaitForTelemetrySocket(telemetryNumRetries, time.Duration(telemetryWaitTimeInMilliseconds))
@@ -319,20 +323,17 @@ func (tb *TelemetryBuffer) ConnectToTelemetryService(telemetryNumRetries, teleme
319323
}
320324
}
321325

326+
// getTelemetryServiceDirectory - check CNI install directory and Executable location for telemetry binary
322327
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 {
325331
ex, _ := os.Executable()
326332
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)
332334
dir = exDir
333335
} else {
334336
dir = CniInstallDir
335337
}
336-
337338
return
338339
}

0 commit comments

Comments
 (0)