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

added warnings and tests for hardware profiles #3657

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rsun19
Copy link
Contributor

@rsun19 rsun19 commented Jan 17, 2025

RHOAIENG-17841

Description

Invalid inputs will now show warnings in the UI

Screenshot 2025-01-17 at 4 43 53 PM

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):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

@openshift-ci openshift-ci bot requested review from mturley and ppadti January 17, 2025 21:45
@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from a244f6b to 6f9c516 Compare January 17, 2025 21:56
@rsun19 rsun19 changed the title added warnings and tests for hardware profiles [WIP] added warnings and tests for hardware profiles Jan 20, 2025
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress This PR is in WIP state label Jan 20, 2025
@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from 6f9c516 to ab511bc Compare January 20, 2025 16:13
@rsun19 rsun19 changed the title [WIP] added warnings and tests for hardware profiles added warnings and tests for hardware profiles Jan 20, 2025
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Jan 20, 2025
@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from ab511bc to 9125256 Compare January 20, 2025 16:16
@DaoDaoNoCode
Copy link
Member

/retest

@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from 9125256 to 723e629 Compare January 20, 2025 19:38
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.36%. Comparing base (791a8b5) to head (86494e3).
Report is 47 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3657      +/-   ##
==========================================
+ Coverage   84.15%   84.36%   +0.21%     
==========================================
  Files        1453     1472      +19     
  Lines       33866    34004     +138     
  Branches     9384     9474      +90     
==========================================
+ Hits        28500    28688     +188     
+ Misses       5366     5316      -50     
Files with missing lines Coverage Δ
frontend/src/app/NavSidebar.tsx 100.00% <100.00%> (ø)
...s/hardwareProfiles/HardwareProfileEnableToggle.tsx 86.95% <100.00%> (+4.34%) ⬆️
...nd/src/pages/hardwareProfiles/HardwareProfiles.tsx 100.00% <100.00%> (ø)
...c/pages/hardwareProfiles/HardwareProfilesTable.tsx 100.00% <100.00%> (ø)
...ages/hardwareProfiles/HardwareProfilesTableRow.tsx 92.85% <100.00%> (+8.48%) ⬆️
...dwareProfiles/manage/ManageNodeResourceSection.tsx 97.56% <100.00%> (+0.33%) ⬆️
...ardwareProfiles/nodeResource/NodeResourceTable.tsx 100.00% <ø> (ø)
...wareProfiles/nodeResource/NodeResourceTableRow.tsx 100.00% <100.00%> (ø)
...d/src/pages/hardwareProfiles/nodeResource/const.ts 100.00% <100.00%> (ø)
frontend/src/pages/hardwareProfiles/utils.ts 100.00% <100.00%> (ø)
... and 5 more

... and 102 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 791a8b5...86494e3. Read the comment docs.

@rsun19
Copy link
Contributor Author

rsun19 commented Jan 20, 2025

ahhh time to add more tests for the code coverage 🤣

Copy link
Member

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

Screenshot 2025-01-20 at 4 53 03 PM

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.

frontend/src/utilities/NavData.tsx Outdated Show resolved Hide resolved
frontend/src/utilities/NavData.tsx Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
@DaoDaoNoCode
Copy link
Member

DaoDaoNoCode commented Jan 20, 2025

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

@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch 9 times, most recently from e934b0d to 2ebd5a8 Compare January 23, 2025 17:03
@rsun19
Copy link
Contributor Author

rsun19 commented Jan 23, 2025

@DaoDaoNoCode made the requested changes. However, for some methods, I had to fall back to identifier.displayName because for some reason resourceType is not allowed in the YAML for hardware profiles. Have you seen this before? Simply referring to resourceType worked a few days ago but now it disappears when trying to parse the hardware profiles

Edit: May be related to this: https://issues.redhat.com/browse/RHOAIENG-18118

@pnaik1
Copy link
Contributor

pnaik1 commented Jan 24, 2025

I had to fall back to identifier.displayName because for some reason resourceType is not allowed in the YAML for hardware profiles. Have you seen this before? Simply referring to resourceType worked a few days ago but now it disappears when trying to parse the hardware profiles

@rsun19 , Here's a possibility that you might be using old hardwareProfile CRD, Juntao added new field resourceType to CRD few days back, can you try applying the latest CRD?
let me know if you need any help here

Copy link
Member

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

  1. 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.
  2. 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/__mocks__/mockHardwareProfile.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
