-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add support for the comparison filters of Google Monitoring API #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Google Monitoring API filters support <,<=,>,>= operators as described in its documentation: https://cloud.google.com/monitoring/api/v3/filters. Current version of the library only has mappings of: 1. ’{key}_prefix:{value}' -> '{key} = starts_with("{value}")' 2. ’{key}_suffix:{value}' -> '{key} = ends_with("{value}")' This patch introduces additional mappings of: 3. ’{key}_greater:{value}' -> '{key} > {value}' 4. ’{key}_greaterequal:{value}' -> '{key} >= {value}' 5. ’{key}_less:{value}' -> '{key} < {value}' 6. ’{key}_lessequal:{value}' -> '{key} <= {value}' So that it is possible, for example, to filter based on the response_code values range, as shown below: metric.type = "appengine.googleapis.com/http/server/response_count" AND metric.label.response_code < 600 AND metric.label.response_code >= 500 This patch will allow to remove “hack” in the following tool: https://github.com/odin-public/gcpmetrics that enables queries to the monitoring api from the command line.
Fixed `tox -e cover` to have 100% coverage after proposed patch
|
I would suggest inserting something like the following in the docstring for |
gcloud/monitoring/query.py
Outdated
| 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.
This comment was marked as spam.
Sorry, something went wrong.
|
I made just a couple of comments. Thank you for the contribution! |
1. Added docstring for select_metrics with the explanation of additional endings. No reason to do the same for select_resources, because all of the currently defined monitored resource labels are strings. 2. Removed array->tuple conversion, moved constant directly into the if condition.
oops i did it again: messed docstring indentation while copy/pasting… :-)
|
Hi Ken, updated PR now has improvements you've suggested. |
|
LGTM |
PR googleapis/google-cloud-python#2234 was merged and functionality available since release 0.19.0
Google Monitoring API filters support <,<=,>,>= operators as described
in its documentation:
https://cloud.google.com/monitoring/api/v3/filters.
Current version of the library only has mappings of:
This patch introduces additional mappings of:
So that it is possible, for example, to filter based on the
response_code values range, as shown below:
metric.type = "appengine.googleapis.com/http/server/response_count"
AND metric.label.response_code < 600
AND metric.label.response_code >= 500
This patch will allow to remove “hack” in the following tool:
https://github.com/odin-public/gcpmetrics that enables
queries to the monitoring api from the command line.