Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Jan 27, 2025
1 parent d49f4d0 commit 0967f6d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 43 deletions.
74 changes: 32 additions & 42 deletions backend/app/api/v1/commons/telco.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ async def getData(
filter: str,
configpath: str,
):
test_types = [
"oslat",
"cyclictest",
"cpu_util",
"deployment",
"ptp",
"reboot",
"rfc-2544",
]
cfg = config.get_config()
try:
jenkins_url = cfg.get("telco.config.job_url")
Expand All @@ -45,18 +36,7 @@ async def getData(
"latest_time": "{}T23:59:59".format(end_datetime.strftime("%Y-%m-%d")),
"output_mode": "json",
}
test_type_filter = " OR ".join(
['test_type="{}"'.format(test_type) for test_type in test_types]
)

searchList = test_type_filter
if filter:
filter_dict = utils.get_dict_from_qs(filter)
searchQuery = utils.construct_query(filter_dict)
if "benchmark" in filter_dict:
searchList = searchQuery
else:
searchList = searchQuery + " " + test_type_filter
searchList = constructFilterQuery(filter)

splunk = SplunkService(configpath=configpath)
response = await splunk.query(
Expand Down Expand Up @@ -104,21 +84,13 @@ async def getData(

jobs = pd.json_normalize(mapped_list)

return {"data": jobs, "total": response["total"]}
return {"data": jobs, "total": response["total"] if response else 0}


async def getFilterData(
start_datetime: date, end_datetime: date, filter: str, configpath: str
):
test_types = [
"oslat",
"cyclictest",
"cpu_util",
"deployment",
"ptp",
"reboot",
"rfc-2544",
]

cfg = config.get_config()
try:
jenkins_url = cfg.get("telco.config.job_url")
Expand All @@ -130,17 +102,7 @@ async def getFilterData(
"latest_time": "{}T23:59:59".format(end_datetime.strftime("%Y-%m-%d")),
"output_mode": "json",
}
test_type_filter = " OR ".join(
['test_type="{}"'.format(test_type) for test_type in test_types]
)
searchList = test_type_filter
if filter:
filter_dict = utils.get_dict_from_qs(filter)
searchQuery = utils.construct_query(filter_dict)
if "benchmark" in filter_dict:
searchList = searchQuery
else:
searchList = searchQuery + " " + test_type_filter
searchList = constructFilterQuery(filter)

splunk = SplunkService(configpath=configpath)
response = await splunk.filterPost(query=query, searchList=searchList)
Expand Down Expand Up @@ -181,3 +143,31 @@ async def getFilterData(
{"key": "jobStatus", "value": ["success", "failure"], "name": "Status"}
)
return {"data": filterData, "total": response["total"]}


def constructFilterQuery(filter):
test_types = [
"oslat",
"cyclictest",
"cpu_util",
"deployment",
"ptp",
"reboot",
"rfc-2544",
]
test_type_filter = " OR ".join(
f'test_type="{test_type}"' for test_type in test_types
)
search_list = test_type_filter

if filter:
filter_dict = utils.get_dict_from_qs(filter)
search_query = utils.construct_query(filter_dict)

# Update `search_list` based on the presence of "benchmark" in `filter_dict`
search_list = (
search_query
if "benchmark" in filter_dict
else f"{search_query} {test_type_filter}"
)
return search_list
2 changes: 1 addition & 1 deletion backend/app/api/v1/commons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def construct_query(filter_dict):
for key, values in filter_dict.items():
k = constants.FIELDS_FILTER_DICT[key]
if len(values) > 1:
or_clause = " or ".join([f'{k}="{value}"' for value in values])
or_clause = " OR ".join([f'{k}="{value}"' for value in values])
query_parts.append(f"{or_clause}")
else:
query_parts.append(f'{k}="{values[0]}"')
Expand Down

0 comments on commit 0967f6d

Please sign in to comment.