Skip to content

Commit

Permalink
Merge pull request #27 from shashank-boyapally/lookback-size
Browse files Browse the repository at this point in the history
lookback size
  • Loading branch information
shashank-boyapally authored Sep 9, 2024
2 parents 69145e4 + 75270b0 commit 582069a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
42 changes: 33 additions & 9 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,9 +67,29 @@ 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"""
"""gets uuid by metadata
Args:
meta (Dict[str, Any]): metadata of the runs
index (str, optional): Index to search. Defaults to None.
lookback_date (datetime, optional):
The cutoff date to get the uuids from. Defaults to None.
lookback_size (int, optional):
Maximum number of runs to get, gets the latest. Defaults to 10000.
lookback_size and lookback_date get the data on the
precedency of whichever cutoff comes first.
Similar to a car manufacturer's warranty limits.
Returns:
List[Dict[str, str]]: _description_
"""
if index is None:
index = self.index
version = meta["ocpVersion"][:4]
Expand Down Expand Up @@ -98,7 +117,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 582069a

Please sign in to comment.