Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit ab5dddd

Browse files
committed
feat(monitoring): Add "not equal" support to the query filter
1 parent 80ec64d commit ab5dddd

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

google/cloud/monitoring_v3/query.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,14 @@ def select_metrics(self, *args, **kwargs):
273273
274274
metric.label.<label> = "<value>"
275275
276-
However, by adding ``"_prefix"`` or ``"_suffix"`` to the keyword,
277-
you can specify a partial match.
276+
However, by adding ``"_notequal"`` to the keyword, you can inequality:
277+
278+
``<label>_notequal=<value>`` generates::
279+
280+
metric.label.<label> != <value>
281+
282+
By adding ``"_prefix"`` or ``"_suffix"`` to the keyword, you can specify
283+
a partial match.
278284
279285
``<label>_prefix=<value>`` generates::
280286
@@ -596,7 +602,7 @@ def _build_label_filter(category, *args, **kwargs):
596602

597603
suffix = None
598604
if key.endswith(
599-
("_prefix", "_suffix", "_greater", "_greaterequal", "_less", "_lessequal")
605+
("_prefix", "_suffix", "_greater", "_greaterequal", "_less", "_lessequal", "_notequal")
600606
):
601607
key, suffix = key.rsplit("_", 1)
602608

@@ -617,6 +623,8 @@ def _build_label_filter(category, *args, **kwargs):
617623
term = "{key} < {value}"
618624
elif suffix == "lessequal":
619625
term = "{key} <= {value}"
626+
elif suffix == "notequal":
627+
term = "{key} != {value}"
620628
else:
621629
term = '{key} = "{value}"'
622630

tests/unit/test_query.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,15 @@ def test_metric_labels(self):
517517
)
518518
self.assertEqual(actual, expected)
519519

520+
def test_metric_label_response_code_not_equal(self):
521+
actual = self._call_fut(
522+
"metric", response_code_notequal=200
523+
)
524+
expected = (
525+
"metric.label.response_code != 200"
526+
)
527+
self.assertEqual(actual, expected)
528+
520529
def test_metric_label_response_code_greater_less(self):
521530
actual = self._call_fut(
522531
"metric", response_code_greater=500, response_code_less=600

0 commit comments

Comments
 (0)