From 837196f12a0d616cb980d78ae288c84adc10c253 Mon Sep 17 00:00:00 2001 From: Idriss Neumann Date: Fri, 1 Nov 2024 11:37:33 +0100 Subject: [PATCH] Fix: gauge regexp --- VERSION | 2 +- src/tests/test_gauge.py | 48 ++++++++++++++++++++++++++++++++++++++ src/tests/test_manifest.py | 2 ++ src/utils/gauge.py | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/tests/test_gauge.py diff --git a/VERSION b/VERSION index d13e837..43beb40 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.6 +4.0.7 diff --git a/src/tests/test_gauge.py b/src/tests/test_gauge.py new file mode 100644 index 0000000..7ea4c80 --- /dev/null +++ b/src/tests/test_gauge.py @@ -0,0 +1,48 @@ +import re + +from unittest import TestCase +from utils.gauge import _numeric_value_pattern + +class TestGauge(TestCase): + def init(self, *args, **kwargs): + super(TestGauge, self).__init__(*args, **kwargs) + + def test_gauge_regexp_integer(self): + ## Given + value = 1 + + #When + result = re.search(_numeric_value_pattern, "{}".format(value)) + + ## Then + self.assertTrue(result) + + def test_gauge_regexp_float(self): + ## Given + value = 1.1 + + #When + result = re.search(_numeric_value_pattern, "{}".format(value)) + + ## Then + self.assertTrue(result) + + def test_gauge_regexp_float2(self): + ## Given + value = 1.15 + + #When + result = re.search(_numeric_value_pattern, "{}".format(value)) + + ## Then + self.assertTrue(result) + + def test_gauge_regexp_string(self): + ## Given + value = "yo" + + #When + result = re.search(_numeric_value_pattern, "{}".format(value)) + + ## Then + self.assertFalse(result) diff --git a/src/tests/test_manifest.py b/src/tests/test_manifest.py index 11e42fd..12c8b89 100644 --- a/src/tests/test_manifest.py +++ b/src/tests/test_manifest.py @@ -1,3 +1,5 @@ +import re + from unittest import TestCase from utils.manifests import get_manifest_as_dict diff --git a/src/utils/gauge.py b/src/utils/gauge.py index fde1e9e..68f3d83 100644 --- a/src/utils/gauge.py +++ b/src/utils/gauge.py @@ -6,7 +6,7 @@ from utils.common import sanitize_metric_name from utils.otel import get_otel_meter -_numeric_value_pattern = r"-?\d+\.\d+" +_numeric_value_pattern = r"-?\d+\.?\d*" _current_gauge_values = {} def create_gauge(name, description):