From bfc70dc80352bae492dd0219a181b8760180472a Mon Sep 17 00:00:00 2001 From: Tamilmani Manoharan Date: Wed, 3 Jan 2018 19:43:22 -0800 Subject: [PATCH 1/2] VSTS#1748724 Made minor changes for windows telemetry to work --- telemetry/telemetry.go | 6 ++++++ telemetry/telemetry_linux.go | 14 +++++--------- telemetry/telemetry_windows.go | 9 ++++----- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index 97f5805a8e..b157df86e7 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -18,6 +18,7 @@ import ( "strings" "github.com/Azure/azure-container-networking/common" + "github.com/Azure/azure-container-networking/platform" ) // OS Details structure. @@ -90,6 +91,11 @@ type ReportManager struct { Report *Report } +const ( + // TelemetryFile Path. + TelemetryFile = platform.RuntimePath + "AzureCNITelemetry.json" +) + // Read file line by line and return array of lines. func ReadFileByLines(filename string) ([]string, error) { var ( diff --git a/telemetry/telemetry_linux.go b/telemetry/telemetry_linux.go index ce910de72e..73a89321b4 100644 --- a/telemetry/telemetry_linux.go +++ b/telemetry/telemetry_linux.go @@ -24,9 +24,8 @@ type DiskInfo struct { } const ( - TelemetryFile = "/var/run/AzureCNITelemetry.json" - MB = 1048576 - KB = 1024 + MB = 104857 + KB = 1024 ) // This function retrieves VMs memory usage. @@ -89,12 +88,9 @@ func (report *Report) GetSystemDetails() { // This function creates a report with os details(ostype, version). func (report *Report) GetOSDetails() { - - osType := "Linux" - linesArr, err := ReadFileByLines("/etc/issue") if err != nil || len(linesArr) <= 0 { - report.OSDetails = &OSInfo{OSType: "Linux"} + report.OSDetails = &OSInfo{OSType: runtime.GOOS} report.OSDetails.ErrorMessage = "reading /etc/issue failed with" + err.Error() return } @@ -103,7 +99,7 @@ func (report *Report) GetOSDetails() { out, err := exec.Command("uname", "-r").Output() if err != nil { - report.OSDetails = &OSInfo{OSType: "Linux"} + report.OSDetails = &OSInfo{OSType: runtime.GOOS} report.OSDetails.ErrorMessage = "uname -r failed with " + err.Error() return } @@ -112,7 +108,7 @@ func (report *Report) GetOSDetails() { kernelVersion = strings.TrimSuffix(kernelVersion, "\n") report.OSDetails = &OSInfo{ - OSType: osType, + OSType: runtime.GOOS, OSVersion: osInfoArr[1], KernelVersion: kernelVersion, OSDistribution: osInfoArr[0], diff --git a/telemetry/telemetry_windows.go b/telemetry/telemetry_windows.go index 0042d01b56..8a8665f2a5 100644 --- a/telemetry/telemetry_windows.go +++ b/telemetry/telemetry_windows.go @@ -3,6 +3,8 @@ package telemetry +import "runtime" + type MemInfo struct { MemTotal uint64 MemFree uint64 @@ -13,10 +15,6 @@ type DiskInfo struct { DiskFree uint64 } -const ( - TelemetryFile = "c:\\AzureCNITelemetry" -) - func getMemInfo() (*MemInfo, error) { return nil, nil @@ -29,8 +27,9 @@ func getDiskInfo(path string) (*DiskInfo, error) { func (report *Report) GetSystemDetails() { + report.SystemDetails = &SystemInfo{} } func (report *Report) GetOSDetails() { - + report.OSDetails = &OSInfo{OSType: runtime.GOOS} } From b7c6e377c19428a73371667fd299f6f78b1739ba Mon Sep 17 00:00:00 2001 From: Tamilmani Manoharan Date: Thu, 4 Jan 2018 12:11:43 -0800 Subject: [PATCH 2/2] Spellchecked Orchestrator and corrected MB value --- telemetry/telemetry.go | 8 ++++---- telemetry/telemetry_linux.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index b157df86e7..3b176ab898 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -61,7 +61,7 @@ type BridgeInfo struct { } // Orchestrator Details structure. -type OrchsestratorInfo struct { +type OrchestratorInfo struct { OrchestratorName string OrchestratorVersion string ErrorMessage string @@ -76,7 +76,7 @@ type Report struct { Context string SubContext string VnetAddressSpace []string - OrchestratorDetails *OrchsestratorInfo + OrchestratorDetails *OrchestratorInfo OSDetails *OSInfo SystemDetails *SystemInfo InterfaceDetails *InterfaceInfo @@ -301,14 +301,14 @@ func (report *Report) GetInterfaceDetails(queryUrl string) { func (report *Report) GetOrchestratorDetails() { out, err := exec.Command("kubectl", "--version").Output() if err != nil { - report.OrchestratorDetails = &OrchsestratorInfo{} + report.OrchestratorDetails = &OrchestratorInfo{} report.OrchestratorDetails.ErrorMessage = "kubectl command failed due to " + err.Error() return } outStr := string(out) outStr = strings.TrimLeft(outStr, " ") - report.OrchestratorDetails = &OrchsestratorInfo{} + report.OrchestratorDetails = &OrchestratorInfo{} resultArray := strings.Split(outStr, " ") if len(resultArray) >= 2 { diff --git a/telemetry/telemetry_linux.go b/telemetry/telemetry_linux.go index 73a89321b4..09d2bd840d 100644 --- a/telemetry/telemetry_linux.go +++ b/telemetry/telemetry_linux.go @@ -24,7 +24,7 @@ type DiskInfo struct { } const ( - MB = 104857 + MB = 1048576 KB = 1024 ) @@ -108,7 +108,7 @@ func (report *Report) GetOSDetails() { kernelVersion = strings.TrimSuffix(kernelVersion, "\n") report.OSDetails = &OSInfo{ - OSType: runtime.GOOS, + OSType: runtime.GOOS, OSVersion: osInfoArr[1], KernelVersion: kernelVersion, OSDistribution: osInfoArr[0],