@@ -75,21 +75,22 @@ def _parse_key(key):
75
75
def _accumulate_metrics (metrics , accumulate ):
76
76
for metric in metrics .values ():
77
77
samples = defaultdict (float )
78
- buckets = {}
78
+ buckets = defaultdict (lambda : defaultdict (float ))
79
+ samples_setdefault = samples .setdefault
79
80
for s in metric .samples :
80
- name , labels , value = s . name , s . labels , s . value
81
+ name , labels , value , timestamp , exemplar = s
81
82
if metric .type == 'gauge' :
82
- without_pid = tuple (l for l in labels if l [0 ] != 'pid' )
83
+ without_pid_key = ( name , tuple (l for l in labels if l [0 ] != 'pid' ) )
83
84
if metric ._multiprocess_mode == 'min' :
84
- current = samples . setdefault (( name , without_pid ) , value )
85
+ current = samples_setdefault ( without_pid_key , value )
85
86
if value < current :
86
- samples [( s . name , without_pid ) ] = value
87
+ samples [without_pid_key ] = value
87
88
elif metric ._multiprocess_mode == 'max' :
88
- current = samples . setdefault (( name , without_pid ) , value )
89
+ current = samples_setdefault ( without_pid_key , value )
89
90
if value > current :
90
- samples [( s . name , without_pid ) ] = value
91
+ samples [without_pid_key ] = value
91
92
elif metric ._multiprocess_mode == 'livesum' :
92
- samples [( name , without_pid ) ] += value
93
+ samples [without_pid_key ] += value
93
94
else : # all/liveall
94
95
samples [(name , labels )] = value
95
96
@@ -98,16 +99,14 @@ def _accumulate_metrics(metrics, accumulate):
98
99
if bucket :
99
100
# _bucket
100
101
without_le = tuple (l for l in labels if l [0 ] != 'le' )
101
- buckets .setdefault (without_le , {})
102
- buckets [without_le ].setdefault (bucket [0 ], 0.0 )
103
102
buckets [without_le ][bucket [0 ]] += value
104
103
else :
105
104
# _sum/_count
106
- samples [(s . name , labels )] += value
105
+ samples [(name , labels )] += value
107
106
108
107
else :
109
108
# Counter and Summary.
110
- samples [(s . name , labels )] += value
109
+ samples [(name , labels )] += value
111
110
112
111
# Accumulate bucket values.
113
112
if metric .type == 'histogram' :
0 commit comments