@@ -174,24 +174,30 @@ def __call__(self, environ, start_response):
174
174
environ ['WATCHER.ACTION' ] = cadf_action
175
175
environ ['WATCHER.SERVICE_TYPE' ] = self .service_type
176
176
177
+ # labels applied to all metrics emitted by this middleware
177
178
labels = [
178
179
"service_name:{0}" .format (self .strategy .get_cadf_service_name ()),
179
180
"service:{0}" .format (self .service_type ),
180
181
"action:{0}" .format (cadf_action ),
182
+ "target_type_uri:{0}" .format (target_type_uri ),
183
+ ]
184
+
185
+ # additional labels not needed in all metrics
186
+ detail_labels = [
181
187
"initiator_project_id:{0}" .format (initiator_project_id ),
182
188
"initiator_domain_id:{0}" .format (initiator_domain_id ),
183
- "target_type_uri:{0}" .format (target_type_uri ),
184
189
]
190
+ detail_labels = labels + detail_labels
185
191
186
192
# include the target project id in metric
187
193
if self .is_include_target_project_id_in_metric :
188
- labels .append (
194
+ detail_labels .append (
189
195
"target_project_id:{0}" .format (target_project_id )
190
196
)
191
197
192
198
# include initiator user id
193
199
if self .is_include_initiator_user_id_in_metric :
194
- labels .append (
200
+ detail_labels .append (
195
201
"initiator_user_id:{0}" .format (initiator_user_id )
196
202
)
197
203
@@ -230,7 +236,7 @@ def _start_response_wrapper(status, headers, exc_info=None):
230
236
labels .append ("status:{0}" .format (status_code ))
231
237
232
238
self .metric_client .timing ('api_requests_duration_seconds' , time .time () - start , tags = labels )
233
- self .metric_client .increment ('api_requests_total' , tags = labels )
239
+ self .metric_client .increment ('api_requests_total' , tags = detail_labels )
234
240
except Exception as e :
235
241
self .logger .debug ("failed to submit metrics for %s: %s" % (str (labels ), str (e )))
236
242
finally :
0 commit comments