From 07d3245b2c86ad73f6690bf1288578133732ac7e Mon Sep 17 00:00:00 2001 From: MVarshini Date: Mon, 7 Oct 2024 17:13:54 +0530 Subject: [PATCH] code cleanup --- backend/app/api/v1/commons/ocp.py | 8 ++------ backend/app/services/search.py | 20 +++---------------- frontend/src/actions/ocpActions.js | 6 +++--- .../components/organisms/MetricsTab/index.jsx | 10 +++++----- 4 files changed, 13 insertions(+), 31 deletions(-) diff --git a/backend/app/api/v1/commons/ocp.py b/backend/app/api/v1/commons/ocp.py index 942308ab..f77e20ef 100644 --- a/backend/app/api/v1/commons/ocp.py +++ b/backend/app/api/v1/commons/ocp.py @@ -7,7 +7,6 @@ def buildFilterQuery(filter: dict, query: dict): minimum_match = 0 filter_dict = json.loads(filter) - print("filter") if bool(filter_dict): for key,val in filter_dict.items(): if key == "workerNodesCount": @@ -35,11 +34,9 @@ def buildFilterQuery(filter: dict, query: dict): queryObj = getMatchPhrase(key, item) query["query"]["bool"]["should"].append(queryObj) minimum_match+=1 - print(len(query["query"]["bool"]["should"])) - print("my match") if len(query["query"]["bool"]["should"]) >= 1: query["query"]["bool"].update({"minimum_should_match": minimum_match}) - print(query) + return query def buildAggregateQuery(): @@ -158,8 +155,7 @@ async def getFilterData(start_datetime: date, end_datetime: date, size:int, offs values=[] if x == "buckets": buck = v[x] - if k == "jobStatus": - print(buck) + if k == "jobStatus": metrics.update(getSummary(buck, isFilterReset)) for m in buck: if k == "ocpVersion": diff --git a/backend/app/services/search.py b/backend/app/services/search.py index 96803bcb..b0972e66 100644 --- a/backend/app/services/search.py +++ b/backend/app/services/search.py @@ -47,8 +47,6 @@ def initialize_es(self, config, path, index): async def post(self, query, indice=None, size=None, offset=None, start_date=None, end_date=None, timestamp_field=None): try: """Runs a query and returns the results""" - print("end date") - print(end_date) """Handles queries that require data from ES docs""" if timestamp_field: """Handles queries that have a timestamp field. Queries from both new and archive instances""" @@ -75,7 +73,6 @@ async def post(self, query, indice=None, size=None, offset=None, start_date=None body=jsonable_encoder(query), size=size) previous_results = {"data":response['hits']['hits'], "total":response['hits']["total"]["value"]} - print("sollamaten po") # previous_results = await self.scan_indices(self.prev_es, self.prev_index, query, timestamp_field, start_date, new_end_date, size, offset) if self.prev_es and self.new_es: self.new_index = self.new_index_prefix + (self.new_index if indice is None else indice) @@ -87,19 +84,15 @@ async def post(self, query, indice=None, size=None, offset=None, start_date=None new_start_date = max(start_date, seven_days_ago) if start_date else seven_days_ago new_results = {} query['query']['bool']['filter'][0]['range'][timestamp_field]['gte'] = str(new_start_date) - if end_date: - print(end_date) + if end_date: query['query']['bool']['filter'][0]['range'][timestamp_field]['lte'] = str(end_date) if end_date is None: - print("why no end_date") response = await self.new_es.search( index=self.new_index+"*", body=jsonable_encoder(query), size=size) new_results = {"data":response['hits']['hits'],"total":response['hits']['total']['value']} - else: - print("hydrogen") - print(query) + else: response = await self.new_es.search( index=self.new_index+"*", body=jsonable_encoder(query), @@ -230,19 +223,12 @@ async def filterPost(self, query, indice=None): try: if self.prev_es: self.prev_index = self.prev_index_prefix + (self.prev_index if indice is None else indice) - print("prev") - print(query) - print(self.prev_index+"*") response = await self.prev_es.search( index=self.prev_index+"*", body=query, size=0) - print(response) - print(response["hits"]["total"]["value"]) elif self.new_es: - self.new_index = self.new_index_prefix + (self.new_index if indice is None else indice) - print("new") - print(self.new_index) + self.new_index = self.new_index_prefix + (self.new_index if indice is None else indice) response = await self.new_es.search( index=self.new_index+"*", body=jsonable_encoder(query), diff --git a/frontend/src/actions/ocpActions.js b/frontend/src/actions/ocpActions.js index 9cfe0ec7..159c8e69 100644 --- a/frontend/src/actions/ocpActions.js +++ b/frontend/src/actions/ocpActions.js @@ -224,10 +224,10 @@ export const setOCPOtherSummaryFilter = () => (dispatch, getState) => { export const getOCPSummary = (summary) => (dispatch) => { const countObj = { - successCount: summary["success"], - failureCount: summary["failure"], + successCount: summary["success"] ?? 0, + failureCount: summary["failure"] ?? 0, othersCount: 0, - total: summary["total"], + total: summary["total"] ?? 0, }; for (const key in summary) { if (key !== "total" && key !== "success" && key !== "failure") { diff --git a/frontend/src/components/organisms/MetricsTab/index.jsx b/frontend/src/components/organisms/MetricsTab/index.jsx index a4712b3a..5c4aa3bf 100644 --- a/frontend/src/components/organisms/MetricsTab/index.jsx +++ b/frontend/src/components/organisms/MetricsTab/index.jsx @@ -46,10 +46,10 @@ const MetricsTab = (props) => { props.updateSelectedFilter("jobStatus", value, true); setAppliedFilters(props.navigation, props.type); }; - const applyOtherFilter = () => { - removeStatusFilter(); - setOtherSummaryFilter(props.type); - }; + // const applyOtherFilter = () => { + // removeStatusFilter(); + // setOtherSummaryFilter(props.type); + // }; return ( @@ -84,7 +84,7 @@ const MetricsTab = (props) => {