@@ -49,9 +49,26 @@ def __init__(self, app, config, logger=logging.getLogger(__name__)):
49
49
self .cadf_service_name = self .wsgi_config .get ('cadf_service_name' , None )
50
50
self .service_type = self .wsgi_config .get ('service_type' , taxonomy .UNKNOWN )
51
51
# get the project uid from the request path or from the token (default)
52
- self .is_project_id_from_path = common .string_to_bool (self .wsgi_config .get ('target_project_id_from_path' , 'False' ))
52
+ self .is_project_id_from_path = common .string_to_bool (
53
+ self .wsgi_config .get ('target_project_id_from_path' , 'False' )
54
+ )
55
+ # get the project id from the service catalog (see documentation on keystone auth_token middleware)
53
56
self .is_project_id_from_service_catalog = common .string_to_bool (
54
- self .wsgi_config .get ('target_project_id_from_service_catalog' , 'False' ))
57
+ self .wsgi_config .get ('target_project_id_from_service_catalog' , 'False' )
58
+ )
59
+
60
+ # whether to include the target project id in the metrics
61
+ self .is_include_target_project_id_in_metric = common .string_to_bool (
62
+ self .wsgi_config .get ('include_target_project_id_in_metric' , 'True' )
63
+ )
64
+ # whether to include the target domain id in the metrics
65
+ self .is_include_target_domain_id_in_metric = common .string_to_bool (
66
+ self .wsgi_config .get ('include_target_domain_id_in_metric' , 'True' )
67
+ )
68
+ # whether to include the initiator user id for authentication request in the metrics
69
+ self .is_include_authentication_initiator_user_id_in_metric = common .string_to_bool (
70
+ self .wsgi_config .get ('include_authentication_initiator_user_id_in_metric' , 'True' )
71
+ )
55
72
56
73
config_file_path = config .get ('config_file' , None )
57
74
if config_file_path :
@@ -163,10 +180,21 @@ def __call__(self, environ, start_response):
163
180
"action:{0}" .format (cadf_action ),
164
181
"initiator_project_id:{0}" .format (initiator_project_id ),
165
182
"initiator_domain_id:{0}" .format (initiator_domain_id ),
166
- "target_project_id:{0}" .format (target_project_id ),
167
183
"target_type_uri:{0}" .format (target_type_uri ),
168
184
]
169
185
186
+ # include the target project id in metric
187
+ if self .is_include_target_project_id_in_metric :
188
+ labels .append (
189
+ "target_project_id:{0}" .format (target_project_id )
190
+ )
191
+
192
+ # if authentication request: include initiator user id
193
+ if cadf_action == taxonomy .ACTION_AUTHENTICATE and self .is_include_authentication_initiator_user_id_in_metric :
194
+ labels .append (
195
+ "initiator_user_id:{0}" .format (initiator_user_id )
196
+ )
197
+
170
198
# if swift request: determine target.container_id based on request path
171
199
if common .is_swift_request (req .path ) or self .service_type == 'object-store' :
172
200
_ , target_container_id = self .get_target_account_container_id_from_request (req )
@@ -330,7 +358,7 @@ def get_project_domain_and_user_id_from_keystone_authentication_request(self, re
330
358
"""
331
359
project_id = domain_id = user_id = taxonomy .UNKNOWN
332
360
try :
333
- if not req .json_body :
361
+ if not req .json :
334
362
return
335
363
336
364
json_body_dict = common .load_json_dict (req .json )
0 commit comments