-
Notifications
You must be signed in to change notification settings - Fork 178
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
added warnings and tests for hardware profiles #3657
base: main
Are you sure you want to change the base?
added warnings and tests for hardware profiles #3657
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
a244f6b
to
6f9c516
Compare
6f9c516
to
ab511bc
Compare
ab511bc
to
9125256
Compare
/retest |
9125256
to
723e629
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3657 +/- ##
==========================================
+ Coverage 84.15% 84.23% +0.08%
==========================================
Files 1453 1455 +2
Lines 33866 34020 +154
Branches 9384 9457 +73
==========================================
+ Hits 28500 28658 +158
+ Misses 5366 5362 -4
... and 4 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
ahhh time to add more tests for the code coverage 🤣 |
frontend/src/__tests__/cypress/cypress/pages/hardwareProfile.ts
Outdated
Show resolved
Hide resolved
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.
Besides the comments I left, one important note is missing. You need to automatically disable the invalid hardware profiles and disable the toggle to prevent them from re-enable it before resolving the invalid values.
Other than that, it works well, good job! Most of my comments are about code quality because we want to make it reusable and easier to maintain in the future. :) Let me know if you have any questions with any of my comments and I am happy to help and walk you through it.
description={hardwareProfile.spec.description} | ||
truncateDescriptionLines={2} | ||
/> | ||
<Flex> |
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.
There is a layout issue with the invalid hardware profiles that have descriptions.
Checking the use of TableRowTitleDescription
, I think you just need to do 3 things.
- Remove the
Flex
layout here and put the wholePopover
into thetitleIcon
ofTableRowTitleDescription
- Add
resource={hardwareProfile}
toTableRowTitleDescription
(I had discussed this with Vince before but forgot to add it in my last PR, you can add it here, so it will show a QuestionIcon popover like other tables to help users find the k8s name of the hardware profile) - Add
wrapResourceTitle={false}
toTableRowTitleDescription
to make sure the warning icon won't go to the next row.
After all the changes, your table title should look like this:
frontend/src/utilities/NavData.tsx
Outdated
useAreaCheck<NavDataHref>(SupportedArea.HARDWARE_PROFILES, [ | ||
{ | ||
id: 'settings-hardware-profiles', | ||
label: 'Hardware profiles', | ||
label: isValid ? ( |
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.
IsValid
? The logic here works well but it looks like you are using an opposite naming for the variable. Maybe change it to isWarning
? or pass!isWarning
into this component and change the logic here.
import { groupVersionKind, HardwareProfileModel } from '~/api'; | ||
import useK8sWatchResourceList from './useK8sWatchResourceList'; | ||
|
||
export const useWatchHardwareProfiles = ( |
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.
If you are planning to use websocket to watch the hardware profiles, maybe also use it when fetching the hardware profile table. Otherwise, when user edits something on the cluster to something invalid, there is an error message on the nav item but nothing on the table because they are using different ways to fetch the hardware profiles.
...profile, | ||
spec: { | ||
...profile.spec, | ||
warning: { |
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.
So as I said above, there is no need to use warningStatus
, you can simply do
warning: parentWarningMessage ? {
title: xxx(your conditions)
message: parentWarningMessage
} : undefined
warningStatus: boolean; | ||
title: string; | ||
message: string; | ||
isDefaultProfile: boolean; |
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.
This prop isDefaultProfile
is also not very useful here. It's only used to decide whether to show a button to restore default or not when rendering the popover, you can just do isHardwareProfileOOTB(profile)
there in the table row. No need to pass it around and make the type complicated. Keep it as simple as possible (P.S. isDefaultProfile
should not be in warning
, when structuring a type, we also need to consider the context and see whether we really need it or if it's reasonable enough to be here, just a suggestion)
let isEnabled = false; | ||
let warningCount = 0; | ||
for (const profile of hardwareProfiles) { | ||
if (profile.spec.warning?.warningStatus === true) { | ||
warningCount += 1; | ||
} | ||
if (profile.spec.enabled === true) { | ||
isEnabled = true; | ||
} | ||
} | ||
|
||
return { | ||
warning: warningCount > 0 || !isEnabled, | ||
title: generateWarningTitle(isEnabled, warningCount === hardwareProfiles.length, warningCount), | ||
message: generateWarningMessage( | ||
isEnabled, | ||
warningCount === hardwareProfiles.length, | ||
warningCount, | ||
), | ||
isEnabled, | ||
}; | ||
}; |
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.
You can do all of these easily. There are some
and every
methods in array.
As for the isEnabled
prop, you don't need to return it because you are not using it anywhere.
let isEnabled = false; | |
let warningCount = 0; | |
for (const profile of hardwareProfiles) { | |
if (profile.spec.warning?.warningStatus === true) { | |
warningCount += 1; | |
} | |
if (profile.spec.enabled === true) { | |
isEnabled = true; | |
} | |
} | |
return { | |
warning: warningCount > 0 || !isEnabled, | |
title: generateWarningTitle(isEnabled, warningCount === hardwareProfiles.length, warningCount), | |
message: generateWarningMessage( | |
isEnabled, | |
warningCount === hardwareProfiles.length, | |
warningCount, | |
), | |
isEnabled, | |
}; | |
}; | |
const hasInvalid = hardwareProfiles.some((profile) => profile.spec.warning); | |
const hasEnabled = hardwareProfiles.some((profile) => profile.spec.enabled); | |
const allInvalid = hardwareProfiles.every((profile) => profile.spec.warning); | |
return { | |
warning: hasInvalid || !hasEnabled, | |
title: generateWarningTitle(hasEnabled, allInvalid), | |
message: generateWarningMessage(hasEnabled, allInvalid), | |
}; |
export const generateWarningMessage = ( | ||
isEnabled: boolean, | ||
isAllWarnings: boolean, | ||
warningCount: number, |
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.
You don't need warningCount here. There is no way warningCount could be 0
in this situation when showing the alert.
export const generateWarningTitle = ( | ||
isEnabled: boolean, | ||
isAllWarnings: boolean, | ||
warningCount: number, |
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.
Same here, no need to add warningCount here.
If the first 2 conditions are not met, directly return the third error title.
I haven't finished testing all the scenarios yet. I will do another round of review after you address the comments I left above and test it overall again. 😄 |
e934b0d
to
2ebd5a8
Compare
@DaoDaoNoCode made the requested changes. However, for some methods, I had to fall back to Edit: May be related to this: https://issues.redhat.com/browse/RHOAIENG-18118 |
@rsun19 , Here's a possibility that you might be using old hardwareProfile CRD, Juntao added new field |
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.
LGTM most of the parts. There are still 2 major things.
- The use of the types - We should try to avoid redundant types and make best use of the available/existing types, so it could be easier to maintain/add features in the future.
- For "Incomplete" hardware profiles (Hardware profiles that miss CPU/Memory), we should not block them from enabling because that's still valid, just not recommended. If you want we can have a talk when you are online, so we can walk through all the comments together to make it work as expected.
frontend/src/pages/hardwareProfiles/HardwareProfileEnableToggle.tsx
Outdated
Show resolved
Hide resolved
frontend/src/pages/hardwareProfiles/manage/ManageNodeResourceSection.tsx
Outdated
Show resolved
Hide resolved
frontend/src/pages/hardwareProfiles/manage/ManageNodeResourceSection.tsx
Outdated
Show resolved
Hide resolved
enabled: profile.spec.enabled && !warningStatus, | ||
warning: parentWarningMessage | ||
? { | ||
title: | ||
warningStatus === true | ||
? `${!hasCPUandMemory(identifiers) ? 'Incomplete' : 'Invalid'} ${ | ||
isDefaultProfile === true ? 'default hardware' : 'hardware' | ||
} profile` | ||
: '', | ||
message: warningStatus === true ? parentWarningMessage : '', | ||
} | ||
: undefined, |
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.
enabled: profile.spec.enabled && !warningStatus, | |
warning: parentWarningMessage | |
? { | |
title: | |
warningStatus === true | |
? `${!hasCPUandMemory(identifiers) ? 'Incomplete' : 'Invalid'} ${ | |
isDefaultProfile === true ? 'default hardware' : 'hardware' | |
} profile` | |
: '', | |
message: warningStatus === true ? parentWarningMessage : '', | |
} | |
: undefined, | |
enabled: profile.spec.enabled && !parentWarningMessage, | |
warning: parentWarningMessage | |
? { | |
title: `${!hasCPUandMemory(identifiers) ? 'Incomplete' : 'Invalid'} ${ | |
isDefaultProfile === true ? 'default hardware' : 'hardware' | |
} profile`, | |
message: parentWarningMessage, | |
} | |
: undefined, |
for (let identifier of identifiers) { | ||
if ( | ||
identifier.resourceType === IdentifierResourceType.CPU || | ||
identifier.displayName === IdentifierResourceType.CPU || | ||
identifier.resourceType === IdentifierResourceType.MEMORY || | ||
identifier.displayName === IdentifierResourceType.MEMORY | ||
) { | ||
identifier = { | ||
...identifier, | ||
warning: true, | ||
}; | ||
} | ||
} |
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 what this is trying to do... Can you explain it to me? What I am reading is: "If this is an OOTB hardware profile and it lacks CPU/Memory resource, add a warning icon to all of its CPU and Memory resource row" - Which doesn't make sense to me. There is no need to add the warning to any resource row in this situation because it's just lacking CPU and/or Memory for the whole table, and needs to be added.
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.
Ah ok that makes sense
46b5431
to
77982f6
Compare
@DaoDaoNoCode Made requested changes. I have a few points though:
|
fa0ed7d
to
940b5dd
Compare
Made further changes. Juntao and I talked with Vince, and we clarified 2 points:
|
940b5dd
to
63543c4
Compare
63543c4
to
4899f28
Compare
RHOAIENG-17841
Description
Invalid inputs will now show warnings in the UI
How Has This Been Tested?
You can directly insert hardware profiles in the cluster dashboard. Input invalid values as specified in the jira issue and mockups.
Test Impact
I added unit tests and cypress tests
Request review criteria:
Self checklist (all need to be checked):
If you have UI changes:
After the PR is posted & before it merges:
main