frontend/src/utilities/valueUnits.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/HardwareProfiles.tsx Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
frontend/src/pages/hardwareProfiles/utils.ts Outdated Show resolved Hide resolved
@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from 2ebd5a8 to 46b5431 Compare January 24, 2025 22:01
@rsun19 rsun19 changed the title [wip] added warnings and tests for hardware profiles added warnings and tests for hardware profiles Jan 30, 2025
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Jan 30, 2025
Copy link
Member

@Gkrumbach07 Gkrumbach07 left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Contributor

openshift-ci bot commented Feb 7, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Gkrumbach07

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Feb 7, 2025
@Gkrumbach07
Copy link
Member

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold This PR is hold for some reason label Feb 7, 2025
@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from 4899f28 to 27a4312 Compare February 10, 2025 21:21
@openshift-ci openshift-ci bot removed the lgtm label Feb 10, 2025
Copy link
Contributor

openshift-ci bot commented Feb 10, 2025

New changes are detected. LGTM label has been removed.

@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from 27a4312 to 5eed089 Compare February 10, 2025 23:12
@rsun19 rsun19 changed the title added warnings and tests for hardware profiles [wip] added warnings and tests for hardware profiles Feb 10, 2025
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress This PR is in WIP state label Feb 10, 2025
@rsun19 rsun19 changed the title [wip] added warnings and tests for hardware profiles added warnings and tests for hardware profiles Feb 11, 2025
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Feb 11, 2025
@rsun19
Copy link
Contributor Author

rsun19 commented Feb 11, 2025

/retest

@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from 5eed089 to 3e8d3d3 Compare February 11, 2025 14:20
@rsun19 rsun19 force-pushed the hardware-profile-edge-case-alerts branch from 3e8d3d3 to 86494e3 Compare February 11, 2025 14:57
@@ -683,3 +683,8 @@ export type IntegrationAppStatus = {
variablesValidationTimestamp?: string;
error: string;
};

export type WarningNotification = {
Copy link
Member

Choose a reason for hiding this comment

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

keep this type within the scope of hardware profiles. so move it under one of those folders in a types.ts folder

Comment on lines +18 to +20
hardwareProfile.spec.enabled &&
(typeof hardwareProfileWarningMessage === 'undefined' ||
hardwareProfileWarningMessage.message.includes(HARDWARE_PROFILES_MISSING_CPU_MEMORY_MESSAGE));
Copy link
Member

Choose a reason for hiding this comment

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

i would keep is enabled separate from the warning. Just use warning to additionally disable the hardware profile

return HardwareProfileBannerWarningTitles.SOME_INCOMPLETE;
};

