Skip to content

Commit

Permalink
lookback size
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Reddy Boyapally <[email protected]>
  • Loading branch information
shashank-boyapally committed Aug 19, 2024
1 parent 69145e4 commit 81423f6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
24 changes: 16 additions & 8 deletions fmatch/matcher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" metadata matcher
"""
"""metadata matcher"""

# pylint: disable = invalid-name, invalid-unary-operand-type, no-member
import os
Expand All @@ -23,10 +22,10 @@ class Matcher:

def __init__(
self,
index: str ="ospst-perf-scale-ci",
level: int =logging.INFO,
ES_URL: str =os.getenv("ES_SERVER"),
verify_certs: bool =True,
index: str = "ospst-perf-scale-ci",
level: int = logging.INFO,
ES_URL: str = os.getenv("ES_SERVER"),
verify_certs: bool = True,
):
self.index = index
self.es_url = ES_URL
Expand Down Expand Up @@ -68,7 +67,11 @@ def query_index(self, index: str, search: Search) -> Response:
return search.execute()

def get_uuid_by_metadata(
self, meta: Dict[str, Any], index: str = None, lookback_date: datetime = None
self,
meta: Dict[str, Any],
index: str = None,
lookback_date: datetime = None,
lookback_size: int = 10000,
) -> List[Dict[str, str]]:
"""get_uuid_by_metadata"""
if index is None:
Expand Down Expand Up @@ -98,7 +101,12 @@ def get_uuid_by_metadata(
must=must_clause,
filter=filter_clause,
)
s = Search(using=self.es, index=index).query(query).extra(size=self.search_size)
s = (
Search(using=self.es, index=index)
.query(query)
.sort({"timestamp": {"order": "desc"}})
.extra(size=lookback_size)
)
result = self.query_index(index, s)
hits = result.hits.hits
uuids_docs = [
Expand Down
24 changes: 24 additions & 0 deletions fmatch/tests/test_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ def test_get_uuid_by_metadata_lookback(matcher_instance):
"buildUrl":"buildUrl1"}]
assert result == expected

def test_get_uuid_by_metadata_lookback_size(matcher_instance):
matcher_instance.es.search = lambda *args, **kwargs: {
"hits": {
"hits": [{"_source": {"uuid": "uuid1",
"buildUrl":"buildUrl1",
"timestamp":"2024-07-10T13:46:24Z"}},
{"_source": {"uuid": "uuid2",
"buildUrl":"buildUrl1",
"timestamp":"2024-07-08T13:46:24Z"}}]
}
}
meta = {
"field1": "value1",
"ocpVersion": "4.15",
}
date= datetime.datetime.strptime("2024-07-07T13:46:24Z","%Y-%m-%dT%H:%M:%SZ")
result = matcher_instance.get_uuid_by_metadata(meta=meta, lookback_date=date, lookback_size=2)
print(result)
expected= [{"uuid": "uuid1",
"buildUrl":"buildUrl1"},
{"uuid": "uuid2",
"buildUrl":"buildUrl1"}]
assert result == expected


def test_match_kube_burner(matcher_instance):
result = matcher_instance.match_kube_burner(["uuid1"],index="ospst-*")
Expand Down

0 comments on commit 81423f6

Please sign in to comment.