FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add support for the comparison filters of Google Monitoring API by maxkuzkin · Pull Request #2234 · googleapis/google-cloud-python · GitHub

Add support for the comparison filters of Google Monitoring API - #2234

Merged
rimey merged 4 commits into
googleapis:masterfrom
maxkuzkin:master
Sep 2, 2016
Merged

Add support for the comparison filters of Google Monitoring API#2234
rimey merged 4 commits into
googleapis:masterfrom
maxkuzkin:master

Conversation

Copy link
Copy Markdown
Contributor

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:

  1. ’{key}_greater:{value}' -> '{key} > {value}'
  2. ’{key}_greaterequal:{value}' -> '{key} >= {value}'
  3. ’{key}_less:{value}' -> '{key} < {value}'
  4. ’{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.

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.
googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 1, 2016
Fixed `tox -e cover` to have 100% coverage after proposed patch

rimey commented Sep 2, 2016

Copy link
Copy Markdown
Contributor

I would suggest inserting something like the following in the docstring for select_metrics at Line 315, immediately after the explanation of _prefix and _suffix. I don't think we need to say anything in the docstring for select_resources, because all of the currently defined monitored resource labels are strings.

        If the label's value type is ``INT64``, a similar notation can be
        used to express inequalities:

        ``<label>_less=<value>`` generates::

            metric.label.<label> < <value>

        ``<label>_lessequal=<value>`` generates::

            metric.label.<label> <= <value>

        ``<label>_greater=<value>`` generates::

            metric.label.<label> > <value>

        ``<label>_greaterequal=<value>`` generates::

            metric.label.<label> >= <value>

Comment thread 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.

rimey commented Sep 2, 2016

Copy link
Copy Markdown
Contributor

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…
:-)

Copy link
Copy Markdown
Contributor Author

Hi Ken, updated PR now has improvements you've suggested.

rimey commented Sep 2, 2016

Copy link
Copy Markdown
Contributor

LGTM

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL