From 0e6f6e7369d08966a66d36ef3cb2fce89c002e1f Mon Sep 17 00:00:00 2001 From: Shashank Reddy Boyapally Date: Mon, 19 Feb 2024 13:30:55 -0500 Subject: [PATCH] string and not list bug fix (#19) Signed-off-by: Shashank Reddy Boyapally --- fmatch/matcher.py | 14 ++++++-------- fmatch/test_fmatch.py | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/fmatch/matcher.py b/fmatch/matcher.py index 7711833..7928242 100644 --- a/fmatch/matcher.py +++ b/fmatch/matcher.py @@ -80,12 +80,10 @@ def get_uuid_by_metadata(self, meta, index=None): must=[ Q( "match", **{field: str(value)} - ) # if isinstance(value, str) else Q('terms', **{field: value}) + ) if isinstance(value, str) else Q('match', **{field: value}) for field, value in meta.items() - if field not in "ocpVersion benchmark" - ] - + ([Q("match", **{"benchmark.keyword": meta["benchmark"]})] - if "benchmark" in meta else []), + if field not in "ocpVersion" + ], filter=[ Q("wildcard", ocpVersion=f"{version}*"), Q("match", jobStatus="success"), @@ -155,10 +153,10 @@ def getResults(self, uuid: str, uuids: list, index_str: str, metrics: dict): metric_queries = [] not_queries = [ ~Q("match", **{not_item_key: not_item_value}) - for not_item_key, not_item_value in metrics["not"].items() + for not_item_key, not_item_value in metrics.get("not",{}).items() ] metric_queries = [ - Q("match", **{metric_key: f'"{metric_value}"'}) + Q("match", **{metric_key: metric_value}) for metric_key, metric_value in metrics.items() if metric_key not in ["name", "metric_of_interest", "not"] ] @@ -194,7 +192,7 @@ def get_agg_metric_query(self, uuids, index, metrics): for not_item_key, not_item_value in not_item.items() ] metric_queries = [ - Q("match", **{metric_key: f'"{metric_value}"'}) + Q("match", **{metric_key: metric_value}) for metric_key, metric_value in metrics.items() if metric_key not in ["name", "metric_of_interest", "not", "agg"] ] diff --git a/fmatch/test_fmatch.py b/fmatch/test_fmatch.py index 9cb42f4..a63437b 100644 --- a/fmatch/test_fmatch.py +++ b/fmatch/test_fmatch.py @@ -21,7 +21,7 @@ meta["jobStatus"] = "success" meta["ocpVersion"] = "4.15" meta["networkType"] = "OVNKubernetes" -meta["benchmark"] = "cluster-density-v2" +meta["benchmark.keyword"] = "cluster-density-v2" # meta['encrypted'] = "true" # meta['ipsec'] = "false" # meta['fips'] = "false" @@ -44,7 +44,7 @@ kapi_metrics = { "name": "apiserverCPU", "metricName": "containerCPU", - "labels.namespace": "openshift-kube-apiserver", + "labels.namespace.keyword": "openshift-kube-apiserver", "metric_of_interest": "value", "agg": {"value": "cpu", "agg_type": "avg"}, }