-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add resource API pattern #9731
Conversation
ℹ️ Manual Changeset Creation ReminderPlease 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. |
src/plugins/query_enhancements/server/routes/resources/routes.ts
Outdated
Show resolved
Hide resolved
src/plugins/query_enhancements/server/routes/resources/routes.ts
Outdated
Show resolved
Hide resolved
registerResourceManager: (dataConnectionType: string, manager: BaseConnectionManager) => | ||
resourceManagerService.register(dataConnectionType, manager), |
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 seems to be
registerResourceManager: (dataConnectionType: string, manager: BaseConnectionManager) => | |
resourceManagerService.register(dataConnectionType, manager), | |
registerResourceManager: resourceManagerService.register, |
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'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
src/plugins/query_enhancements/server/routes/resources/routes.ts
Outdated
Show resolved
Hide resolved
src/plugins/query_enhancements/server/routes/resources/routes.ts
Outdated
Show resolved
Hide resolved
src/plugins/query_enhancements/server/routes/resources/routes.ts
Outdated
Show resolved
Hide resolved
if (this.managers[dataConnectionType] !== undefined) { | ||
throw new Error( | ||
`Manager for dataConnectionType ${dataConnectionType} is already registered. Unable to register another manager.` | ||
); |
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.
does this error crash the server?
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.
Yes. This error will crash the server, the same as when registering the same route multiple times.
2a1778c
to
a112aac
Compare
❌ Invalid Prefix For Manual Changeset CreationInvalid 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' }), |
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 don't think it needs query
if it's already using content
?
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.
Do we want to keep the ability, so that some handlers can still use queryParams?
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.
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()), |
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.
should this be schema.object({}, { unknowns: 'allow' })
?
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.
Updated. Thank you!
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
❌ Invalid Prefix For Manual Changeset CreationInvalid 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. |
a112aac
to
2bd2b10
Compare
return response.notFound(); | ||
} | ||
try { | ||
const resourcesResponse = await manager.getResources(context, request); |
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 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
2bd2b10
to
65efa1d
Compare
Signed-off-by: Kathy Guo <[email protected]>
42da8e7
to
5483e45
Compare
Description
feat. Add resource API pattern in query_enhancements
Issues Resolved
Screenshot
Testing the changes
yarn test
Changelog
Check List
yarn test:jest
yarn test:jest_integration