Skip to content

Commit 45914be

Browse files
authored
Adding telemetry report functions for DNC. (#216)
* Adding telemetry report functions for DNC. * Addressing Yongli's suggestions. * commit to switch branches * Adding some changes to npm due to telemetry change. * Modifying tests for interface reports...
1 parent 9e760b8 commit 45914be

File tree

9 files changed

+342
-206
lines changed

9 files changed

+342
-206
lines changed

cni/network/network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
type netPlugin struct {
3434
*cni.Plugin
3535
nm network.NetworkManager
36-
reportManager *telemetry.CNIReportManager
36+
reportManager *telemetry.ReportManager
3737
}
3838

3939
// NewPlugin creates a new netPlugin object.
@@ -58,7 +58,7 @@ func NewPlugin(config *common.PluginConfig) (*netPlugin, error) {
5858
}, nil
5959
}
6060

61-
func (plugin *netPlugin) SetReportManager(reportManager *telemetry.CNIReportManager) {
61+
func (plugin *netPlugin) SetReportManager(reportManager *telemetry.ReportManager) {
6262
plugin.reportManager = reportManager
6363
}
6464

cni/network/plugin/main.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package main
55

66
import (
77
"os"
8+
"reflect"
89

910
"github.com/Azure/azure-container-networking/cni"
1011
"github.com/Azure/azure-container-networking/cni/network"
@@ -17,17 +18,16 @@ const (
1718
hostNetAgentURL = "http://169.254.169.254/machine/plugins?comp=netagent&type=cnireport"
1819
ipamQueryURL = "http://169.254.169.254/machine/plugins?comp=nmagent&type=getinterfaceinfov1"
1920
pluginName = "CNI"
20-
reportType = "application/json"
2121
)
2222

2323
// Version is populated by make during build.
2424
var version string
2525

2626
// If report write succeeded, mark the report flag state to false.
27-
func markSendReport(reportManager *telemetry.CNIReportManager) {
28-
if err := reportManager.Report.SetReportState(); err != nil {
27+
func markSendReport(reportManager *telemetry.ReportManager) {
28+
if err := reportManager.SetReportState(); err != nil {
2929
log.Printf("SetReportState failed due to %v", err)
30-
reportManager.Report.ErrorMessage = err.Error()
30+
reflect.ValueOf(reportManager.Report).Elem().FieldByName("ErrorMessage").SetString(err.Error())
3131

3232
if reportManager.SendReport() != nil {
3333
log.Printf("SendReport failed due to %v", err)
@@ -36,10 +36,10 @@ func markSendReport(reportManager *telemetry.CNIReportManager) {
3636
}
3737

3838
// send error report to hostnetagent if CNI encounters any error.
39-
func reportPluginError(reportManager *telemetry.CNIReportManager, err error) {
39+
func reportPluginError(reportManager *telemetry.ReportManager, err error) {
4040
log.Printf("Report plugin error")
41-
reportManager.GetReport(pluginName, version)
42-
reportManager.Report.ErrorMessage = err.Error()
41+
reportManager.Report.(*telemetry.CNIReport).GetReport(pluginName, version, ipamQueryURL)
42+
reflect.ValueOf(reportManager.Report).Elem().FieldByName("ErrorMessage").SetString(err.Error())
4343

4444
if err = reportManager.SendReport(); err != nil {
4545
log.Printf("SendReport failed due to %v", err)
@@ -56,19 +56,18 @@ func main() {
5656
)
5757

5858
config.Version = version
59-
reportManager := &telemetry.CNIReportManager{
60-
ReportManager: &telemetry.ReportManager{
61-
HostNetAgentURL: hostNetAgentURL,
62-
ReportType: reportType,
59+
reportManager := &telemetry.ReportManager{
60+
HostNetAgentURL: hostNetAgentURL,
61+
ContentType: telemetry.ContentType,
62+
Report: &telemetry.CNIReport{
63+
Context: "AzureCNI",
6364
},
64-
IpamQueryURL: ipamQueryURL,
65-
Report: &telemetry.CNIReport{},
6665
}
6766

68-
reportManager.GetReport(pluginName, config.Version)
69-
reportManager.Report.Context = "AzureCNI"
67+
reportManager.GetHostMetadata()
68+
reportManager.Report.(*telemetry.CNIReport).GetReport(pluginName, config.Version, ipamQueryURL)
7069

71-
if !reportManager.Report.GetReportState() {
70+
if !reportManager.GetReportState() {
7271
log.Printf("GetReport state file didn't exist. Setting flag to true")
7372

7473
err = reportManager.SendReport()
@@ -122,7 +121,8 @@ func main() {
122121
}
123122

124123
// Report CNI successfully finished execution.
125-
reportManager.Report.CniSucceeded = true
124+
reflect.ValueOf(reportManager.Report).Elem().FieldByName("CniSucceeded").SetBool(true)
125+
126126
if err = reportManager.SendReport(); err != nil {
127127
log.Printf("SendReport failed due to %v", err)
128128
} else {

common/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/Azure/azure-container-networking/log"
1313
)
1414

15-
// Azure host agent XML document format.
15+
// XmlDocument - Azure host agent XML document format.
1616
type XmlDocument struct {
1717
XMLName xml.Name `xml:"Interfaces"`
1818
Interface []struct {

npm/npm.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package npm
55
import (
66
"fmt"
77
"os"
8+
"reflect"
89
"sync"
910
"time"
1011

@@ -22,7 +23,7 @@ import (
2223

2324
var (
2425
hostNetAgentURLForNpm = "http://169.254.169.254/machine/plugins?comp=netagent&type=npmreport"
25-
reportType = "application/json"
26+
contentType = "application/json"
2627
)
2728

2829
// NetworkPolicyManager contains informers for pod, namespace and networkpolicy.
@@ -40,7 +41,7 @@ type NetworkPolicyManager struct {
4041
isAzureNpmChainCreated bool
4142

4243
clusterState telemetry.ClusterState
43-
reportManager *telemetry.NPMReportManager
44+
reportManager *telemetry.ReportManager
4445
}
4546

4647
// GetClusterState returns current cluster state.
@@ -51,11 +52,18 @@ func (npMgr *NetworkPolicyManager) GetClusterState() telemetry.ClusterState {
5152
// UpdateAndSendReport updates the npm report then send it.
5253
// This function should only be called when npMgr is locked.
5354
func (npMgr *NetworkPolicyManager) UpdateAndSendReport(err error, eventMsg string) error {
54-
npMgr.reportManager.Report.ClusterState = npMgr.GetClusterState()
55-
npMgr.reportManager.Report.EventMessage = eventMsg
55+
clusterState := npMgr.GetClusterState()
56+
v := reflect.ValueOf(npMgr.reportManager.Report).Elem().FieldByName("ClusterState")
57+
if v.CanSet() {
58+
v.FieldByName("PodCount").SetInt(int64(clusterState.PodCount))
59+
v.FieldByName("NsCount").SetInt(int64(clusterState.NsCount))
60+
v.FieldByName("NwPolicyCount").SetInt(int64(clusterState.NwPolicyCount))
61+
}
62+
63+
reflect.ValueOf(npMgr.reportManager.Report).Elem().FieldByName("EventMessage").SetString(eventMsg)
5664

5765
if err != nil {
58-
npMgr.reportManager.Report.ErrorMessage = err.Error()
66+
reflect.ValueOf(npMgr.reportManager.Report).Elem().FieldByName("EventMessage").SetString(err.Error())
5967
}
6068

6169
return npMgr.reportManager.SendReport()
@@ -84,8 +92,19 @@ func (npMgr *NetworkPolicyManager) Run(stopCh <-chan struct{}) error {
8492

8593
// RunReportManager starts NPMReportManager and send telemetry periodically.
8694
func (npMgr *NetworkPolicyManager) RunReportManager() {
95+
if err := npMgr.reportManager.GetHostMetadata(); err != nil {
96+
reflect.ValueOf(npMgr.reportManager.Report).Elem().FieldByName("ErrorMessage").SetString(err.Error())
97+
}
98+
8799
for {
88-
npMgr.reportManager.Report.ClusterState = npMgr.GetClusterState()
100+
clusterState := npMgr.GetClusterState()
101+
v := reflect.ValueOf(npMgr.reportManager.Report).Elem().FieldByName("ClusterState")
102+
if v.CanSet() {
103+
v.FieldByName("PodCount").SetInt(int64(clusterState.PodCount))
104+
v.FieldByName("NsCount").SetInt(int64(clusterState.NsCount))
105+
v.FieldByName("NwPolicyCount").SetInt(int64(clusterState.NwPolicyCount))
106+
}
107+
89108
if err := npMgr.reportManager.SendReport(); err != nil {
90109
log.Printf("Error sending NPM telemetry report")
91110
}
@@ -115,12 +134,10 @@ func NewNetworkPolicyManager(clientset *kubernetes.Clientset, informerFactory in
115134
NsCount: 0,
116135
NwPolicyCount: 0,
117136
},
118-
reportManager: &telemetry.NPMReportManager{
119-
ReportManager: &telemetry.ReportManager{
120-
HostNetAgentURL: hostNetAgentURLForNpm,
121-
ReportType: reportType,
122-
},
123-
Report: &telemetry.NPMReport{},
137+
reportManager: &telemetry.ReportManager{
138+
HostNetAgentURL: hostNetAgentURLForNpm,
139+
ContentType: contentType,
140+
Report: &telemetry.NPMReport{},
124141
},
125142
}
126143

@@ -132,7 +149,7 @@ func NewNetworkPolicyManager(clientset *kubernetes.Clientset, informerFactory in
132149

133150
clusterID := util.GetClusterID(npMgr.nodeName)
134151
clusterState := npMgr.GetClusterState()
135-
npMgr.reportManager.GetReport(clusterID, npMgr.nodeName, npmVersion, serverVersion.GitVersion, clusterState)
152+
npMgr.reportManager.Report.(*telemetry.NPMReport).GetReport(clusterID, npMgr.nodeName, npmVersion, serverVersion.GitVersion, clusterState)
136153

137154
allNs, err := newNs(util.KubeAllNamespacesFlag)
138155
if err != nil {

platform/os_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const (
2323

2424
// NPMRuntimePath is the path where NPM logging files are stored.
2525
NPMRuntimePath = "/var/run/"
26+
27+
// DNCRuntimePath is the path where DNC logging files are stored.
28+
DNCRuntimePath = "/var/run/"
2629
)
2730

2831
// GetOSInfo returns OS version information.

platform/os_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const (
1717

1818
// NPMRuntimePath is the path where NPM state files are stored.
1919
NPMRuntimePath = ""
20+
21+
// DNCRuntimePath is the path where NPM state files are stored.
22+
DNCRuntimePath = ""
2023
)
2124

2225
// GetOSInfo returns OS version information.

0 commit comments

Comments
 (0)