@@ -23,6 +23,11 @@ import (
2323)
2424
2525const (
26+ // NPMTelemetryFile Path.
27+ NPMTelemetryFile = platform .NPMRuntimePath + "AzureNPMTelemetry.json"
28+ // CNITelemetryFile Path.
29+ CNITelemetryFile = platform .CNIRuntimePath + "AzureCNITelemetry.json"
30+
2631 metadataURL = "http://169.254.169.254/metadata/instance?api-version=2017-08-01&format=json"
2732 ContentType = "application/json"
2833)
@@ -73,24 +78,6 @@ type OrchestratorInfo struct {
7378 ErrorMessage string
7479}
7580
76- const (
77- // CNITelemetryFile Path.
78- CNITelemetryFile = platform .CNIRuntimePath + "AzureCNITelemetry.json"
79- // NPMTelemetryFile Path.
80- NPMTelemetryFile = platform .NPMRuntimePath + "AzureNPMTelemetry.json"
81- // DNCTelemetryFile Path.
82- DNCTelemetryFile = platform .DNCRuntimePath + "AzureDNCTelemetry.json"
83- )
84-
85- const (
86- // CNI report type
87- CNIReportType = "CNI"
88- // NPM report type
89- NPMReportType = "NPM"
90- // DNC report type
91- DNCReportType = "DNC"
92- )
93-
9481// Metadata retrieved from wireserver
9582type Metadata struct {
9683 Location string `json:"location"`
@@ -155,18 +142,6 @@ type NPMReport struct {
155142 Metadata Metadata `json:"compute"`
156143}
157144
158- // DNCReport structure.
159- type DNCReport struct {
160- IsNewInstance bool
161- CPUUsage string
162- MemoryUsage string
163- Processes string
164- EventMessage string
165- PartitionKey string
166- Allocations string
167- Metadata Metadata `json:"compute"`
168- }
169-
170145// ReportManager structure.
171146type ReportManager struct {
172147 HostNetAgentURL string
@@ -230,24 +205,18 @@ func (report *NPMReport) GetReport(clusterID, nodeName, npmVersion, kubernetesVe
230205func (reportMgr * ReportManager ) SendReport () error {
231206 log .Printf ("[Telemetry] Going to send Telemetry report to hostnetagent %v" , reportMgr .HostNetAgentURL )
232207
233- var body bytes.Buffer
234- httpc := & http.Client {}
235- json .NewEncoder (& body ).Encode (reportMgr .Report )
236-
237208 switch reportMgr .Report .(type ) {
238209 case * CNIReport :
239210 log .Printf ("[Telemetry] %+v" , reportMgr .Report .(* CNIReport ))
240-
241211 case * NPMReport :
242212 log .Printf ("[Telemetry] %+v" , reportMgr .Report .(* NPMReport ))
243-
244- case * DNCReport :
245- log .Printf ("[Telemetry] %+v" , reportMgr .Report .(* DNCReport ))
246-
247213 default :
248- return fmt . Errorf ("[Telemetry] failed to resolve report type" )
214+ log . Printf ("[Telemetry] %+v" , reportMgr . Report )
249215 }
250216
217+ httpc := & http.Client {}
218+ var body bytes.Buffer
219+ json .NewEncoder (& body ).Encode (reportMgr .Report )
251220 resp , err := httpc .Post (reportMgr .HostNetAgentURL , reportMgr .ContentType , & body )
252221 if err != nil {
253222 return fmt .Errorf ("[Telemetry] HTTP Post returned error %v" , err )
@@ -271,29 +240,11 @@ func (reportMgr *ReportManager) SendReport() error {
271240}
272241
273242// SetReportState will save the state in file if telemetry report sent successfully.
274- func (reportMgr * ReportManager ) SetReportState () error {
275- var telemetryFile string
243+ func (reportMgr * ReportManager ) SetReportState (telemetryFile string ) error {
276244 var reportBytes []byte
277245 var err error
278246
279- // get bytes from associated report type
280- switch reportMgr .Report .(type ) {
281- case * CNIReport :
282- telemetryFile = CNITelemetryFile
283- reportBytes , err = json .Marshal (reportMgr .Report .(* CNIReport ))
284-
285- case * NPMReport :
286- telemetryFile = NPMTelemetryFile
287- reportBytes , err = json .Marshal (reportMgr .Report .(* NPMReport ))
288-
289- case * DNCReport :
290- telemetryFile = DNCTelemetryFile
291- reportBytes , err = json .Marshal (reportMgr .Report .(* DNCReport ))
292-
293- default :
294- return fmt .Errorf ("[Telemetry] Invalid report type" )
295- }
296-
247+ reportBytes , err = json .Marshal (reportMgr .Report )
297248 if err != nil {
298249 return fmt .Errorf ("[Telemetry] report write failed with err %+v" , err )
299250 }
@@ -319,24 +270,7 @@ func (reportMgr *ReportManager) SetReportState() error {
319270}
320271
321272// GetReportState will check if report is sent at least once by checking telemetry file.
322- func (reportMgr * ReportManager ) GetReportState () bool {
323- var telemetryFile string
324-
325- switch reportMgr .Report .(type ) {
326- case * CNIReport :
327- telemetryFile = CNITelemetryFile
328-
329- case * NPMReport :
330- telemetryFile = NPMTelemetryFile
331-
332- case * DNCReport :
333- telemetryFile = DNCTelemetryFile
334-
335- default :
336- log .Printf ("[Telemetry] Invalid report type" )
337- return false
338- }
339-
273+ func (reportMgr * ReportManager ) GetReportState (telemetryFile string ) bool {
340274 // try to set IsNewInstance in report
341275 if _ , err := os .Stat (telemetryFile ); os .IsNotExist (err ) {
342276 log .Printf ("[Telemetry] File not exist %v" , telemetryFile )
@@ -518,28 +452,3 @@ func (reportMgr *ReportManager) GetHostMetadata() error {
518452
519453 return err
520454}
521-
522- // GetSystemDetails - retrieve system details like cpu usage, mem usage, and number or running processes
523- func (reportMgr * ReportManager ) GetSystemDetails () error {
524- // hostStat, err := host.Info()
525- // if err != nil {
526- // return err
527- // }
528-
529- // reflect.ValueOf(reportMgr.Report).Elem().FieldByName("Processes").SetString(strconv.FormatUint(hostStat.Procs, 10))
530-
531- // cpuStat, err := cpu.Percent(0, false)
532- // if err != nil {
533- // return err
534- // }
535-
536- // reflect.ValueOf(reportMgr.Report).Elem().FieldByName("CPUUsage").SetString(strconv.FormatFloat(cpuStat[0], 'f', 2, 64))
537-
538- // memStat, err := mem.VirtualMemory()
539- // if err != nil {
540- // return err
541- // }
542-
543- // reflect.ValueOf(reportMgr.Report).Elem().FieldByName("MemoryUsage").SetString(strconv.FormatFloat(memStat.UsedPercent, 'f', 2, 64))
544- return nil
545- }
0 commit comments