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] Shim new platform #34531

Merged
merged 3 commits into from
Apr 10, 2019
Merged

Conversation

sorenlouv
Copy link
Member

@sorenlouv sorenlouv commented Apr 4, 2019

Closes #34533

Following the steps in the Migration guide to add shims for new platform

@sorenlouv sorenlouv requested a review from a team as a code owner April 4, 2019 11:08
@elasticmachine
Copy link
Contributor

💔 Build Failed

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.

As far as shimming the new platform I think this is spot on!

Note: I didn't dig into the apm plugin's code itself, so I'll spend some more time looking through the code "downstream" from the shim.

x-pack/plugins/apm/public/new-platform/plugin.tsx Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@jasonrhodes jasonrhodes left a comment

Choose a reason for hiding this comment

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

First pass this looks really good, still on the fence about the singleton approach but can't totally articulate what I'm scared of, just want to think about it a little more today :) Will run the code locally and do some QA later, too.

import { CoreSetup } from 'src/core/public';

export let basePath = {
addToPath: path => `/kbn-basepath${path}`
Copy link
Member

Choose a reason for hiding this comment

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

Do we want this function to have this default?

// Also, non-react functions will not be able to access context - therefore singletons might not be the worst idea
export function _setCoreDependencies(core: CoreSetup) {
basePath = core.basePath;
}
Copy link
Member

Choose a reason for hiding this comment

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

In the long run, I wonder if it'd be "more React-like" for us to work on converting imperative helper methods into declarative components that would then be able to use hooks to get the values from context.

Out of curiosity, how many imperative helpers do we currently have, and how many of them need access to these core deps? I imagine it's mostly the url helper stuff needing basePath, etc.

Copy link
Member

Choose a reason for hiding this comment

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

The more I think about this, the more I think the core services should work the same as location -- seems weird to have location be accessible via context + hook (which also means you can't directly access it from imperative code) and then have these values cached in a singleton. Curious how you all are feeling about it, though?

Copy link
Member Author

@sorenlouv sorenlouv Apr 8, 2019

Choose a reason for hiding this comment

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

I think it makes sense to pass stateful objects (like location) down via context. But I find it a little odd to do the same with methods. But that's probably subjective.

core services should work the same as location

So should we use the singleton approach for everything, or React Context? If we use the latter, how should callApi access kfetch?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, yeah. My first thought is that if kfetch is no longer globally stateful (i.e. the platform isn't setting things on it before providing it to the plugin), then it should just be a separate package we import via npm/yarn. Anything else that's just a stateless method should work the same way, imo, then the rest would be handled via React context. I think we'll need to talk to the platform folks about this...

@weltenwort what is your team thinking wrt to how to handle things like this in the new platform?

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'd definitely importing it statically if that's an option!

Copy link
Member

Choose a reason for hiding this comment

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

While I can't speak for the whole infra monitoring team, I've started to write hooks for such external services (e.g. useKibanaUiSettings('mySetting')) in https://github.com/elastic/kibana/pull/34615/files#diff-5c1aef9186a64f50ff1ef32ee57a92ccR29) to abstract these platform details away.

These hooks can then either get the reference from the context if it needs to be injected or statically import it if possible.

Copy link
Member

Choose a reason for hiding this comment

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

That way the plugin dependencies could be injected with one platformDependencies provider, but fine-grained hooks hide the fact that we're extracting the individual component from one larger object. Not sure if I'm making sense, let me know if you want to discuss it in person after I had my morning tea. 😉

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@jasonrhodes jasonrhodes left a comment

Choose a reason for hiding this comment

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

LGTM

@sorenlouv sorenlouv merged commit 93549e6 into elastic:master Apr 10, 2019
@sorenlouv sorenlouv deleted the apm-shim-new-platform branch April 10, 2019 12:42
sorenlouv added a commit to sorenlouv/kibana that referenced this pull request Apr 10, 2019
sorenlouv added a commit that referenced this pull request Apr 10, 2019
chandlerprall pushed a commit to chandlerprall/kibana that referenced this pull request Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants