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
48 changes: 48 additions & 0 deletions telemetry/aiwrapper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package telemetry

import (
"testing"

"github.com/Azure/azure-container-networking/aitelemetry"
"github.com/stretchr/testify/require"
)

func TestCreateAITelemetryHandle(t *testing.T) {
tests := []struct {
name string
aiConfig aitelemetry.AIConfig
disableAll bool
disableMetric bool
disableTrace bool
wantErr bool
}{
{
name: "disable telemetry",
aiConfig: aitelemetry.AIConfig{},
disableAll: false,
disableMetric: true,
disableTrace: true,
wantErr: true,
},
{
name: "empty aiconfig",
aiConfig: aitelemetry.AIConfig{},
disableAll: true,
disableMetric: true,
disableTrace: true,
wantErr: true,
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
err := CreateAITelemetryHandle(tt.aiConfig, tt.disableAll, tt.disableMetric, tt.disableTrace)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})
}
}
18 changes: 5 additions & 13 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package telemetry

import (
"encoding/json"
"fmt"

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

const (
Expand Down Expand Up @@ -122,30 +122,22 @@ func (reportMgr *ReportManager) SendReport(tb *TelemetryBuffer) error {

// ReportToBytes - returns the report bytes
func (reportMgr *ReportManager) ReportToBytes() ([]byte, error) {
var err error
var report []byte

switch reportMgr.Report.(type) {
case *CNIReport:
case *AIMetric:
default:
err = fmt.Errorf("[Telemetry] Invalid report type")
}

if err != nil {
return []byte{}, err
return []byte{}, errors.Errorf("Invalid report type: %T", reportMgr.Report)
}

report, err = json.Marshal(reportMgr.Report)
report, err := json.Marshal(reportMgr.Report)
return report, err
}

// This function for sending CNI metrics to telemetry service
func SendCNIMetric(cniMetric *AIMetric, tb *TelemetryBuffer) error {
var (
err error
report []byte
)
var err error
var report []byte

if tb != nil && tb.Connected {
reportMgr := &ReportManager{Report: cniMetric}
Expand Down
Loading