Skip to content
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

Open
wants to merge 5 commits into
base: revamp
Choose a base branch
from

Conversation

MVarshini
Copy link
Collaborator

Type of change

  • Refactor
  • New feature
  • Bug fix
  • Optimization
  • Documentation Update

Description

The [PROD]_JOBS_API accepts size and offset params

Related Tickets & Documents

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please describe the System Under Test.
  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

@MVarshini MVarshini self-assigned this Nov 19, 2024
@MVarshini MVarshini changed the base branch from main to revamp November 20, 2024 13:39
Comment on lines 30 to 31
return jobs
return jobs
return ({'data':jobs, 'total': response['total']})
Copy link
Member

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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."),
Copy link
Member

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
Copy link
Member

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.

Comment on lines +121 to +122
# return await self.scan_indices(self.new_es, self.new_index, query, timestamp_field, start_date, end_date, size)
# else:
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

@dbutenhof dbutenhof left a 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 ...

backend/app/api/v1/commons/hce.py Show resolved Hide resolved
backend/app/api/v1/commons/hce.py Outdated Show resolved Hide resolved
backend/app/api/v1/endpoints/cpt/cptJobs.py Outdated Show resolved Hide resolved
except Exception as e:
print(f"Error fetching data for product {product}: {e}")


num = 0 if totalJobs is None else int(totalJobs)
Copy link
Collaborator

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...

backend/app/api/v1/endpoints/cpt/cptJobs.py Show resolved Hide resolved
backend/app/api/v1/endpoints/cpt/cptJobs.py Outdated Show resolved Hide resolved
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")
Copy link
Collaborator

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.

Copy link
Collaborator

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

  1. run black and Prettier on all Python and JavaScript/CSS files, and
  2. 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.)
  3. 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will follow it!

backend/app/api/v1/endpoints/cpt/maps/ocp.py Show resolved Hide resolved
backend/app/api/v1/endpoints/ocm/ocmJobs.py Outdated Show resolved Hide resolved
backend/app/api/v1/endpoints/ocp/ocpJobs.py Outdated Show resolved Hide resolved
@vishnuchalla vishnuchalla mentioned this pull request Nov 21, 2024
7 tasks
frontend/src/components/organisms/Pagination/index.jsx Outdated Show resolved Hide resolved
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")
Copy link
Collaborator

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

  1. run black and Prettier on all Python and JavaScript/CSS files, and
  2. 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.)
  3. 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.

Copy link
Collaborator

@dbutenhof dbutenhof left a 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. 😆

Comment on lines 29 to 31
if len(jobs) == 0:
return jobs
return({'data':jobs, 'total': 0})
return ({'data':jobs, 'total': response['total']})
Copy link
Collaborator

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.

Copy link
Member

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})
Copy link
Collaborator

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})
Copy link
Collaborator

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. \
Copy link
Collaborator

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"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants