ferruzzi commented on code in PR #30873: URL: https://github.com/apache/airflow/pull/30873#discussion_r1181873135
########## tests/core/test_otel_logger.py: ########## @@ -0,0 +1,156 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from unittest import mock + +import pytest +from opentelemetry.metrics import MeterProvider + +from airflow.metrics.otel_logger import ( + METRIC_NAME_PREFIX, + OTEL_NAME_MAX_LENGTH, + UP_DOWN_COUNTERS, + SafeOtelLogger, + _is_up_down_counter, +) + + +def full_name(name: str): + return f"{METRIC_NAME_PREFIX}{name}" + + [email protected] +def name(): + return "test_stats_run" + + +class TestOtelMetrics: + def setup_method(self): + self.meter = mock.Mock(MeterProvider) + self.stats = SafeOtelLogger(otel_provider=self.meter) + self.map = self.stats.metrics_map.map + + def test_is_up_down_counter_positive(self): + udc = next(iter(UP_DOWN_COUNTERS)) + + assert _is_up_down_counter(udc) + + def test_is_up_down_counter_negative(self): + assert not _is_up_down_counter("this_is_not_a_udc") + + def test_stat_name_must_be_a_string(self): + self.stats.incr(42) Review Comment: Thinking on this more, SHOULD they? Do we really want Airflow blowing up because someone implemented a metric with a bad name? Maybe this should be logged as a warning? I'll add a more thorough name screening/validation, but maybe an exception isn't the right failure behavior here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
