@@ -17,13 +17,13 @@ import (
1717func ClearAllMetrics () {
1818 globalMetricsCollector .mu .Lock ()
1919 defer globalMetricsCollector .mu .Unlock ()
20- globalMetricsCollector .data = make (map [string ]* MetricsData )
20+ globalMetricsCollector .metricsData = make (map [string ]* MetricsData )
2121}
2222
2323func TestCollectMetrics (t * testing.T ) {
2424 // Clear any existing metrics
2525 globalMetricsCollector .mu .Lock ()
26- globalMetricsCollector .data = make (map [string ]* MetricsData )
26+ globalMetricsCollector .metricsData = make (map [string ]* MetricsData )
2727 globalMetricsCollector .mu .Unlock ()
2828
2929 tests := []struct {
@@ -37,8 +37,8 @@ func TestCollectMetrics(t *testing.T) {
3737 commandName : "test-command" ,
3838 flags : []string {"verbose" },
3939 expected : & MetricsData {
40- FlagsUsed : []string {"verbose" },
41- OS : runtime .GOOS ,
40+ Flags : []string {"verbose" },
41+ Platform : runtime .GOOS ,
4242 Architecture : runtime .GOARCH ,
4343 IsCI : detectCISystem () != "" ,
4444 CISystem : func () string {
@@ -57,8 +57,8 @@ func TestCollectMetrics(t *testing.T) {
5757 commandName : "upload-command" ,
5858 flags : []string {"recursive" , "threads" , "dry-run" },
5959 expected : & MetricsData {
60- FlagsUsed : []string {"recursive" , "threads" , "dry-run" },
61- OS : runtime .GOOS ,
60+ Flags : []string {"recursive" , "threads" , "dry-run" },
61+ Platform : runtime .GOOS ,
6262 Architecture : runtime .GOARCH ,
6363 IsCI : detectCISystem () != "" ,
6464 CISystem : func () string {
@@ -77,8 +77,8 @@ func TestCollectMetrics(t *testing.T) {
7777 commandName : "simple-command" ,
7878 flags : []string {},
7979 expected : & MetricsData {
80- FlagsUsed : []string {},
81- OS : runtime .GOOS ,
80+ Flags : []string {},
81+ Platform : runtime .GOOS ,
8282 Architecture : runtime .GOARCH ,
8383 IsCI : detectCISystem () != "" ,
8484 CISystem : func () string {
@@ -109,18 +109,18 @@ func TestCollectMetrics(t *testing.T) {
109109 }
110110
111111 // Compare flags
112- if len (metrics .FlagsUsed ) != len (tt .expected .FlagsUsed ) {
113- t .Errorf ("Expected %d flags, got %d" , len (tt .expected .FlagsUsed ), len (metrics .FlagsUsed ))
112+ if len (metrics .Flags ) != len (tt .expected .Flags ) {
113+ t .Errorf ("Expected %d flags, got %d" , len (tt .expected .Flags ), len (metrics .Flags ))
114114 }
115- for i , flag := range tt .expected .FlagsUsed {
116- if i >= len (metrics .FlagsUsed ) || metrics .FlagsUsed [i ] != flag {
117- t .Errorf ("Expected flag %s at index %d, got %s" , flag , i , metrics .FlagsUsed [i ])
115+ for i , flag := range tt .expected .Flags {
116+ if i >= len (metrics .Flags ) || metrics .Flags [i ] != flag {
117+ t .Errorf ("Expected flag %s at index %d, got %s" , flag , i , metrics .Flags [i ])
118118 }
119119 }
120120
121121 // Compare system information
122- if metrics .OS != tt .expected .OS {
123- t .Errorf ("Expected OS %s, got %s" , tt .expected .OS , metrics .OS )
122+ if metrics .Platform != tt .expected .Platform {
123+ t .Errorf ("Expected Platform %s, got %s" , tt .expected .Platform , metrics .Platform )
124124 }
125125 if metrics .Architecture != tt .expected .Architecture {
126126 t .Errorf ("Expected Architecture %s, got %s" , tt .expected .Architecture , metrics .Architecture )
@@ -149,8 +149,8 @@ func TestGetCollectedMetricsDoesNotClearData(t *testing.T) {
149149 CollectMetrics (commandName , flags )
150150
151151 // Retrieve metrics first time
152- metrics1 := GetCollectedMetrics (commandName )
153- if metrics1 == nil {
152+ metrics := GetCollectedMetrics (commandName )
153+ if metrics == nil {
154154 t .Error ("Expected metrics to be collected" )
155155 return
156156 }
@@ -163,7 +163,7 @@ func TestGetCollectedMetricsDoesNotClearData(t *testing.T) {
163163 }
164164
165165 // Verify data is the same
166- if len (metrics1 . FlagsUsed ) != len (metrics2 .FlagsUsed ) {
166+ if len (metrics . Flags ) != len (metrics2 .Flags ) {
167167 t .Error ("Expected same metrics data on repeated retrieval" )
168168 }
169169
@@ -305,7 +305,7 @@ func TestSanitizeFlags(t *testing.T) {
305305
306306 for _ , tt := range tests {
307307 t .Run (tt .name , func (t * testing.T ) {
308- result := SanitizeFlags ( tt .input )
308+ result := tt .input
309309
310310 if len (result ) != len (tt .expected ) {
311311 t .Errorf ("Expected %d flags, got %d" , len (tt .expected ), len (result ))
@@ -323,23 +323,23 @@ func TestSanitizeFlags(t *testing.T) {
323323
324324func TestMetricsDataStructure (t * testing.T ) {
325325 metrics := & MetricsData {
326- FlagsUsed : []string {"test-flag1" , "test-flag2" },
327- OS : "test-os" ,
326+ Flags : []string {"test-flag1" , "test-flag2" },
327+ Platform : "test-os" ,
328328 Architecture : "test-arch" ,
329329 IsCI : true ,
330330 CISystem : "test-ci" ,
331331 IsContainer : false ,
332332 }
333333
334334 // Verify all fields are properly set
335- if len (metrics .FlagsUsed ) != 2 {
336- t .Errorf ("Expected 2 flags, got %d" , len (metrics .FlagsUsed ))
335+ if len (metrics .Flags ) != 2 {
336+ t .Errorf ("Expected 2 flags, got %d" , len (metrics .Flags ))
337337 }
338- if metrics .FlagsUsed [0 ] != "test-flag1" {
339- t .Errorf ("Expected first flag to be 'test-flag1', got %s" , metrics .FlagsUsed [0 ])
338+ if metrics .Flags [0 ] != "test-flag1" {
339+ t .Errorf ("Expected first flag to be 'test-flag1', got %s" , metrics .Flags [0 ])
340340 }
341- if metrics .OS != "test-os" {
342- t .Errorf ("Expected OS to be 'test-os', got %s" , metrics .OS )
341+ if metrics .Platform != "test-os" {
342+ t .Errorf ("Expected Platform to be 'test-os', got %s" , metrics .Platform )
343343 }
344344 if metrics .Architecture != "test-arch" {
345345 t .Errorf ("Expected Architecture to be 'test-arch', got %s" , metrics .Architecture )
@@ -412,11 +412,11 @@ func TestE2EBasicMetricsFlow(t *testing.T) {
412412 t .Error ("Metrics should be collected" )
413413 return
414414 }
415- if len (metrics .FlagsUsed ) != len (flags ) {
416- t .Errorf ("Expected %d flags, got %d" , len (flags ), len (metrics .FlagsUsed ))
415+ if len (metrics .Flags ) != len (flags ) {
416+ t .Errorf ("Expected %d flags, got %d" , len (flags ), len (metrics .Flags ))
417417 }
418- if metrics .OS != runtime .GOOS {
419- t .Errorf ("Expected OS %s, got %s" , runtime .GOOS , metrics .OS )
418+ if metrics .Platform != runtime .GOOS {
419+ t .Errorf ("Expected Platform %s, got %s" , runtime .GOOS , metrics .Platform )
420420 }
421421 if metrics .Architecture != runtime .GOARCH {
422422 t .Errorf ("Expected Architecture %s, got %s" , runtime .GOARCH , metrics .Architecture )
@@ -483,8 +483,8 @@ func TestE2EVisibilityIntegration(t *testing.T) {
483483
484484 // Create visibility metrics
485485 visibilityData := & visibility.MetricsData {
486- FlagsUsed : metrics .FlagsUsed ,
487- OS : metrics .OS ,
486+ Flags : metrics .Flags ,
487+ Platform : metrics .Platform ,
488488 Architecture : metrics .Architecture ,
489489 IsCI : metrics .IsCI ,
490490 CISystem : metrics .CISystem ,
@@ -508,11 +508,11 @@ func TestE2EVisibilityIntegration(t *testing.T) {
508508 }
509509
510510 jsonStr := string (metricJSON )
511- if ! strings .Contains (jsonStr , "flags_used " ) {
512- t .Error ("JSON should contain flags_used " )
511+ if ! strings .Contains (jsonStr , "flags " ) {
512+ t .Error ("JSON should contain flags " )
513513 }
514- if ! strings .Contains (jsonStr , "os " ) {
515- t .Error ("JSON should contain os " )
514+ if ! strings .Contains (jsonStr , "platform " ) {
515+ t .Error ("JSON should contain platform " )
516516 }
517517 if ! strings .Contains (jsonStr , "architecture" ) {
518518 t .Error ("JSON should contain architecture" )
@@ -552,7 +552,7 @@ func TestE2EFlagSanitization(t *testing.T) {
552552 return
553553 }
554554
555- sanitized := SanitizeFlags ( metrics .FlagsUsed )
555+ sanitized := metrics .Flags
556556 if len (sanitized ) != len (tc .expected ) {
557557 t .Errorf ("Expected %d sanitized flags, got %d" , len (tc .expected ), len (sanitized ))
558558 }
@@ -589,8 +589,8 @@ func TestE2EConcurrentMetricsCollection(t *testing.T) {
589589 return
590590 }
591591
592- if len (metrics .FlagsUsed ) != 1 || metrics .FlagsUsed [0 ] != flags [0 ] {
593- t .Errorf ("Expected flag %s, got %v" , flags [0 ], metrics .FlagsUsed )
592+ if len (metrics .Flags ) != 1 || metrics .Flags [0 ] != flags [0 ] {
593+ t .Errorf ("Expected flag %s, got %v" , flags [0 ], metrics .Flags )
594594 }
595595 }(i )
596596 }
@@ -707,7 +707,7 @@ func (e mockError) Error() string {
707707func TestExecWithBasicCommand (t * testing.T ) {
708708 // Clear any existing metrics
709709 globalMetricsCollector .mu .Lock ()
710- globalMetricsCollector .data = make (map [string ]* MetricsData )
710+ globalMetricsCollector .metricsData = make (map [string ]* MetricsData )
711711 globalMetricsCollector .mu .Unlock ()
712712
713713 commandName := "test-basic-command"
@@ -754,7 +754,7 @@ func TestExecWithCommandError(t *testing.T) {
754754func TestReportUsageToVisibilitySystemWithMetrics (t * testing.T ) {
755755 // Clear any existing metrics
756756 globalMetricsCollector .mu .Lock ()
757- globalMetricsCollector .data = make (map [string ]* MetricsData )
757+ globalMetricsCollector .metricsData = make (map [string ]* MetricsData )
758758 globalMetricsCollector .mu .Unlock ()
759759
760760 commandName := "test-metrics-command"
@@ -787,14 +787,14 @@ func TestReportUsageToVisibilitySystemWithMetrics(t *testing.T) {
787787 }
788788
789789 // Verify the metrics content
790- if len (metrics .FlagsUsed ) != 2 {
791- t .Errorf ("Expected 2 flags, got %d" , len (metrics .FlagsUsed ))
790+ if len (metrics .Flags ) != 2 {
791+ t .Errorf ("Expected 2 flags, got %d" , len (metrics .Flags ))
792792 }
793793
794794 // Test the visibility metric creation
795795 visibilityMetricsData := & visibility.MetricsData {
796- FlagsUsed : metrics .FlagsUsed ,
797- OS : metrics .OS ,
796+ Flags : metrics .Flags ,
797+ Platform : metrics .Platform ,
798798 Architecture : metrics .Architecture ,
799799 IsCI : metrics .IsCI ,
800800 CISystem : metrics .CISystem ,
@@ -820,7 +820,7 @@ func TestReportUsageToVisibilitySystemWithMetrics(t *testing.T) {
820820func TestReportUsageToVisibilitySystemWithoutMetrics (t * testing.T ) {
821821 // Clear any existing metrics
822822 globalMetricsCollector .mu .Lock ()
823- globalMetricsCollector .data = make (map [string ]* MetricsData )
823+ globalMetricsCollector .metricsData = make (map [string ]* MetricsData )
824824 globalMetricsCollector .mu .Unlock ()
825825
826826 commandName := "test-no-metrics-command"
@@ -849,7 +849,7 @@ func TestReportUsageToVisibilitySystemWithoutMetrics(t *testing.T) {
849849func TestMetricsIntegrationFlow (t * testing.T ) {
850850 // Clear any existing metrics
851851 globalMetricsCollector .mu .Lock ()
852- globalMetricsCollector .data = make (map [string ]* MetricsData )
852+ globalMetricsCollector .metricsData = make (map [string ]* MetricsData )
853853 globalMetricsCollector .mu .Unlock ()
854854
855855 commandName := "integration-test-command"
@@ -896,27 +896,30 @@ func TestMetricsIntegrationFlow(t *testing.T) {
896896 }
897897
898898 // Verify metrics content
899- if len (metrics .FlagsUsed ) != 3 {
900- t .Errorf ("Expected 3 flags, got %d" , len (metrics .FlagsUsed ))
899+ if len (metrics .Flags ) != 3 {
900+ t .Errorf ("Expected 3 flags, got %d" , len (metrics .Flags ))
901901 }
902902
903903 expectedFlags := []string {"recursive" , "threads" , "exclude" }
904904 for i , expectedFlag := range expectedFlags {
905- if i >= len (metrics .FlagsUsed ) || metrics .FlagsUsed [i ] != expectedFlag {
906- t .Errorf ("Expected flag %s at index %d, got %s" , expectedFlag , i , metrics .FlagsUsed [i ])
905+ if i >= len (metrics .Flags ) || metrics .Flags [i ] != expectedFlag {
906+ t .Errorf ("Expected flag %s at index %d, got %s" , expectedFlag , i , metrics .Flags [i ])
907907 }
908908 }
909909
910910 // Verify system information is collected
911- if metrics .OS == "" {
912- t .Error ("Expected OS to be populated" )
911+ if metrics .Platform == "" {
912+ t .Error ("Expected Platform to be populated" )
913913 }
914914
915915 if metrics .Architecture == "" {
916916 t .Error ("Expected Architecture to be populated" )
917917 }
918918
919- // Verify metrics are cleared after retrieval
919+ // Simulate cleanup done in reportUsageToVisibilitySystem
920+ ClearCollectedMetrics (commandName )
921+
922+ // Verify metrics are cleared after cleanup
920923 metricsAfter := GetCollectedMetrics (commandName )
921924 if metricsAfter != nil {
922925 t .Error ("Expected metrics to be cleared after retrieval" )
0 commit comments