Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"

"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/platform"
)

// OS Details structure.
Expand Down Expand Up @@ -60,7 +61,7 @@ type BridgeInfo struct {
}

// Orchestrator Details structure.
type OrchsestratorInfo struct {
type OrchestratorInfo struct {
OrchestratorName string
OrchestratorVersion string
ErrorMessage string
Expand All @@ -75,7 +76,7 @@ type Report struct {
Context string
SubContext string
VnetAddressSpace []string
OrchestratorDetails *OrchsestratorInfo
OrchestratorDetails *OrchestratorInfo
OSDetails *OSInfo
SystemDetails *SystemInfo
InterfaceDetails *InterfaceInfo
Expand All @@ -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 (
Expand Down Expand Up @@ -295,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 {
Expand Down
14 changes: 5 additions & 9 deletions telemetry/telemetry_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ type DiskInfo struct {
}

const (
TelemetryFile = "/var/run/AzureCNITelemetry.json"
MB = 1048576
KB = 1024
MB = 1048576
KB = 1024
)

// This function retrieves VMs memory usage.
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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],
Expand Down
9 changes: 4 additions & 5 deletions telemetry/telemetry_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package telemetry

import "runtime"

type MemInfo struct {
MemTotal uint64
MemFree uint64
Expand All @@ -13,10 +15,6 @@ type DiskInfo struct {
DiskFree uint64
}

const (
TelemetryFile = "c:\\AzureCNITelemetry"
)

func getMemInfo() (*MemInfo, error) {

return nil, nil
Expand All @@ -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}
}