Skip to content

Commit

Permalink
Fix: gauge regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
idrissneumann committed Nov 1, 2024
1 parent 83aa492 commit 837196f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.6
4.0.7
48 changes: 48 additions & 0 deletions src/tests/test_gauge.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions src/tests/test_manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from unittest import TestCase
from utils.manifests import get_manifest_as_dict

Expand Down
2 changes: 1 addition & 1 deletion src/utils/gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 837196f

Please sign in to comment.