@@ -53,6 +53,7 @@ type Aggregate struct {
5353
5454type GroupState struct {
5555 normalizedValues NormalizedValues
56+ labels Labels
5657 recentRawValues []float64
5758 recentOpValue float64
5859 recentCount int
@@ -95,14 +96,14 @@ func (labels Labels) getNormalizedValues() NormalizedValues {
9596 return NormalizedValues (normalizedAsString )
9697}
9798
98- func (aggregate Aggregate ) FilterEntry (entry config.GenericMap ) (error , NormalizedValues ) {
99+ func (aggregate Aggregate ) FilterEntry (entry config.GenericMap ) (error , NormalizedValues , Labels ) {
99100 labels , allLabelsFound := aggregate .LabelsFromEntry (entry )
100101 if ! allLabelsFound {
101- return fmt .Errorf ("missing keys in entry" ), ""
102+ return fmt .Errorf ("missing keys in entry" ), "" , nil
102103 }
103104
104105 normalizedValues := labels .getNormalizedValues ()
105- return nil , normalizedValues
106+ return nil , normalizedValues , labels
106107}
107108
108109func getInitValue (operation string ) float64 {
@@ -120,15 +121,15 @@ func getInitValue(operation string) float64 {
120121 }
121122}
122123
123- func (aggregate Aggregate ) UpdateByEntry (entry config.GenericMap , normalizedValues NormalizedValues ) error {
124+ func (aggregate Aggregate ) UpdateByEntry (entry config.GenericMap , normalizedValues NormalizedValues , labels Labels ) error {
124125
125126 aggregate .mutex .Lock ()
126127 defer aggregate .mutex .Unlock ()
127128
128129 var groupState * GroupState
129130 oldEntry , ok := aggregate .cache .GetCacheEntry (string (normalizedValues ))
130131 if ! ok {
131- groupState = & GroupState {normalizedValues : normalizedValues }
132+ groupState = & GroupState {normalizedValues : normalizedValues , labels : labels }
132133 initVal := getInitValue (string (aggregate .Definition .Operation ))
133134 groupState .totalValue = initVal
134135 groupState .recentOpValue = initVal
@@ -183,13 +184,13 @@ func (aggregate Aggregate) UpdateByEntry(entry config.GenericMap, normalizedValu
183184func (aggregate Aggregate ) Evaluate (entries []config.GenericMap ) error {
184185 for _ , entry := range entries {
185186 // filter entries matching labels with aggregates
186- err , normalizedValues := aggregate .FilterEntry (entry )
187+ err , normalizedValues , labels := aggregate .FilterEntry (entry )
187188 if err != nil {
188189 continue
189190 }
190191
191192 // update aggregate group by entry
192- err = aggregate .UpdateByEntry (entry , normalizedValues )
193+ err = aggregate .UpdateByEntry (entry , normalizedValues , labels )
193194 if err != nil {
194195 log .Debugf ("UpdateByEntry error %v" , err )
195196 continue
@@ -208,7 +209,7 @@ func (aggregate Aggregate) GetMetrics() []config.GenericMap {
208209 // iterate over the items in the cache
209210 aggregate .cache .Iterate (func (key string , value interface {}) {
210211 group := value .(* GroupState )
211- metrics = append ( metrics , config.GenericMap {
212+ newEntry := config.GenericMap {
212213 "name" : aggregate .Definition .Name ,
213214 "operation" : aggregate .Definition .Operation ,
214215 "record_key" : aggregate .Definition .RecordKey ,
@@ -220,7 +221,12 @@ func (aggregate Aggregate) GetMetrics() []config.GenericMap {
220221 "recent_op_value" : group .recentOpValue ,
221222 "recent_count" : group .recentCount ,
222223 strings .Join (aggregate .Definition .By , "_" ): string (group .normalizedValues ),
223- })
224+ }
225+ // add the items in aggregate.Definition.By individually to the entry
226+ for _ , key := range aggregate .Definition .By {
227+ newEntry [key ] = group .labels [key ]
228+ }
229+ metrics = append (metrics , newEntry )
224230 // Once reported, we reset the recentXXX fields
225231 if aggregate .Definition .Operation == OperationRawValues {
226232 group .recentRawValues = make ([]float64 , 0 )
0 commit comments