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

refactor: centralize resource slot type definitions and improve device metadata handling in /react #2684

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

yomybaby
Copy link
Member

@yomybaby yomybaby commented Sep 3, 2024

TL;DR

Added support for dynamic accelerator types and improved resource allocation handling.

What changed?

  • Introduced ResourceSlotName type to handle known and unknown accelerator types
  • Updated ResourceTypeIcon component to use dynamic resource slot details
  • Modified ResourceAllocationFormItems to use resource slot details for display units
  • Added JSON schema validation for device metadata
  • Implemented isMatchingMaxPerContainer function for flexible config matching
  • Updated resource limit calculations to support unknown accelerator types

The steps to add a new accelerator type

  1. Add the accelerator type to knownAcceleratorResourceSlotNames in react/src/hooks/backendai.tsx.
  2. Add an icon for the new accelerator type to resourceTypeIconSrcMap in react/src/components/ResourceNumber.tsx.
  3. Add new accelerator metadata to resources/device_metadata.json.

After following only step 1, you got a TypeScript error related to step 2 and Jest test failures related to step 3.

How to test?

  1. Run the JSON schema validation test for device metadata
  2. Test the resource allocation form with various accelerator types
  3. Verify that unknown accelerator types are handled correctly in the UI
  4. Check if the resource limits are calculated correctly for all accelerator types

Why make this change?

This change improves the flexibility and maintainability of the codebase by:

  1. Supporting dynamic accelerator types without hardcoding
  2. Ensuring consistency between device metadata and code
  3. Improving resource limit calculations for various accelerator types
  4. Enhancing the user interface to display correct units for different accelerators

These improvements allow for easier addition of new accelerator types and better handling of resource allocation across different devices.

Copy link

graphite-app bot commented Sep 3, 2024

Your org requires the Graphite merge queue for merging into main

Add the label “flow:merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “flow:hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the size:L 100~500 LoC label Sep 3, 2024
Copy link
Member Author

yomybaby commented Sep 3, 2024

Copy link

github-actions bot commented Sep 3, 2024

Coverage report for ./react

St.
Category Percentage Covered / Total
🔴 Statements
5.49% (+0.12% 🔼)
337/6143
🔴 Branches
5.08% (+0.06% 🔼)
214/4215
🔴 Functions
3.12% (+0.04% 🔼)
63/2019
🔴 Lines
5.38% (+0.12% 🔼)
323/5999
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / ResourceNumber.tsx
21.43% (-5.24% 🔻)
0% 0%
21.43% (-5.24% 🔻)
🔴
... / ResourceAllocationFormItems.tsx
16.33%
11.67% (-0.1% 🔻)
13.64% 15.98%

Test suite run success

85 tests passing in 11 suites.

Report generated by 🧪jest coverage report action from d52c682

@yomybaby yomybaby force-pushed the refactor/remove-hard-coded-resource-name branch from 5d3ed00 to 726b291 Compare September 3, 2024 11:36
@yomybaby yomybaby marked this pull request as ready for review September 3, 2024 11:37
@yomybaby yomybaby force-pushed the refactor/remove-hard-coded-resource-name branch 2 times, most recently from a76b485 to 3086120 Compare September 4, 2024 03:03
@yomybaby yomybaby changed the title Refactor: Remove all hard-coded resource slot names in /react refactor: centralize resource slot type definitions and improve device metadata handling Sep 4, 2024
@yomybaby yomybaby changed the title refactor: centralize resource slot type definitions and improve device metadata handling refactor: centralize resource slot type definitions and improve device metadata handling in /react Sep 4, 2024
@yomybaby yomybaby marked this pull request as draft September 4, 2024 03:05
@yomybaby yomybaby force-pushed the refactor/remove-hard-coded-resource-name branch from 3086120 to 8d61cb6 Compare September 4, 2024 03:06
@yomybaby yomybaby marked this pull request as ready for review September 4, 2024 03:43
@yomybaby yomybaby force-pushed the refactor/remove-hard-coded-resource-name branch 2 times, most recently from e6cb569 to 92df5b7 Compare September 4, 2024 15:45
Copy link
Contributor

@lizable lizable 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

graphite-app bot commented Sep 5, 2024

Merge activity

…e metadata handling in `/react` (#2684)

### TL;DR

Added support for dynamic accelerator types and improved resource allocation handling.

### What changed?

- Introduced `ResourceSlotName` type to handle known and unknown accelerator types
- Updated `ResourceTypeIcon` component to use dynamic resource slot details
- Modified `ResourceAllocationFormItems` to use resource slot details for display units
- Added JSON schema validation for device metadata
- Implemented `isMatchingMaxPerContainer` function for flexible config matching
- Updated resource limit calculations to support unknown accelerator types

### The steps to add a new accelerator type
1. Add the accelerator type to `knownAcceleratorResourceSlotNames` in `react/src/hooks/backendai.tsx`.
2. Add an icon for the new accelerator type to `resourceTypeIconSrcMap` in `react/src/components/ResourceNumber.tsx`.
3. Add new accelerator metadata to `resources/device_metadata.json`.

After following only step 1, you got a TypeScript error related to step 2 and Jest test failures related to step 3.

### How to test?

1. Run the JSON schema validation test for device metadata
2. Test the resource allocation form with various accelerator types
3. Verify that unknown accelerator types are handled correctly in the UI
4. Check if the resource limits are calculated correctly for all accelerator types

### Why make this change?

This change improves the flexibility and maintainability of the codebase by:

1. Supporting dynamic accelerator types without hardcoding
2. Ensuring consistency between device metadata and code
3. Improving resource limit calculations for various accelerator types
4. Enhancing the user interface to display correct units for different accelerators

These improvements allow for easier addition of new accelerator types and better handling of resource allocation across different devices.
@lizable lizable force-pushed the refactor/remove-hard-coded-resource-name branch from 92df5b7 to d52c682 Compare September 5, 2024 02:53
@graphite-app graphite-app bot merged commit d52c682 into main Sep 5, 2024
8 checks passed
@graphite-app graphite-app bot deleted the refactor/remove-hard-coded-resource-name branch September 5, 2024 02:56
Copy link
Member Author

@yomybaby yomybaby left a comment

Choose a reason for hiding this comment

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

This PR is related to #1937

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L 100~500 LoC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants