diff --git a/tests/unit/serve/instrumentation/conftest.py b/tests/unit/serve/instrumentation/conftest.py index 77bff13945578..ad66789e2aeed 100644 --- a/tests/unit/serve/instrumentation/conftest.py +++ b/tests/unit/serve/instrumentation/conftest.py @@ -27,6 +27,7 @@ def __init__( type, "opentelemetry.sdk.metrics.view.Aggregation" ] = None, ): + print(f'JOAN IS HERE DIRMETRIC') super().__init__( preferred_temporality=preferred_temporality, preferred_aggregation=preferred_aggregation, @@ -40,6 +41,7 @@ def export( timeout_millis: float = 10_000, **kwargs, ) -> MetricExportResult: + print(f'export to {self.metric_filename} => {metrics_data.to_json()[0:3]}') self.f.write(metrics_data.to_json()) self.f.write('\n') self.f.flush() @@ -75,6 +77,7 @@ def monkeypatch_metric_exporter( f.write('0') def collect_metrics(): + print(f'tick_counter_filename {tick_counter_filename}') with open(tick_counter_filename, 'r', encoding='utf-8') as ft: tick_counter = int(ft.read()) with open(tick_counter_filename, 'w', encoding='utf-8') as ft2: @@ -88,15 +91,20 @@ def _get_service_name(otel_measurement): def read_metrics(): def read_metric_file(filename): + print(f'filename {filename}') with open(filename, 'r', encoding='utf-8') as fr: r = fr.read() - print(f'READ {r}') - return json.loads(r) - - return { - _get_service_name(i): i - for i in map(read_metric_file, metrics_path.glob('*')) - } + print(f'READ {r[0:3]}') + try: + return json.loads(r) + except: + return None + + ret = {} + for i in map(read_metric_file, metrics_path.glob('*')): + if i is not None: + ret[_get_service_name(i)] = i + return ret class PatchedTextReader(PeriodicExportingMetricReader): def __init__(self, *args, **kwargs) -> None: diff --git a/tests/unit/serve/instrumentation/test_gateway_metric_labels.py b/tests/unit/serve/instrumentation/test_gateway_metric_labels.py index 2d8eb08f0ff2d..757d2d9e41756 100644 --- a/tests/unit/serve/instrumentation/test_gateway_metric_labels.py +++ b/tests/unit/serve/instrumentation/test_gateway_metric_labels.py @@ -26,7 +26,6 @@ def meow(self, docs, **kwargs): f.post('/') collect_metrics() metrics = read_metrics() - print(f' metrics {metrics.keys()}') gateway_metrics = metrics['gateway/rep-0']['resource_metrics'][0][ 'scope_metrics' ][0]['metrics'] diff --git a/tests/unit/serve/instrumentation/test_instrumentation.py b/tests/unit/serve/instrumentation/test_instrumentation.py index c1d1d8228cba8..d83dd0d65c559 100644 --- a/tests/unit/serve/instrumentation/test_instrumentation.py +++ b/tests/unit/serve/instrumentation/test_instrumentation.py @@ -88,10 +88,10 @@ def _sleep(): } @MetricsTimer(summary, histogram, labels) - def _sleep(): + def _sleep_2(): time.sleep(0.1) - _sleep() + _sleep_2() # Prometheus samples summary_count_sample = [ @@ -107,5 +107,5 @@ def _sleep(): .to_json() ) assert 'time_taken_decorator' == histogram_metric['name'] - assert 1 == histogram_metric['data']['data_points'][0]['count'] - assert labels == histogram_metric['data']['data_points'][0]['attributes'] + assert 1 == histogram_metric['data']['data_points'][1]['count'] + assert labels == histogram_metric['data']['data_points'][1]['attributes']