export const generateWarningMessage = (
Copy link
Member

Choose a reason for hiding this comment

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

doesnt need to be exported if not used outside this file


export const isHardwareProfileOOTB = (hardwareProfile: HardwareProfileKind): boolean =>
hardwareProfile.metadata.labels?.['opendatahub.io/ootb'] === 'true';

export const generateWarningTitle = (
Copy link
Member

Choose a reason for hiding this comment

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

doesnt need to be exported unless used outside this file

Comment on lines +140 to +229
export const hardwareProfileWarning = (
hardwareProfile: HardwareProfileKind,
): WarningNotification | undefined => {
const identifiers = hardwareProfile.spec.identifiers ?? [];
let parentWarningMessage = '';
const isDefaultProfile = isHardwareProfileOOTB(hardwareProfile);
if (!hasCPUandMemory(identifiers)) {
parentWarningMessage = HARDWARE_PROFILES_MISSING_CPU_MEMORY_MESSAGE;
}
for (const identifier of identifiers) {
try {
if (identifier.minCount.toString().at(0) === '-') {
parentWarningMessage = `Minimum allowed ${
identifier.resourceType ?? identifier.displayName
} cannot be negative.`;
continue;
}
if (identifier.maxCount.toString().at(0) === '-') {
parentWarningMessage = `Maximum allowed ${
identifier.resourceType ?? identifier.displayName
} cannot be negative.`;
continue;
}
if (identifier.defaultCount.toString().at(0) === '-') {
parentWarningMessage = `Default count for ${
identifier.resourceType ?? identifier.displayName
} cannot be negative.`;
continue;
}
const [minCount] = splitValueUnit(
identifier.minCount.toString(),
determineUnit(identifier),
true,
);
const [maxCount] = splitValueUnit(
identifier.maxCount.toString(),
determineUnit(identifier),
true,
);
const [defaultCount] = splitValueUnit(
identifier.defaultCount.toString(),
determineUnit(identifier),
true,
);
if (!Number.isInteger(minCount)) {
parentWarningMessage = `Minimum count for ${
identifier.resourceType ?? identifier.displayName
} cannot be a decimal.`;
}
if (!Number.isInteger(maxCount)) {
parentWarningMessage = `Maximum count for ${
identifier.resourceType ?? identifier.displayName
} cannot be a decimal.`;
}
if (!Number.isInteger(defaultCount)) {
parentWarningMessage = `Default count for ${
identifier.resourceType ?? identifier.displayName
} cannot be a decimal.`;
}
if (minCount > maxCount) {
parentWarningMessage = `Minimum allowed ${
identifier.resourceType ?? identifier.displayName
} cannot exceed maximum allowed ${identifier.resourceType ?? identifier.displayName}.`;
} else if (defaultCount < minCount || defaultCount > maxCount) {
parentWarningMessage = `The default count for ${
identifier.resourceType ?? identifier.displayName
} must be between the minimum allowed ${
identifier.resourceType ?? identifier.displayName
} and maximum allowed ${identifier.resourceType ?? identifier.displayName}.`;
}
} catch (e) {
parentWarningMessage = `The resource count for ${
identifier.resourceType ?? identifier.displayName
} has an invalid unit.`;
}
}

return parentWarningMessage
? {
title: `${!hasCPUandMemory(identifiers) ? 'Incomplete' : 'Invalid'} ${
isDefaultProfile === true ? 'default hardware' : 'hardware'
} profile`,
message: `${parentWarningMessage} ${
isDefaultProfile
? HARDWARE_PROFILES_DEFAULT_WARNING_MESSAGE
: 'Edit the profile to make the profile valid.'
}`,
}
: undefined;
};
Copy link
Member

Choose a reason for hiding this comment

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

this function should basically validate the hardware profile. It looks like you are returning only one error becuase parentWarningMessage keeps getting overwritten.

I think this function should return an array of all the warnings with the profile. so...

enum HardwareProfileWarningType {
   HARDWARE_PROFILES_DEFAULT_WARNING,
   HARDWARE_PROFILES_MISSING_CPU_MEMORY,
   OTHER
}
   
type HardwareProfileWarning = {
   title: string,
   message: string
   type: HardwareProfileWarningType
}

export const validateProfileWarning = ( hardwareProfile: HardwareProfileKind): HardwareProfileWarning[] => {
  // same func body but instead add to this array and return that
} 

Comment on lines +63 to +98
export const generateWarningForHardwareProfiles = (
hardwareProfiles: HardwareProfileKind[],
): WarningNotification | undefined => {
const hasInvalid = hardwareProfiles.some((profile) => {
const warning = hardwareProfileWarning(profile);
return (
typeof warning !== 'undefined' &&
!warning.message.includes(HARDWARE_PROFILES_MISSING_CPU_MEMORY_MESSAGE)
);
});
const hasEnabled = hardwareProfiles.some((profile) => profile.spec.enabled);
const allInvalid = hardwareProfiles.every((profile) => {
const warning = hardwareProfileWarning(profile);
return (
typeof warning !== 'undefined' &&
!warning.message.includes(HARDWARE_PROFILES_MISSING_CPU_MEMORY_MESSAGE)
);
});
const allIncomplete = hardwareProfiles.every((profile) => {
const warning = hardwareProfileWarning(profile);
return (
typeof warning !== 'undefined' &&
warning.message.includes(HARDWARE_PROFILES_MISSING_CPU_MEMORY_MESSAGE)
);
});
const hasInvalidIncludingIncompleteProfiles = hardwareProfiles.some(
(profile) => typeof hardwareProfileWarning(profile) !== 'undefined',
);
if (hardwareProfiles.length === 0 || (!hasInvalidIncludingIncompleteProfiles && hasEnabled)) {
return undefined;
}
return {
title: generateWarningTitle(hasEnabled, allInvalid, hasInvalid, allIncomplete),
message: generateWarningMessage(hasEnabled, allInvalid, hasInvalid, allIncomplete),
};
};
Copy link
Member

Choose a reason for hiding this comment

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

Now this function after updating the other func (hardwareProfileWarning) you can instead look for the specific warnings like

const warnings = hardwareProfileWarning(profile);
const invalid === warnings.some(warning => warning.type === HARDWARE_PROFILES_MISSING_CPU_MEMORY)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved do-not-merge/hold This PR is hold for some reason
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants