Skip to content

Add resource API pattern #9731

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

Closed

Conversation

kathyguo18
Copy link

@kathyguo18 kathyguo18 commented Apr 25, 2025

Description

feat. Add resource API pattern in query_enhancements

Issues Resolved

Screenshot

Testing the changes

yarn test

Changelog

  • Add resource API pattern in query_enhancements

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

ℹ️ Manual Changeset Creation Reminder

Please ensure manual commit for changeset file 9731.yml under folder changelogs/fragments to complete this PR.

If you want to use the available OpenSearch Changeset Bot App to avoid manual creation of changeset file you can install it in your forked repository following this link.

For more information about formatting of changeset files, please visit OpenSearch Auto Changeset and Release Notes Tool.

Comment on lines +104 to +105
registerResourceManager: (dataConnectionType: string, manager: BaseConnectionManager) =>
resourceManagerService.register(dataConnectionType, manager),
Copy link
Member

Choose a reason for hiding this comment

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

this seems to be

Suggested change
registerResourceManager: (dataConnectionType: string, manager: BaseConnectionManager) =>
resourceManagerService.register(dataConnectionType, manager),
registerResourceManager: resourceManagerService.register,

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure about the reason. But when using resourceManagerService.register directly, it goes to the method itself instead of the resourceManagerService singleton.

The error is like:

TypeError: Cannot read properties of undefined (reading 'type')
    at Object.registerResourceManager 
    at AwsapmdqsdashboardsPluginPlugin.setup 

if (this.managers[dataConnectionType] !== undefined) {
throw new Error(
`Manager for dataConnectionType ${dataConnectionType} is already registered. Unable to register another manager.`
);
Copy link
Member

Choose a reason for hiding this comment

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

does this error crash the server?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. This error will crash the server, the same as when registering the same route multiple times.

@kathyguo18 kathyguo18 force-pushed the feature/resource branch 2 times, most recently from 2a1778c to a112aac Compare April 30, 2025 22:22
Copy link
Contributor

❌ Invalid Prefix For Manual Changeset Creation

Invalid description prefix. Found "feat". Only "skip" entry option is permitted for manual commit of changeset files.

If you were trying to skip the changelog entry, please use the "skip" entry option in the ##Changelog section of your PR description.

{
path: `${BASE_API}/resources`,
validate: {
query: schema.object({}, { unknowns: 'allow' }),
Copy link
Member

Choose a reason for hiding this comment

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

i don't think it needs query if it's already using content?

Copy link
Author

Choose a reason for hiding this comment

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

Do we want to keep the ability, so that some handlers can still use queryParams?

Copy link
Author

Choose a reason for hiding this comment

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

Removed the query. If other handlers want to use queryParams, they can request to update it later.

name: schema.maybe(schema.string()),
type: schema.string(),
}),
content: schema.maybe(schema.any()),
Copy link
Member

Choose a reason for hiding this comment

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

should this be schema.object({}, { unknowns: 'allow' })?

Copy link
Author

Choose a reason for hiding this comment

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

Updated. Thank you!

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.76%. Comparing base (a37c8ea) to head (2bd2b10).
Report is 4 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (a37c8ea) and HEAD (2bd2b10). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (a37c8ea) HEAD (2bd2b10)
Linux_4 1 0
Windows_4 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9731      +/-   ##
==========================================
- Coverage   61.91%   56.76%   -5.15%     
==========================================
  Files        3826     3387     -439     
  Lines       92552    84491    -8061     
  Branches    14740    13490    -1250     
==========================================
- Hits        57301    47965    -9336     
- Misses      31547    33474    +1927     
+ Partials     3704     3052     -652     
Flag Coverage Δ
Linux_1 28.89% <ø> (ø)
Linux_2 56.43% <ø> (ø)
Linux_3 39.57% <ø> (ø)
Linux_4 ?
Windows_1 28.91% <ø> (ø)
Windows_2 56.39% <ø> (ø)
Windows_3 39.59% <ø> (+<0.01%) ⬆️
Windows_4 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

❌ Invalid Prefix For Manual Changeset Creation

Invalid description prefix. Found "Add resource API pattern in query_enhancements". Only "skip" entry option is permitted for manual commit of changeset files.

If you were trying to skip the changelog entry, please use the "skip" entry option in the ##Changelog section of your PR description.

return response.notFound();
}
try {
const resourcesResponse = await manager.getResources(context, request);
Copy link
Member

Choose a reason for hiding this comment

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

i just noticed that this is still getResources. with this how would you create a resource? while you may pass in arbitrary operations as resource type, it won't make sense if the manager call is always getResources

it might be better to make the path ${BASE_API}/resources/search (i would prefer to have a separate POST route for search, rather than putting get, list, create in the same route), or change this to handlePostRequest rather than getResources, in order to distinguish between get and create

Signed-off-by: Kathy Guo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants