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

[APM] Replace ui/kfetch with core.http #47635

Merged
merged 5 commits into from
Oct 11, 2019

Conversation

dgieselaar
Copy link
Member

@dgieselaar dgieselaar commented Oct 8, 2019

Closes #46548.

This replaces the static import ui/kfetch with the injected http module from core. To accommodate this, several changes were made:

  • Change callApi's signature from ( options ) to ( http, options ).
  • Expose a useCallApi hook that uses useKibanaCore to get http from context.
  • Change callApmApi to a factory function that needs http. I could not get a similar (http, options) signature to work because I could not extract the type of options from callApmApi, presumably because it is a generic.
  • Expose a useCallApmApi hook, similar to useCallApi.
  • Inject callApmApi as the first argument to the callback passed to useFetcher. I figured this is a little better than using a separate hook because it a) removes the need for an extra import/hook b) avoids the dependency dance for useFetcher.
  • use useFetcher in useApmIndexPattern

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@dgieselaar dgieselaar marked this pull request as ready for review October 9, 2019 08:58
@dgieselaar dgieselaar requested a review from a team as a code owner October 9, 2019 08:58
@dgieselaar dgieselaar requested a review from a team as a code owner October 9, 2019 09:40
Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Small nit on the docs for HttpFetchError but otherwise Platform changes LGTM

@@ -435,6 +433,19 @@ export interface HttpErrorResponse {
response?: Response;
}

// Warning: (ae-missing-release-tag) "HttpFetchError" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add an block comment above the definition of HttpFetchError like:

/*
 * @public 
 */

That will make this warning go away and mark the type as part of the public API

Copy link
Member Author

@dgieselaar dgieselaar Oct 10, 2019

Choose a reason for hiding this comment

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

Fixed. That comment format specifically seemingly did not work, but /** @public */ did.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

environments: []
}
]
} as never);
Copy link
Member

Choose a reason for hiding this comment

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

why never?

Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason TS expects never as a type. I'm probably doing something wrong, but I couldn't figure it out and didn't want to spend too much time fixing types for a test. Do you happen to know what's going on?

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about:

    function getCoreMock(res: HttpBody) {
      return ({
        http: {
          basePath: {
            prepend: (path: string) => `/basepath${path}`
          },
          get: jest.fn(res)
        },
        notifications: {
          toasts: {
            addWarning: () => {}
          }
        }
      } as unknown) as LegacyCoreStart & {
        http: { get: jest.SpyInstance<LegacyCoreStart['http']['get'], any> };
      };
    }

This way the spies are not modified, and the compile error disappears

Copy link
Member Author

Choose a reason for hiding this comment

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

I think my type was just wrong. Simplified to { get: jest.Mock<any,any> } and that works as well.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@dgieselaar
Copy link
Member Author

@sqren I've merged in your changes and did some rudimentary checks that the agent configuration things that you merged in still working, but can you do some surface checks as well just to be sure?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

lgtm. Did some manual testing of agent configs and still works as expected 👍

@dgieselaar dgieselaar merged commit 819f334 into elastic:master Oct 11, 2019
@dgieselaar dgieselaar deleted the replace-kfetch-with-core branch October 11, 2019 14:35
dgieselaar added a commit that referenced this pull request Oct 15, 2019
* [APM] Replace ui/kfetch with core.http

Closes #46548.

* Remove kfetch mocks in tests

* Expose HttpFetchError from src/core/public/index

* Make HttpFetchError public

* Simplify tests for ServiceOverview
@ogupte ogupte self-assigned this Oct 21, 2019
@ogupte ogupte added the apm:test-plan-done Pull request that was successfully tested during the test plan label Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:test-plan-done Pull request that was successfully tested during the test plan release_note:enhancement v7.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] NP migration replace ui/kfetch with core.http
6 participants