@@ -63,10 +63,13 @@ def get_instrument_specs(
63
63
be used in.
64
64
"""
65
65
specs = {}
66
+
67
+ def get_spec_fn (metric_config : metric_configuration_pb2 .MetricConfig ):
68
+ return _get_instrument_spec (metric_config , config .context_labels_from_input )
66
69
specs [MetricContext .INPUT ] = tuple (
67
- map (_get_instrument_spec , config .input_metrics ))
70
+ map (get_spec_fn , config .input_metrics ))
68
71
specs [MetricContext .OUTPUT ] = tuple (
69
- map (_get_instrument_spec , config .output_metrics ))
72
+ map (get_spec_fn , config .output_metrics ))
70
73
return specs
71
74
72
75
@@ -88,12 +91,15 @@ def get_metric_instances(
88
91
"""
89
92
configs : tuple [metric_configuration_pb2 .MetricConfig , ...]
90
93
filter_str : str
94
+ ctx_labels_for_spec : tuple [metric_configuration_pb2 .LabelConfig , ...]
91
95
if context == MetricContext .INPUT :
92
96
configs = tuple (config .input_metrics )
93
97
filter_str = _format_filter (config .input_content_filter )
98
+ ctx_labels_for_spec = config .context_labels_from_input
94
99
elif context == MetricContext .OUTPUT :
95
100
configs = tuple (config .output_metrics )
96
101
filter_str = _format_filter (config .output_content_filter )
102
+ ctx_labels_for_spec = config .context_labels_from_input
97
103
else :
98
104
return {}
99
105
@@ -106,7 +112,7 @@ def get_metric_instances(
106
112
for filtered_payload in filtered_values :
107
113
values = _get_metric_values (metric_config , filtered_payload )
108
114
labels = _get_metric_labels (metric_config , filtered_payload )
109
- spec = _get_instrument_spec (metric_config )
115
+ spec = _get_instrument_spec (metric_config , ctx_labels_for_spec )
110
116
if spec in outputs :
111
117
outputs [spec ].append (MetricInstance (values , labels ))
112
118
else :
@@ -159,10 +165,13 @@ def _format_filter(filter_str: str) -> str:
159
165
160
166
def _get_instrument_spec (
161
167
config : metric_configuration_pb2 .MetricConfig ,
168
+ context_labels : tuple [metric_configuration_pb2 .LabelConfig , ...] = ()
162
169
) -> MetricInstrumentSpec :
163
170
instrument_type = _get_instrument_type (config )
164
171
metric_value_type = _get_metric_value_type (config )
165
- label_names = _get_metric_label_keys_no_payload (config )
172
+ label_names = _get_metric_label_keys_no_payload (
173
+ config ) + _label_keys_no_payload (context_labels )
174
+
166
175
return MetricInstrumentSpec (
167
176
instrumentType = instrument_type ,
168
177
metricValueType = metric_value_type ,
@@ -229,9 +238,15 @@ def _get_metric_labels(
229
238
230
239
def _get_metric_label_keys_no_payload (
231
240
config : metric_configuration_pb2 .MetricConfig
241
+ ) -> tuple [str , ...]:
242
+ return _label_keys_no_payload (config .labels )
243
+
244
+
245
+ def _label_keys_no_payload (
246
+ configs : tuple [metric_configuration_pb2 .LabelConfig , ...]
232
247
) -> tuple [str , ...]:
233
248
label_keys : list [str ] = []
234
- for label_config in config . labels :
249
+ for label_config in configs :
235
250
key = _extract_values (label_config .label_key , {})
236
251
label_keys .extend (key )
237
252
return tuple (label_keys )
0 commit comments