Open racinmat opened 1 month ago
Here is my fix for that, but I failed to make the tests run on Windows:
from google.cloud import monitoring_v3
from datetime import datetime, timedelta
from google.cloud.monitoring_v3.query import Query
from google.cloud.monitoring_v3.types import Aggregation
from google.cloud.monitoring_v3 import query
import pandas as pd
# I could make a PR, but running the tests there is pain
def fixed_build_label_filter(category, *args, **kwargs):
"""Construct a filter string to filter on metric or resource labels."""
terms = list(args)
for key, value in kwargs.items():
if value is None:
continue
suffix = None
if key.endswith(
(
"_prefix",
"_suffix",
"_greater",
"_greaterequal",
"_less",
"_lessequal",
"_notequal",
"_regex",
)
):
key, suffix = key.rsplit("_", 1)
if category == "resource" and key == "resource_type":
key = "resource.type"
else:
key = ".".join((category, "label", key))
if suffix == "prefix":
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}"
elif suffix == "notequal":
term = "{key} != {value}"
elif suffix == "regex":
term = '{key} = monitoring.regex.full_match("{value}")'
else:
term = '{key} = "{value}"'
terms.append(term.format(key=key, value=value))
return " AND ".join(sorted(terms))
query._build_label_filter = fixed_build_label_filter
The
google-cloud-monitoring
does not supportmonitoring.regex.full_match
. See https://github.com/googleapis/google-cloud-python/blob/main/packages/google-cloud-monitoring/google/cloud/monitoring_v3/query.py#L622-L637 I need to have a way to passkey=value
without escaping to fully use the functionality, e.g. themonitoring.regex.full_match
. Now, when I call e.g.I get an error, because the filter built from the params is like this:
but I need