@@ -23,6 +23,7 @@ import (
2323
2424 "github.com/netobserv/flowlogs-pipeline/pkg/api"
2525 "github.com/netobserv/flowlogs-pipeline/pkg/config"
26+ "github.com/netobserv/flowlogs-pipeline/pkg/test"
2627 "github.com/stretchr/testify/require"
2728)
2829
@@ -34,7 +35,7 @@ func TestNewAggregator_Invalid(t *testing.T) {
3435 Operation : "sum" ,
3536 SplitAB : true ,
3637 Input : "Input" ,
37- })
38+ }, nil )
3839 require .NotNil (t , err )
3940
4041 // unknown OperationType
@@ -43,15 +44,15 @@ func TestNewAggregator_Invalid(t *testing.T) {
4344 Operation : "unknown" ,
4445 SplitAB : true ,
4546 Input : "Input" ,
46- })
47+ }, nil )
4748 require .NotNil (t , err )
4849
4950 // invalid first agg
5051 _ , err = newAggregator (api.OutputField {
5152 Operation : "first" ,
5253 SplitAB : true ,
5354 Input : "Input" ,
54- })
55+ }, nil )
5556 require .NotNil (t , err )
5657}
5758
@@ -64,58 +65,58 @@ func TestNewAggregator_Valid(t *testing.T) {
6465 {
6566 name : "Default SplitAB" ,
6667 outputField : api.OutputField {Name : "MyAgg" , Operation : "sum" },
67- expected : & aSum {aggregateBase {"MyAgg" , "MyAgg" , false , float64 (0 )}},
68+ expected : & aSum {aggregateBase {"MyAgg" , "MyAgg" , false , float64 (0 ), nil }},
6869 },
6970 {
7071 name : "Default input" ,
7172 outputField : api.OutputField {Name : "MyAgg" , Operation : "sum" , SplitAB : true },
72- expected : & aSum {aggregateBase {"MyAgg" , "MyAgg" , true , float64 (0 )}},
73+ expected : & aSum {aggregateBase {"MyAgg" , "MyAgg" , true , float64 (0 ), nil }},
7374 },
7475 {
7576 name : "Custom input" ,
7677 outputField : api.OutputField {Name : "MyAgg" , Operation : "sum" , Input : "MyInput" },
77- expected : & aSum {aggregateBase {"MyInput" , "MyAgg" , false , float64 (0 )}},
78+ expected : & aSum {aggregateBase {"MyInput" , "MyAgg" , false , float64 (0 ), nil }},
7879 },
7980 {
8081 name : "OperationType sum" ,
8182 outputField : api.OutputField {Name : "MyAgg" , Operation : "sum" },
82- expected : & aSum {aggregateBase {"MyAgg" , "MyAgg" , false , float64 (0 )}},
83+ expected : & aSum {aggregateBase {"MyAgg" , "MyAgg" , false , float64 (0 ), nil }},
8384 },
8485 {
8586 name : "OperationType count" ,
8687 outputField : api.OutputField {Name : "MyAgg" , Operation : "count" },
87- expected : & aCount {aggregateBase {"MyAgg" , "MyAgg" , false , float64 (0 )}},
88+ expected : & aCount {aggregateBase {"MyAgg" , "MyAgg" , false , float64 (0 ), nil }},
8889 },
8990 {
9091 name : "OperationType max" ,
9192 outputField : api.OutputField {Name : "MyAgg" , Operation : "max" },
92- expected : & aMax {aggregateBase {"MyAgg" , "MyAgg" , false , - math .MaxFloat64 }},
93+ expected : & aMax {aggregateBase {"MyAgg" , "MyAgg" , false , - math .MaxFloat64 , nil }},
9394 },
9495 {
9596 name : "OperationType min" ,
9697 outputField : api.OutputField {Name : "MyAgg" , Operation : "min" },
97- expected : & aMin {aggregateBase {"MyAgg" , "MyAgg" , false , math .MaxFloat64 }},
98+ expected : & aMin {aggregateBase {"MyAgg" , "MyAgg" , false , math .MaxFloat64 , nil }},
9899 },
99100 {
100101 name : "Default first" ,
101102 outputField : api.OutputField {Name : "MyCp" , Operation : "first" },
102- expected : & aFirst {aggregateBase {"MyCp" , "MyCp" , false , nil }},
103+ expected : & aFirst {aggregateBase {"MyCp" , "MyCp" , false , nil , nil }},
103104 },
104105 {
105106 name : "Custom input first" ,
106107 outputField : api.OutputField {Name : "MyCp" , Operation : "first" , Input : "MyInput" },
107- expected : & aFirst {aggregateBase {"MyInput" , "MyCp" , false , nil }},
108+ expected : & aFirst {aggregateBase {"MyInput" , "MyCp" , false , nil , nil }},
108109 },
109110 {
110111 name : "Default last" ,
111112 outputField : api.OutputField {Name : "MyCp" , Operation : "last" },
112- expected : & aLast {aggregateBase {"MyCp" , "MyCp" , false , nil }},
113+ expected : & aLast {aggregateBase {"MyCp" , "MyCp" , false , nil , nil }},
113114 },
114115 }
115116
116117 for _ , test := range table {
117118 t .Run (test .name , func (t * testing.T ) {
118- agg , err := newAggregator (test .outputField )
119+ agg , err := newAggregator (test .outputField , nil )
119120 require .NoError (t , err )
120121 require .Equal (t , test .expected , agg )
121122 })
@@ -134,7 +135,7 @@ func TestAddField_and_Update(t *testing.T) {
134135 }
135136 var aggs []aggregator
136137 for _ , of := range ofs {
137- agg , err := newAggregator (of )
138+ agg , err := newAggregator (of , nil )
138139 require .NoError (t , err )
139140 aggs = append (aggs , agg )
140141 }
@@ -183,3 +184,35 @@ func TestAddField_and_Update(t *testing.T) {
183184 })
184185 }
185186}
187+
188+ func TestMissingFieldError (t * testing.T ) {
189+ test .ResetPromRegistry ()
190+ metrics := newMetrics (opMetrics )
191+ agg , err := newAggregator (api.OutputField {Name : "Bytes" , Operation : "sum" , SplitAB : true }, metrics )
192+ require .NoError (t , err )
193+
194+ conn := NewConnBuilder (metrics ).Build ()
195+ agg .addField (conn )
196+
197+ flowLog := config.GenericMap {}
198+ agg .update (conn , flowLog , dirAB , true )
199+
200+ exposed := test .ReadExposedMetrics (t )
201+ require .Contains (t , exposed , `conntrack_aggregator_errors{error="MissingFieldError",field="Bytes"} 1` )
202+ }
203+
204+ func TestFloat64ConversionError (t * testing.T ) {
205+ test .ResetPromRegistry ()
206+ metrics := newMetrics (opMetrics )
207+ agg , err := newAggregator (api.OutputField {Name : "Bytes" , Operation : "sum" , SplitAB : true }, metrics )
208+ require .NoError (t , err )
209+
210+ conn := NewConnBuilder (metrics ).Build ()
211+ agg .addField (conn )
212+
213+ flowLog := config.GenericMap {"Bytes" : "float64 inconvertible value" }
214+ agg .update (conn , flowLog , dirAB , true )
215+
216+ exposed := test .ReadExposedMetrics (t )
217+ require .Contains (t , exposed , `conntrack_aggregator_errors{error="Float64ConversionError",field="Bytes"} 1` )
218+ }
0 commit comments