Skip to content

Commit ba3bbe0

Browse files
Remove azure-vnet-telemetry for windows multitenancy (#1430)
* Remove azure-vne-telemetry for windows multitenancy and telemetry service for windows multitenancy will be started from cns. * start telemetry service from cns * lint and log fix * minor change * addressed comment
1 parent fa487c4 commit ba3bbe0

File tree

14 files changed

+105
-82
lines changed

14 files changed

+105
-82
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ acncli-binary:
146146

147147
# Build the Azure CNS binary.
148148
azure-cns-binary:
149-
cd $(CNS_DIR) && CGO_ENABLED=0 go build -v -o $(CNS_BUILD_DIR)/azure-cns$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -X $(CNS_AI_PATH)=$(CNS_AI_ID)" -gcflags="-dwarflocationlists=true"
149+
cd $(CNS_DIR) && CGO_ENABLED=0 go build -v -o $(CNS_BUILD_DIR)/azure-cns$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -X $(CNS_AI_PATH)=$(CNS_AI_ID) -X $(CNI_AI_PATH)=$(CNI_AI_ID)" -gcflags="-dwarflocationlists=true"
150150

151151
# Build the Azure NPM binary.
152152
azure-npm-binary:
@@ -392,8 +392,11 @@ cni-archive: azure-vnet-binary azure-vnet-ipam-binary azure-vnet-ipamv6-binary a
392392

393393
$(MKDIR) $(CNI_MULTITENANCY_BUILD_DIR)
394394
cp cni/azure-$(GOOS)-multitenancy.conflist $(CNI_MULTITENANCY_BUILD_DIR)/10-azure.conflist
395+
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_MULTITENANCY_BUILD_DIR)
396+
ifeq ($(GOOS),linux)
395397
cp telemetry/azure-vnet-telemetry.config $(CNI_MULTITENANCY_BUILD_DIR)/azure-vnet-telemetry.config
396-
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) $(CNI_MULTITENANCY_BUILD_DIR)
398+
cp $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) $(CNI_MULTITENANCY_BUILD_DIR)
399+
endif
397400
cd $(CNI_MULTITENANCY_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_MULTITENANCY_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config
398401

399402
$(MKDIR) $(CNI_SWIFT_BUILD_DIR)

aitelemetry/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
type Report struct {
1212
Message string
1313
Context string
14+
AppVersion string
1415
CustomDimensions map[string]string
1516
}
1617

@@ -25,6 +26,7 @@ type Event struct {
2526
type Metric struct {
2627
Name string
2728
Value float64
29+
AppVersion string
2830
CustomDimensions map[string]string
2931
}
3032

aitelemetry/telemetrywrapper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ func (th *telemetryHandle) TrackLog(report Report) {
205205
// Initialize new trace message
206206
trace := appinsights.NewTraceTelemetry(report.Message, appinsights.Warning)
207207

208+
// will be empty if cns used as telemetry service for cni
209+
if th.appVersion == "" {
210+
th.appVersion = report.AppVersion
211+
}
212+
208213
// Override few of existing columns with metadata
209214
trace.Tags.User().SetAuthUserId(runtime.GOOS)
210215
trace.Tags.Operation().SetId(report.Context)
@@ -295,6 +300,10 @@ func (th *telemetryHandle) TrackMetric(metric Metric) {
295300
metadata := th.metadata
296301
th.rwmutex.RUnlock()
297302

303+
if th.appVersion == "" {
304+
th.appVersion = metric.AppVersion
305+
}
306+
298307
// Check if metadata is populated
299308
if metadata.SubscriptionID != "" {
300309
aimetric.Properties[locationStr] = metadata.Location

cni/network/network.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"fmt"
1010
"net"
11+
"os"
1112
"time"
1213

1314
"github.com/Azure/azure-container-networking/aitelemetry"
@@ -161,6 +162,19 @@ func (plugin *NetPlugin) Start(config *common.PluginConfig) error {
161162
return nil
162163
}
163164

165+
// This function for sending CNI metrics to telemetry service
166+
func logAndSendEvent(plugin *NetPlugin, msg string) {
167+
log.Printf(msg)
168+
sendEvent(plugin, msg)
169+
}
170+
171+
func sendEvent(plugin *NetPlugin, msg string) {
172+
eventMsg := fmt.Sprintf("[%d] %s", os.Getpid(), msg)
173+
plugin.report.Version = plugin.Version
174+
plugin.report.EventMessage = eventMsg
175+
telemetry.SendCNIEvent(plugin.tb, plugin.report)
176+
}
177+
164178
func (plugin *NetPlugin) GetAllEndpointState(networkid string) (*api.AzureCNIState, error) {
165179
st := api.AzureCNIState{
166180
ContainerInterfaces: make(map[string]api.PodNetworkInterfaceInfo),
@@ -321,7 +335,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
321335

322336
startTime := time.Now()
323337

324-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("[cni-net] Processing ADD command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}.",
338+
logAndSendEvent(plugin, fmt.Sprintf("[cni-net] Processing ADD command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}.",
325339
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData))
326340

327341
// Parse network configuration from stdin.
@@ -339,6 +353,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
339353
cniMetric.Metric = aitelemetry.Metric{
340354
Name: telemetry.CNIAddTimeMetricStr,
341355
Value: float64(operationTimeMs),
356+
AppVersion: plugin.Version,
342357
CustomDimensions: make(map[string]string),
343358
}
344359
SetCustomDimensions(&cniMetric, nwCfg, err)
@@ -501,7 +516,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
501516
}
502517
}
503518

504-
telemetry.SendCNIEvent(plugin.tb, fmt.Sprintf("Allocated IPAddress from ipam:%+v v6:%+v", ipamAddResult.ipv4Result, ipamAddResult.ipv6Result))
519+
sendEvent(plugin, fmt.Sprintf("Allocated IPAddress from ipam:%+v v6:%+v", ipamAddResult.ipv4Result, ipamAddResult.ipv6Result))
505520

506521
defer func() {
507522
if err != nil {
@@ -512,14 +527,14 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
512527
// Create network
513528
if nwInfoErr != nil {
514529
// Network does not exist.
515-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("[cni-net] Creating network %v.", networkID))
530+
logAndSendEvent(plugin, fmt.Sprintf("[cni-net] Creating network %v.", networkID))
516531
// opts map needs to get passed in here
517532
if nwInfo, err = plugin.createNetworkInternal(networkID, policies, ipamAddConfig, ipamAddResult); err != nil {
518533
log.Errorf("Create network failed: %w", err)
519534
return err
520535
}
521536

522-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("[cni-net] Created network %v with subnet %v.", networkID, ipamAddResult.hostSubnetPrefix.String()))
537+
logAndSendEvent(plugin, fmt.Sprintf("[cni-net] Created network %v with subnet %v.", networkID, ipamAddResult.hostSubnetPrefix.String()))
523538
}
524539

525540
natInfo := getNATInfo(nwCfg.ExecutionMode, options[network.SNATIPKey], nwCfg.MultiTenancy, enableSnatForDNS)
@@ -546,7 +561,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
546561
return err
547562
}
548563

549-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("CNI ADD succeeded : IP:%+v, VlanID: %v, podname %v, namespace %v numendpoints:%d",
564+
sendEvent(plugin, fmt.Sprintf("CNI ADD succeeded : IP:%+v, VlanID: %v, podname %v, namespace %v numendpoints:%d",
550565
ipamAddResult.ipv4Result.IPs, epInfo.Data[network.VlanIDKey], k8sPodName, k8sNamespace, plugin.nm.GetNumberOfEndpoints("", nwCfg.Name)))
551566

552567
return nil
@@ -749,7 +764,7 @@ func (plugin *NetPlugin) createEndpointInternal(opt *createEndpointInternalOpt)
749764
}
750765

751766
// Create the endpoint.
752-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("[cni-net] Creating endpoint %s.", epInfo.PrettyString()))
767+
logAndSendEvent(plugin, fmt.Sprintf("[cni-net] Creating endpoint %s.", epInfo.PrettyString()))
753768
err = plugin.nm.CreateEndpoint(cnsclient, opt.nwInfo.Id, &epInfo)
754769
if err != nil {
755770
err = plugin.Errorf("Failed to create endpoint: %v", err)
@@ -859,12 +874,11 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
859874
nwInfo network.NetworkInfo
860875
epInfo *network.EndpointInfo
861876
cniMetric telemetry.AIMetric
862-
msg string
863877
)
864878

865879
startTime := time.Now()
866880

867-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("[cni-net] Processing DEL command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v, StdinData:%s}.",
881+
logAndSendEvent(plugin, fmt.Sprintf("[cni-net] Processing DEL command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v, StdinData:%s}.",
868882
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData))
869883

870884
defer func() {
@@ -883,13 +897,16 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
883897
}
884898

885899
plugin.setCNIReportDetails(nwCfg, CNI_DEL, "")
900+
plugin.report.ContainerName = k8sPodName + ":" + k8sNamespace
901+
886902
iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
887903

888904
sendMetricFunc := func() {
889905
operationTimeMs := time.Since(startTime).Milliseconds()
890906
cniMetric.Metric = aitelemetry.Metric{
891907
Name: telemetry.CNIDelTimeMetricStr,
892908
Value: float64(operationTimeMs),
909+
AppVersion: plugin.Version,
893910
CustomDimensions: make(map[string]string),
894911
}
895912
SetCustomDimensions(&cniMetric, nwCfg, err)
@@ -957,7 +974,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
957974
// attempt to release address associated with this Endpoint id
958975
// This is to ensure clean up is done even in failure cases
959976
log.Printf("[cni-net] Failed to query endpoint %s: %v", endpointID, err)
960-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("Release ip by ContainerID (endpoint not found):%v", args.ContainerID))
977+
logAndSendEvent(plugin, fmt.Sprintf("Release ip by ContainerID (endpoint not found):%v", args.ContainerID))
961978
if err = plugin.ipamInvoker.Delete(nil, nwCfg, args, nwInfo.Options); err != nil {
962979
return plugin.RetriableError(fmt.Errorf("failed to release address(no endpoint): %w", err))
963980
}
@@ -970,7 +987,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
970987

971988
// schedule send metric before attempting delete
972989
defer sendMetricFunc()
973-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("Deleting endpoint:%v", endpointID))
990+
logAndSendEvent(plugin, fmt.Sprintf("Deleting endpoint:%v", endpointID))
974991
// Delete the endpoint.
975992
if err = plugin.nm.DeleteEndpoint(networkID, endpointID); err != nil {
976993
// return a retriable error so the container runtime will retry this DEL later
@@ -982,7 +999,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
982999
if !nwCfg.MultiTenancy {
9831000
// Call into IPAM plugin to release the endpoint's addresses.
9841001
for _, address := range epInfo.IPAddresses {
985-
telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("Release ip:%s", address.IP.String()))
1002+
logAndSendEvent(plugin, fmt.Sprintf("Release ip:%s", address.IP.String()))
9861003
err = plugin.ipamInvoker.Delete(&address, nwCfg, args, nwInfo.Options)
9871004
if err != nil {
9881005
return plugin.RetriableError(fmt.Errorf("failed to release address: %w", err))
@@ -997,8 +1014,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
9971014
}
9981015
}
9991016

1000-
plugin.setCNIReportDetails(nwCfg, CNI_DEL, msg)
1001-
telemetry.SendCNIEvent(plugin.tb, fmt.Sprintf("CNI DEL succeeded : Released ip %+v podname %v namespace %v", nwCfg.Ipam.Address, k8sPodName, k8sNamespace))
1017+
sendEvent(plugin, fmt.Sprintf("CNI DEL succeeded : Released ip %+v podname %v namespace %v", nwCfg.Ipam.Address, k8sPodName, k8sNamespace))
10021018

10031019
return err
10041020
}
@@ -1038,6 +1054,7 @@ func (plugin *NetPlugin) Update(args *cniSkel.CmdArgs) error {
10381054
cniMetric.Metric = aitelemetry.Metric{
10391055
Name: telemetry.CNIUpdateTimeMetricStr,
10401056
Value: float64(operationTimeMs),
1057+
AppVersion: plugin.Version,
10411058
CustomDimensions: make(map[string]string),
10421059
}
10431060
SetCustomDimensions(&cniMetric, nwCfg, err)

cni/network/plugin/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func rootExecute() error {
152152
SystemDetails: telemetry.SystemInfo{},
153153
InterfaceDetails: telemetry.InterfaceInfo{},
154154
BridgeDetails: telemetry.BridgeInfo{},
155+
Version: version,
155156
},
156157
}
157158

cni/telemetry/service/telemetrymain.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
// Entry point of the telemetry service if started by CNI
44

55
import (
6+
"context"
67
"fmt"
78
"os"
89
"runtime"
@@ -189,7 +190,7 @@ func main() {
189190
err = telemetry.CreateAITelemetryHandle(aiConfig, config.DisableAll, config.DisableTrace, config.DisableMetric)
190191
log.Printf("[Telemetry] AI Handle creation status:%v", err)
191192
log.Logf("[Telemetry] Report to host for an interval of %d seconds", config.ReportToHostIntervalInSeconds)
192-
tb.PushData()
193+
tb.PushData(context.Background())
193194
telemetry.CloseAITelemetryHandle()
194195

195196
log.Close()

cns/service/main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"github.com/Azure/azure-container-networking/processlock"
4747
localtls "github.com/Azure/azure-container-networking/server/tls"
4848
"github.com/Azure/azure-container-networking/store"
49+
"github.com/Azure/azure-container-networking/telemetry"
4950
"github.com/avast/retry-go/v3"
5051
"github.com/pkg/errors"
5152
"go.uber.org/zap"
@@ -266,6 +267,13 @@ var args = acn.ArgumentList{
266267
Type: "string",
267268
DefaultValue: "",
268269
},
270+
{
271+
Name: acn.OptTelemetryService,
272+
Shorthand: acn.OptTelemetryServiceAlias,
273+
Description: "Flag to start telemetry service to receive telemetry events from CNI. Default, disabled.",
274+
Type: "bool",
275+
DefaultValue: false,
276+
},
269277
}
270278

271279
// init() is executed before main() whenever this package is imported
@@ -367,6 +375,28 @@ func sendRegisterNodeRequest(httpc *http.Client, httpRestService cns.HTTPService
367375
return nil
368376
}
369377

378+
func startTelemetryService(ctx context.Context) {
379+
var config aitelemetry.AIConfig
380+
381+
err := telemetry.CreateAITelemetryHandle(config, false, false, false)
382+
if err != nil {
383+
log.Errorf("AI telemetry handle creation failed..:%w", err)
384+
return
385+
}
386+
387+
tbtemp := telemetry.NewTelemetryBuffer()
388+
//nolint:errcheck // best effort to cleanup leaked pipe/socket before start
389+
tbtemp.Cleanup(telemetry.FdName)
390+
391+
tb := telemetry.NewTelemetryBuffer()
392+
err = tb.StartServer()
393+
if err != nil {
394+
log.Errorf("Telemetry service failed to start: %w", err)
395+
return
396+
}
397+
tb.PushData(rootCtx)
398+
}
399+
370400
// Main is the entry point for CNS.
371401
func main() {
372402
// Initialize and parse command line arguments.
@@ -396,6 +426,7 @@ func main() {
396426
clientDebugCmd := acn.GetArg(acn.OptDebugCmd).(string)
397427
clientDebugArg := acn.GetArg(acn.OptDebugArg).(string)
398428
cmdLineConfigPath := acn.GetArg(acn.OptCNSConfigPath).(string)
429+
telemetryDaemonEnabled := acn.GetArg(acn.OptTelemetryService).(bool)
399430

400431
if vers {
401432
printVersion()
@@ -475,6 +506,10 @@ func main() {
475506
logger.InitAI(aiConfig, ts.DisableTrace, ts.DisableMetric, ts.DisableEvent)
476507
}
477508

509+
if telemetryDaemonEnabled {
510+
go startTelemetryService(rootCtx)
511+
}
512+
478513
// Log platform information.
479514
logger.Printf("Running on %v", platform.GetOSInfo())
480515

common/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ const (
8787
OptTelemetry = "telemetry"
8888
OptTelemetryAlias = "dt"
8989

90+
// Enable Telemetry service
91+
OptTelemetryService = "telemetry-service"
92+
OptTelemetryServiceAlias = "ts"
93+
9094
// HTTP connection timeout
9195
OptHttpConnectionTimeout = "http-connection-timeout"
9296
OptHttpConnectionTimeoutAlias = "httpcontimeout"

network/endpoint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ type apipaClient interface {
101101
}
102102

103103
func (epInfo *EndpointInfo) PrettyString() string {
104-
return fmt.Sprintf("Id:%s ContainerID:%s NetNsPath:%s IfName:%s IfIndex:%d MacAddr:%s IPAddrs:%v Gateways:%v",
104+
return fmt.Sprintf("Id:%s ContainerID:%s NetNsPath:%s IfName:%s IfIndex:%d MacAddr:%s IPAddrs:%v Gateways:%v Data:%+v",
105105
epInfo.Id, epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName, epInfo.IfIndex, epInfo.MacAddress.String(), epInfo.IPAddresses,
106-
epInfo.Gateways)
106+
epInfo.Gateways, epInfo.Data)
107107
}
108108

109109
// NewEndpoint creates a new endpoint in the network.

network/endpoint_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (nw *network) newEndpointImplHnsV2(cli apipaClient, epInfo *EndpointInfo) (
318318
}
319319

320320
// Create the HCN endpoint.
321-
log.Printf("[net] Creating hcn endpoint: %+v", hcnEndpoint)
321+
log.Printf("[net] Creating hcn endpoint: %s computenetwork:%s", hcnEndpoint.Name, hcnEndpoint.HostComputeNetwork)
322322
hnsResponse, err := Hnsv2.CreateEndpoint(hcnEndpoint)
323323
if err != nil {
324324
return nil, fmt.Errorf("Failed to create endpoint: %s due to error: %v", hcnEndpoint.Name, err)

0 commit comments

Comments
 (0)