-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Uptime] replace fetch with kibana http #59881
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
Conversation
|
Pinging @elastic/uptime (Team:uptime) |
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.
Definitely an improvement! Left some notes.
| ); | ||
| }, [canSave, renderGlobalHelpControls, setBadge]); | ||
|
|
||
| apiService.http = core.http; |
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.
Per our discussion, can we just store the whole of core here. I think that's generally more useful.
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.
have exposed a core via kibana_service.ts https://github.com/elastic/kibana/pull/59881/files#diff-9da56dd30eec66800d99e2aa39faf33e
x-pack/legacy/plugins/uptime/public/state/effects/fetch_effect.ts
Outdated
Show resolved
Hide resolved
| const decoded = OverviewFiltersType.decode(responseData); | ||
|
|
||
| ThrowReporter.report(decoded); | ||
| PathReporter.report(decoded); |
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 do anything? IIRC Throw reporter issues a throw, while PathReporter returns a value like what's shown here: https://github.com/gcanti/io-ts#error-reporters . I don't think we should be making this change, which is unrelated, in this PR.
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.
ThrowReporter is deprecated.
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.
Good to know. That said, I think we'll need throw new Error(PathReporter.report(decoded)) the code as-is just generates a string and throws it away.
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 don't need to throw it, because we are not catching it. We are only checking for errors now.
|
|
||
| const decoded = SnapshotType.decode(responseData); | ||
| ThrowReporter.report(decoded); | ||
| PathReporter.report(decoded); |
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.
Same comment here, let's stick with the ThrowReporter. Let's not mix too many things into one PR unless there's an issue with separating them out.
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 don't need to throw it, because we are not catching it. We are only checking for errors now.
|
|
||
| public async get(apiUrl: string, params: HttpFetchQuery) { | ||
| const response = await this.http!.get(apiUrl, { query: params }); | ||
| if (response instanceof Error) { |
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.
Are we trying to make Kibana's fetch more like window.fetch where errors are thrown instead of returned?
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.
have updated this.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
justinkambic
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.
Left a comment regarding io-ts usage for api requests.
| return ApiService.instance; | ||
| } | ||
|
|
||
| public async get(apiUrl: string, params?: HttpFetchQuery, decodeType?: 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.
I think it would be better to require the decodeType parameter. We could then describe decodeType better than any. If we did something like:
import { Decoder } from 'io-ts'| public async get(apiUrl: string, params?: HttpFetchQuery, decodeType?: any) { | |
| public async get<T>(apiUrl: string, params?: HttpFetchQuery, decoder: Decoder<unknown, T>) { |
In this case, T will be the type we get when isRight is truthy, and unknown is the type we specify for the value we give to PathReporter (which is ok, because decode will return an object of type Either<t.Errors, T> anyway, so the reporter will be happy).
Partial, Type, Intersection, etc., all seem to extend the Decoder interface, so I think this would be a safe assumption for us to make here.
Then, if we define a complex type like:
const MyComplexType = t.intersection([
t.partial({
foo: t.string,
}),
t.type({
bar: t.number,
}),
]);..the usage of the function will remain the same, but our responses will be typed appropriately:
const apiResponse = apiService.get('/api/pathToComplexType', { foo: 'bar' }, MyComplexType);And the resultant object will be typed like:

If we allow the decodeType parameter to be optional, we can only ever guarantee a return type of any; this is more-or-less what we've always done, but the idea of type safety at runtime and "automatic" typing for all API responses sounds very nice to me.
If we feel it's out of the scope of this PR, a tech debt follow-up issue would be ok by me too, if we are agreed this is something we'd want.
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 #60395 to track the addition of this. I think this will be a nice add when we can get to it.
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.
Thank you
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
* master: [NP] Cutover ensureDefaultIndexPattern to kibana_utils (elastic#59895) Closes elastic#60265. Adds Beta badge to service map (elastic#60482) [Visualize] Duplicated query filters in es request (elastic#60106) [ML] Disable functional transform tests Fixes to service map single node banner (elastic#60072) [Uptime] replace fetch with kibana http (elastic#59881) Upgrade @types/node to match Node.js runtime (elastic#60368)
…nless * 'app/painless' of github.com:elastic/kibana: (64 commits) Fix filter scope in bool query (#60488) change index pattern id to be the same as index pattern title (#60436) [Endpoint] resolver v1 events (#59233) Branding fixes for dashboard, loader and space selector (#60073) skip flaky suite (#60535) [SIEM][Detection Engine] Fixes bug with timeline templates not working Fixed errors which are happening if switch between alert types (#60453) [EPM] Add mapping field types to index template generation v2 (#60266) [NP] Cutover ensureDefaultIndexPattern to kibana_utils (#59895) Closes #60265. Adds Beta badge to service map (#60482) [Visualize] Duplicated query filters in es request (#60106) [ML] Disable functional transform tests Fixes to service map single node banner (#60072) [Uptime] replace fetch with kibana http (#59881) Upgrade @types/node to match Node.js runtime (#60368) [License Management] NP migration (#60250) Fix create alert button from not showing in alerts list (#60444) [SIEM][Case] Update connector through flyout (#60307) add data-test-subj where possible on SO management table (#60226) Enforce `required` presence for value/key validation of `recordOf` and `mapOf`. (#60406) ...
* upstream/app/painless: (66 commits) Another i18n issue Fix i18n Fix filter scope in bool query (elastic#60488) change index pattern id to be the same as index pattern title (elastic#60436) [Endpoint] resolver v1 events (elastic#59233) Branding fixes for dashboard, loader and space selector (elastic#60073) skip flaky suite (elastic#60535) [SIEM][Detection Engine] Fixes bug with timeline templates not working Fixed errors which are happening if switch between alert types (elastic#60453) [EPM] Add mapping field types to index template generation v2 (elastic#60266) [NP] Cutover ensureDefaultIndexPattern to kibana_utils (elastic#59895) Closes elastic#60265. Adds Beta badge to service map (elastic#60482) [Visualize] Duplicated query filters in es request (elastic#60106) [ML] Disable functional transform tests Fixes to service map single node banner (elastic#60072) [Uptime] replace fetch with kibana http (elastic#59881) Upgrade @types/node to match Node.js runtime (elastic#60368) [License Management] NP migration (elastic#60250) Fix create alert button from not showing in alerts list (elastic#60444) [SIEM][Case] Update connector through flyout (elastic#60307) ...
…alerting/tls-warning * 'alerting/tls-warning' of github.com:gmmorris/kibana: (33 commits) [ML] Disable functional transform tests Fixes to service map single node banner (elastic#60072) [Uptime] replace fetch with kibana http (elastic#59881) Upgrade @types/node to match Node.js runtime (elastic#60368) [License Management] NP migration (elastic#60250) Fix create alert button from not showing in alerts list (elastic#60444) [SIEM][Case] Update connector through flyout (elastic#60307) add data-test-subj where possible on SO management table (elastic#60226) Enforce `required` presence for value/key validation of `recordOf` and `mapOf`. (elastic#60406) [ML] Re-enabling file upload telemetry (elastic#60418) [NP] Use local helper shortenDottedString for discover (elastic#60271) [Console] Fix for `_settings` and x-pack autocomplete (elastic#60246) Task/host enhancements (elastic#59671) [Search service] Asynchronous ES search strategy (elastic#53538) Index Action - Moved index params fields to connector config (elastic#60349) Edits UI text for ML nodes and job button (elastic#60184) Publish getIsNavDrawerLocked$ method on core chrome service. (elastic#60191) Disabled edit alert button on management ui for non registered UI alert types (elastic#60439) Revert "[Console] Fix bool filter autocompletions and refactor (elastic#60361)" [Console] Fix bool filter autocompletions and refactor (elastic#60361) ...
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
* use kibana http * unused import * fix type * update type * refactor * fix types * fix type * fix type
|
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
1 similar comment
|
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
Summary
Fixes #56894
This PR will replace fetch usage with kibana http.