Skip to content

Commit 0451318

Browse files
committed
send telemetry for ipam config, epinfo, and error on cni add completion
1 parent 8046c63 commit 0451318

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

cni/network/network.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
431431
zap.String("pod", k8sPodName),
432432
zap.Any("IPs", cniResult.IPs),
433433
zap.Error(log.NewErrorWithoutStackTrace(err)))
434+
435+
telemetry.SendEvent(fmt.Sprintf("ADD command completed for ipamAddResult verbose: %s epInfos: %s error: %v ", ipamAddResult.PrettyString(), network.FormatStructPointers(epInfos), err))
434436
}()
435437

436438
ipamAddResult = IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
@@ -562,6 +564,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
562564

563565
infraSeen := false
564566
endpointIndex := 1
567+
565568
for key := range ipamAddResult.interfaceInfo {
566569
ifInfo := ipamAddResult.interfaceInfo[key]
567570
logger.Info("Processing interfaceInfo:", zap.Any("ifInfo", ifInfo))
@@ -631,8 +634,6 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
631634
if err != nil {
632635
return errors.Wrap(err, "failed to create endpoint") // behavior can change if you don't assign to err prior to returning
633636
}
634-
// telemetry added
635-
telemetry.SendEvent(fmt.Sprintf("CNI ADD Process succeeded for interfaces: %v", ipamAddResult.PrettyString()))
636637
return nil
637638
}
638639

cni/telemetry/client/telemetry_client.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ func NewTelemetryClient(report *telemetry.CNIReport) *TelemetryClient {
3030
func (c *TelemetryClient) ConnectTelemetry(logger *zap.Logger) {
3131
c.tb = telemetry.NewTelemetryBuffer(logger)
3232
c.tb.ConnectToTelemetry()
33+
c.logger = logger
3334
}
3435

3536
func (c *TelemetryClient) StartAndConnectTelemetry(logger *zap.Logger) {
3637
c.tb = telemetry.NewTelemetryBuffer(logger)
3738
c.tb.ConnectToTelemetryService(telemetryNumberRetries, telemetryWaitTimeInMilliseconds)
39+
c.logger = logger
3840
}
3941

4042
func (c *TelemetryClient) DisconnectTelemetry() {
@@ -43,8 +45,7 @@ func (c *TelemetryClient) DisconnectTelemetry() {
4345
}
4446
c.tb.Close()
4547
}
46-
47-
func (c *TelemetryClient) SendEvent(msg string) {
48+
func (c *TelemetryClient) sendTelemetry(msg string) {
4849
if c.tb == nil {
4950
return
5051
}
@@ -53,3 +54,13 @@ func (c *TelemetryClient) SendEvent(msg string) {
5354
c.CNIReportSettings.EventMessage = eventMsg
5455
telemetry.SendCNIEvent(c.tb, c.CNIReportSettings)
5556
}
57+
func (c *TelemetryClient) sendLog(msg string) {
58+
if c.logger == nil {
59+
return
60+
}
61+
c.logger.Info("Telemetry Event", zap.String("message", msg))
62+
}
63+
func (c *TelemetryClient) SendEvent(msg string) {
64+
c.sendLog(msg)
65+
c.sendTelemetry(msg)
66+
}

network/endpoint.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,30 @@ type apipaClient interface {
154154
CreateHostNCApipaEndpoint(ctx context.Context, networkContainerID string) (string, error)
155155
}
156156

157+
func FormatStructPointers[T any](slice []*T) string {
158+
var builder strings.Builder
159+
for _, ptr := range slice {
160+
if ptr != nil {
161+
fmt.Fprintf(&builder, "%+v \n", *ptr)
162+
}
163+
}
164+
return builder.String()
165+
}
166+
157167
func (epInfo *EndpointInfo) PrettyString() string {
158-
return fmt.Sprintf("Id:%s ContainerID:%s NetNsPath:%s IfName:%s IfIndex:%d MacAddr:%s IPAddrs:%v Gateways:%v Data:%+v NICType: %s NetworkContainerID: %s HostIfName: %s NetNs: %s Options: %v",
168+
return fmt.Sprintf("Id:%s ContainerID:%s NetNsPath:%s IfName:%s IfIndex:%d MacAddr:%s IPAddrs:%v Gateways:%v Data:%+v NICType: %s NetworkContainerID: %s HostIfName: %s NetNs: %s Options: %v MasterIfName: %s IfName: %s HNSEndpointID: %s HNSNetworkID: %s",
159169
epInfo.EndpointID, epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName, epInfo.IfIndex, epInfo.MacAddress.String(), epInfo.IPAddresses,
160-
epInfo.Gateways, epInfo.Data, epInfo.NICType, epInfo.NetworkContainerID, epInfo.HostIfName, epInfo.NetNs, epInfo.Options)
170+
epInfo.Gateways, epInfo.Data, epInfo.NICType, epInfo.NetworkContainerID, epInfo.HostIfName, epInfo.NetNs, epInfo.Options, epInfo.MasterIfName,
171+
epInfo.IfName, epInfo.HNSEndpointID, epInfo.HNSNetworkID)
161172
}
162173

163174
func (ifInfo *InterfaceInfo) PrettyString() string {
164-
return fmt.Sprintf("Name:%s NICType:%v MacAddr:%s IPConfigs:%+v Routes:%+v DNSInfo:%+v",
165-
ifInfo.Name, ifInfo.NICType, ifInfo.MacAddress.String(), ifInfo.IPConfigs, ifInfo.Routes, ifInfo.DNS)
175+
var ncresponse string
176+
if ifInfo.NCResponse != nil {
177+
ncresponse = fmt.Sprintf("%+v", *ifInfo.NCResponse)
178+
}
179+
return fmt.Sprintf("Name:%s NICType:%v MacAddr:%s IPConfigs:%s Routes:%+v DNSInfo:%+v NCResponse: %s",
180+
ifInfo.Name, ifInfo.NICType, ifInfo.MacAddress.String(), FormatStructPointers(ifInfo.IPConfigs), ifInfo.Routes, ifInfo.DNS, ncresponse)
166181
}
167182

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

0 commit comments

Comments
 (0)