@@ -43,7 +43,7 @@ const (
4343)
4444
4545type Labels map [string ]string
46- type NormalizedValues string
46+ type NormalizedValues [] string
4747
4848type Aggregate struct {
4949 definition * api.AggregateDefinition
@@ -78,7 +78,7 @@ func (aggregate *Aggregate) LabelsFromEntry(entry config.GenericMap) (Labels, bo
7878}
7979
8080func (labels Labels ) getNormalizedValues () NormalizedValues {
81- var normalizedAsString string
81+ var normalized NormalizedValues
8282
8383 keys := make ([]string , 0 , len (labels ))
8484 for k := range labels {
@@ -87,20 +87,16 @@ func (labels Labels) getNormalizedValues() NormalizedValues {
8787 sort .Strings (keys )
8888
8989 for _ , k := range keys {
90- normalizedAsString += labels [k ] + ","
90+ normalized = append ( normalized , labels [k ])
9191 }
9292
93- if len (normalizedAsString ) > 0 {
94- normalizedAsString = normalizedAsString [:len (normalizedAsString )- 1 ]
95- }
96-
97- return NormalizedValues (normalizedAsString )
93+ return normalized
9894}
9995
10096func (aggregate * Aggregate ) filterEntry (entry config.GenericMap ) (NormalizedValues , Labels , error ) {
10197 labels , allLabelsFound := aggregate .LabelsFromEntry (entry )
10298 if ! allLabelsFound {
103- return "" , nil , fmt .Errorf ("missing keys in entry" )
99+ return nil , nil , fmt .Errorf ("missing keys in entry" )
104100 }
105101
106102 normalizedValues := labels .getNormalizedValues ()
@@ -128,7 +124,7 @@ func (aggregate *Aggregate) UpdateByEntry(entry config.GenericMap, normalizedVal
128124 defer aggregate .mutex .Unlock ()
129125
130126 var groupState * GroupState
131- oldEntry , ok := aggregate .cache .GetCacheEntry (string ( normalizedValues ) )
127+ oldEntry , ok := aggregate .cache .GetCacheEntry (normalizedValues )
132128 if ! ok {
133129 groupState = & GroupState {normalizedValues : normalizedValues , labels : labels }
134130 initVal := getInitValue (string (aggregate .definition .OperationType ))
@@ -140,7 +136,7 @@ func (aggregate *Aggregate) UpdateByEntry(entry config.GenericMap, normalizedVal
140136 } else {
141137 groupState = oldEntry .(* GroupState )
142138 }
143- aggregate .cache .UpdateCacheEntry (string ( normalizedValues ) , func () interface {} {
139+ aggregate .cache .UpdateCacheEntry (normalizedValues , func () interface {} {
144140 return groupState
145141 })
146142
@@ -212,20 +208,21 @@ func (aggregate *Aggregate) GetMetrics() []config.GenericMap {
212208 var metrics []config.GenericMap
213209
214210 // iterate over the items in the cache
215- aggregate .cache .Iterate (func (_ string , value interface {}) {
211+ aggregate .cache .Iterate (func (_ uint64 , value interface {}) {
216212 group := value .(* GroupState )
213+ nv := strings .Join (group .normalizedValues , "," )
217214 newEntry := config.GenericMap {
218215 "name" : aggregate .definition .Name ,
219216 "operation_type" : aggregate .definition .OperationType ,
220217 "operation_key" : aggregate .definition .OperationKey ,
221218 "by" : strings .Join (aggregate .definition .GroupByKeys , "," ),
222- "aggregate" : string ( group . normalizedValues ) ,
219+ "aggregate" : nv ,
223220 "total_value" : group .totalValue ,
224221 "total_count" : group .totalCount ,
225222 "recent_raw_values" : group .recentRawValues ,
226223 "recent_op_value" : group .recentOpValue ,
227224 "recent_count" : group .recentCount ,
228- strings .Join (aggregate .definition .GroupByKeys , "_" ): string ( group . normalizedValues ) ,
225+ strings .Join (aggregate .definition .GroupByKeys , "_" ): nv ,
229226 }
230227 // add the items in aggregate.definition.GroupByKeys individually to the entry
231228 for _ , key := range aggregate .definition .GroupByKeys {
0 commit comments