Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Oct 7, 2024
1 parent fd6055e commit 07d3245
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
8 changes: 2 additions & 6 deletions backend/app/api/v1/commons/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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":
Expand Down
20 changes: 3 additions & 17 deletions backend/app/services/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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)
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/actions/ocpActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/organisms/MetricsTab/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Accordion togglePosition="start">
<AccordionItem>
Expand Down Expand Up @@ -84,7 +84,7 @@ const MetricsTab = (props) => {
<MetricCard
title={"Others"}
footer={summary?.othersCount}
clickHandler={applyOtherFilter}
// clickHandler={applyOtherFilter}
/>
</AccordionContent>
</AccordionItem>
Expand Down

0 comments on commit 07d3245

Please sign in to comment.