-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Pagination in CPT Dashboard #135
base: revamp
Are you sure you want to change the base?
Conversation
backend/app/api/v1/commons/hce.py
Outdated
return jobs | ||
return jobs | ||
return ({'data':jobs, 'total': response['total']}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have the output format differ between the empty and non-empty case?
It looks like this results in the need to have if statements for the empty case in several spots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MVarshini maybe we can just have this check at one place from where this virtual function is being invoked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the non-empty case too.
@@ -37,7 +37,11 @@ | |||
},) | |||
async def jobs(start_date: date = Query(None, description="Start date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-10"]), | |||
end_date: date = Query(None, description="End date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-15"]), | |||
pretty: bool = Query(False, description="Output contet in pretty format.")): | |||
pretty: bool = Query(False, description="Output contet in pretty format."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: content
@@ -2,8 +2,8 @@ | |||
from datetime import date | |||
|
|||
################################################################ | |||
# This will return a DataFrame from HCE required by the CPT | |||
# endpoint, it contians the following columns: | |||
# This will return a Dictionary with from HCE required by the CPT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inclusion of "with" here seems odd.
# return await self.scan_indices(self.new_es, self.new_index, query, timestamp_field, start_date, end_date, size) | ||
# else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned that this change might inadvertently impact other scenarios, even though I've verified it against most cases. If it doesn't affect any other cases then these lines can be taken out or it can be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get all the way through, but here's a bunch ...
except Exception as e: | ||
print(f"Error fetching data for product {product}: {e}") | ||
|
||
|
||
num = 0 if totalJobs is None else int(totalJobs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
totalJobs
is an int
and it's not optional, so either the parameter type hint is wrong, or most of this statement isn't meaningful. Why is it checking for None
? Why is it converting to int
?
I'm not really sure what totalJobs
does here. The relationship of num
and total
is a bit odd; a comment would probably help to clarify the intent.
num
is 0 if totalJobs
is passed in as 0 or None
. If totalJobs
is 0 (not None) then we compute total
by summing across products; and then we set totalJobs
to the max of those two, and report it as the response["total"]
... what purpose does this serve? I guess I'm missing something here...
df["ciSystem"] = "Jenkins" | ||
df["testName"] = df["product"] + ":" + df["test"] | ||
df["product"] = df["group"] | ||
df["jobStatus"] = df['result'].apply(lambda x: "SUCCESS" if x == 'PASS' else "FAILURE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixing double-quote and single-quote indices isn't really a good idea. (If you ran black
it would convert all the single quoted strings to double-quotes.) While Python allows both, mixing them in a module (much less in a line) is unnecessarily confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, as a general maintainability/readability suggestion to the maintainers: after all the outstanding PRs are merged and stabilized, it'd be a great idea to
- run
black
andPrettier
on all Python and JavaScript/CSS files, and - add a CI lint check GitHub Action that'll fail a PR if it breaks the style rules. (Of course adding additional lint checks with
flake8
/ES lint/CodeQL would be a great idea too.) - Submit this as a PR with no functional changes; it might be large, (depending on how bad the code is), but it'd be straightforward to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will follow it!
df["ciSystem"] = "Jenkins" | ||
df["testName"] = df["product"] + ":" + df["test"] | ||
df["product"] = df["group"] | ||
df["jobStatus"] = df['result'].apply(lambda x: "SUCCESS" if x == 'PASS' else "FAILURE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, as a general maintainability/readability suggestion to the maintainers: after all the outstanding PRs are merged and stabilized, it'd be a great idea to
- run
black
andPrettier
on all Python and JavaScript/CSS files, and - add a CI lint check GitHub Action that'll fail a PR if it breaks the style rules. (Of course adding additional lint checks with
flake8
/ES lint/CodeQL would be a great idea too.) - Submit this as a PR with no functional changes; it might be large, (depending on how bad the code is), but it'd be straightforward to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of good cleanup, but I think you added a few bugs while you were at it. 😆
backend/app/api/v1/commons/hce.py
Outdated
if len(jobs) == 0: | ||
return jobs | ||
return({'data':jobs, 'total': 0}) | ||
return ({'data':jobs, 'total': response['total']}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? if len(jobs)
is 0 doesn't that mean len(tasks)
was 0? And doesn't that mean that response["total"]
is 0?
Also, you don't need to parenthesize the dict constructor -- return {"data": jobs, "total": response["total"]}
would work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, is this necessary? Is the response value total
not present when the number of jobs is zero?
@@ -27,7 +27,7 @@ async def getData(start_datetime: date, end_datetime: date, size:int, offset:int | |||
tasks = [item['_source'] for item in response["data"]] | |||
jobs = pd.json_normalize(tasks) | |||
if len(jobs) == 0: | |||
return jobs | |||
return ({'data':jbs, 'total': 0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that 'data':jbs
is a typo. There isn't actually a jbs
in scope, is there?
@@ -27,7 +27,7 @@ async def getData(start_datetime: date, end_datetime: date, size, offset, config | |||
tasks = [item['_source'] for item in response['data']] | |||
jobs = pd.json_normalize(tasks) | |||
if len(jobs) == 0: | |||
return jobs | |||
return ({'data':jbs, 'total': 0}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jbs
=> jobs
@@ -12,7 +12,7 @@ | |||
|
|||
@router.get('/api/v1/ocp/jobs', | |||
summary="Returns a job list", | |||
description="Returns a list of jobs in the specified dates of requested size. \ | |||
description="Returns a list of jobs in the specified dates. \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "in the specified date range"?
Type of change
Description
The
[PROD]_JOBS_API
acceptssize
andoffset
paramsRelated Tickets & Documents
Checklist before requesting a review
Testing