-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Uptime] Remove legacy es client #51403
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
[Uptime] Remove legacy es client #51403
Conversation
|
Pinging @elastic/uptime (Team:uptime) |
💔 Build Failed
|
💔 Build Failed
|
💚 Build Succeeded
|
💔 Build Failed
|
💚 Build Succeeded
|
b62319c to
84fdd3d
Compare
💔 Build Failed
|
84fdd3d to
5267e09
Compare
💔 Build Failed
|
…itor details endpoint.
andrewvc
left a comment
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.
Generally looks great, though I did have some questions about some aspects of the code.
Code runs fine in a smoke test locally.
|
@elasticmachine merge upstream |
| export interface GetSnapshotCountParams { | ||
| dateRangeStart: string; | ||
| dateRangeEnd: string; | ||
| filters?: string | null; | ||
| statusFilter?: string | null; | ||
| } | ||
|
|
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.
it's generally makes sense to move all the interfaces to the top of the file, can you move this close to MonitorStatesParams?
And also may be use MonitorStatesParams for snapshot as well, since pagination is optional. Once you do that i guess it will also makes sense to have a bit more generic name Just QueryParams, WDYT?
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.
We already have that in the first Maps PR, when we merge one we can overwrite this for the other and yes we can just use a generic interface for components that only require these four basic params I agree!
| dateRangeEnd, | ||
| pagination, | ||
| filters, | ||
| statusFilter, |
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.
Probably not related to this PR, but i have always been confused by filters and statusFilter, i mean they always gives my brain a challenge to process the information. "Ok we have filters and then we have statusFilter :) let's think about it , what they means."
i guess we should probably rename statusFilter to monitorStatus or maybe just merge it with filters.or maybe it's fine, it's just me :D
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.
We should chat about this, I'm realizing maybe @andrewvc and myself have never explained why we have this weirdness. I'd be fine to rename it to something else in a separate PR if we can think of a less confusing way to refer to it.
| filterClause: filters && filters !== '' ? JSON.parse(filters) : null, | ||
| size: CONTEXT_DEFAULTS.MAX_MONITORS_FOR_SNAPSHOT_COUNT, | ||
| statusFilter, | ||
| statusFilter: statusFilter || 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.
i wonder why are you explicitly assigning it as undefined, if it's already undefined, i mean that's how short-hand objection notation works.
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.
Reason for this: QueryContext requires statusFilter to be string | undefined, but the typing for statusFilter from API requests historically can be string | null | undefined. I didn't want to break any code that might be explicitly testing the value for undefined so I overwrite any falsy value with undefined. We can clean this up by modifying the type provided by the request handler, which I will do.
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.
Fixed this in c0d5187.
| value: 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.
Another unrelated to PR , suggestion is to rename adapter_types file to just types.
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 naming convention predates Uptime and was a result of mirroring other new plugins. I think we've done away with many of the conventions, so I am fine with renaming these files to make them less verbose.
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 created elastic/uptime#126
| } | ||
| } | ||
| }, | ||
| }; |
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.
Again file naming, unrelated to this PR, elasticsearch_pings_adapter.ts should be just elasticsearch_pings, since it's inside adapters folder, so it doesn't make sense to prefix/postfix files. It's a twitter rules as well, when you have already used "lol", "haha" can't be used in the same tweet :P
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.
Lol, I see what you're saying haha.
Addressed in #51403 (comment).
shahzad31
left a comment
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 have left some suggestions, those are totally optional.
other PR is good to go, smoke tested and didn't find any issue.
…bic/kibana into uptime_remove-legacy-es-client
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
andrewvc
left a comment
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
* Move a REST endpoint and the GQL endpoint to NP routing. * Delete obsolete REST endpoint. * Update remaining REST routes to work with NP router. * Remove obsolete code, update some unit tests. * Simplify route creation. * Remove tests of API decommissioned API endpoint. * Rename domain check. * Make return shape of index pattern endpoint correspond to required NP resp body. * Move validate to appropriate level of route definition object for monitor details endpoint. * Update snapshot count route. * Fix broken lint rule. * Move a REST endpoint and the GQL endpoint to NP routing. * Update remaining REST routes to work with NP router. * Update remaining REST routes to work with NP router. * Refactor query functions to accept new es client from request contexts. * WIP updating framework adapter. * Refactor remaining routes/resolvers to remove usage of legacy Elasticsearch client. * Fix broken unit tests. * Fix incorrect user usage for a REST endpoint. * Fix some broken imports and types. * Port monitor details REST endpoint to NP. * Remove some merge errors. * Update adapters to take a single options parameter. * Update broken test files. * Resolve typescript warnings. * Update resolver types. * Change GraphQL interface name for es client. * Delete unused code and fix incorrect type. * Rename type for REST endpoint creators. * Nest message values in body object for invalid response messages. * Reorganize a file and clean up some types. * Add wrapper function to reduce boilerplate route code.
* Move a REST endpoint and the GQL endpoint to NP routing. * Delete obsolete REST endpoint. * Update remaining REST routes to work with NP router. * Remove obsolete code, update some unit tests. * Simplify route creation. * Remove tests of API decommissioned API endpoint. * Rename domain check. * Make return shape of index pattern endpoint correspond to required NP resp body. * Move validate to appropriate level of route definition object for monitor details endpoint. * Update snapshot count route. * Fix broken lint rule. * Move a REST endpoint and the GQL endpoint to NP routing. * Update remaining REST routes to work with NP router. * Update remaining REST routes to work with NP router. * Refactor query functions to accept new es client from request contexts. * WIP updating framework adapter. * Refactor remaining routes/resolvers to remove usage of legacy Elasticsearch client. * Fix broken unit tests. * Fix incorrect user usage for a REST endpoint. * Fix some broken imports and types. * Port monitor details REST endpoint to NP. * Remove some merge errors. * Update adapters to take a single options parameter. * Update broken test files. * Resolve typescript warnings. * Update resolver types. * Change GraphQL interface name for es client. * Delete unused code and fix incorrect type. * Rename type for REST endpoint creators. * Nest message values in body object for invalid response messages. * Reorganize a file and clean up some types. * Add wrapper function to reduce boilerplate route code.
Summary
Working toward removing legacy elasticsearch client from Uptime backend.Code is WIP.Do not review until #51125 is merged.The biggest change in this patch is that we are getting our elasticsearch client from the request object provided by the Kibana route handler. Before we were storing references to an elasticsearch client that was provided at bootstrap time.
Changes
GraphQL route creation
We were previously passing the
requestobject to our GraphQL resolvers by including it in anoptionsobject that was included in the resolver parameters. We're doing essentially the same thing, but now are including thecallWithCurrentUserfunction provided by the request context.The implementation of this is largely the same in GQL resolvers, except that we're simply passing this client to the adapters instead of the request object itself. Example:
Before:
After:
Adapter interfaces
Adapter functions now subscribe to a shared interface. Their first parameter is the elasticsearch client used by the adapter to query ES. The second parameter is either an object containing data needed for the adapter query, or
undefined. I might revise this before opening the PR for review to take only a shared object.This interface can be found here.
Before:
After:
The goal is to eventually extract all these methods out of their current class configuration into pure functions exported from their own modules, which will make them simpler to test and create shorter adapter files.
Reviewing the PR
Primary changes here are architectural - if all tests are passing and you're able to open/run the Uptime app like it would normally work, all should be well. The larger portion of the review should be to ensure that I've preserved existing code quality as much as possible, and that new patterns introduced make sense.
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.For maintainers