Skip to content

Commit

Permalink
support not regexp filter (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexdene authored May 6, 2024
1 parent abfdddd commit de7723e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pangolier/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def to_str(self, pretty: bool = False) -> str:
return '=~"%s"' % self.expression


class NotRegexpFilter(FilterBase):
def to_str(self, pretty: bool = False) -> str:
return '!~"%s"' % self.expression


FilterValueType = Union[str, FilterBase]
FilterTuple = tuple[str, FilterBase]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='pangolier',
version='0.2.2',
version='0.2.3',
packages=find_packages(include=['pangolier']),
package_data={
'pangolier': ['py.typed'],
Expand Down
10 changes: 9 additions & 1 deletion tests/test_filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase

from pangolier.metrics import Metric
from pangolier.filters import NotEqualFilter, RegexpFilter
from pangolier.filters import NotEqualFilter, RegexpFilter, NotRegexpFilter


class TestFilter(TestCase):
Expand Down Expand Up @@ -59,3 +59,11 @@ def test_not_equal_filter(self) -> None:
).to_str(),
'http_requests_total{job!=""}'
)

def test_not_regexp_filter(self) -> None:
self.assertEqual(
Metric('http_requests_total').filter(
job=NotRegexpFilter('prometheus-.*'),
).to_str(),
'http_requests_total{job!~"prometheus-.*"}'
)

0 comments on commit de7723e

Please sign in to comment.