Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion gcloud/monitoring/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,9 @@ def _build_label_filter(category, *args, **kwargs):
continue

suffix = None
if key.endswith('_prefix') or key.endswith('_suffix'):
ends = ['_prefix', '_suffix', '_greater', '_greaterequal',
'_less', '_lessequal']
if key.endswith(tuple(ends)):

This comment was marked as spam.

key, suffix = key.rsplit('_', 1)

if category == 'resource' and key == 'resource_type':
Expand All @@ -649,6 +651,14 @@ def _build_label_filter(category, *args, **kwargs):
term = '{key} = starts_with("{value}")'
elif suffix == 'suffix':
term = '{key} = ends_with("{value}")'
elif suffix == 'greater':
term = '{key} > {value}'
elif suffix == 'greaterequal':
term = '{key} >= {value}'
elif suffix == 'less':
term = '{key} < {value}'
elif suffix == 'lessequal':
term = '{key} <= {value}'
else:
term = '{key} = "{value}"'

Expand Down
22 changes: 22 additions & 0 deletions gcloud/monitoring/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,28 @@ def test_metric_labels(self):
)
self.assertEqual(actual, expected)

def test_metric_label_response_code_greater_less(self):
actual = self._callFUT(
'metric',
response_code_greater=500,
response_code_less=600)
expected = (
'metric.label.response_code < 600'
' AND metric.label.response_code > 500'
)
self.assertEqual(actual, expected)

def test_metric_label_response_code_greater_less_equal(self):
actual = self._callFUT(
'metric',
response_code_greaterequal=500,
response_code_lessequal=600)
expected = (
'metric.label.response_code <= 600'
' AND metric.label.response_code >= 500'
)
self.assertEqual(actual, expected)

def test_resource_labels(self):
actual = self._callFUT(
'resource',
Expand Down