-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Core] Deprecate async lifecycles #53268
Comments
Pinging @elastic/kibana-platform (Team:Platform) |
What about a way to access Currently on the server For plugins which have synchronous registries containing items that rely on specific uiSettings, in a // server/plugin.ts
async setup(core, { foo }) {
const dateFormat = await core.uiSettings.get('dateFormat');
// foo.registerSomething is sync
foo.registerSomething(new MyRegistryItem({ dateFormat }));
}
class MyRegistryItem {
constructor({ dateFormat }) {
this.dateFormat = dateFormat;
return ...
}
} |
Tricky thing about this is that UiSettings are stored as a Saved Object, one per space. On the client, we actually cache this document in memory, which is less than ideal, but hasn't caused any major problems since there is only one space active in the browser at a time. The server-side is a bit different since it's serving many spaces simultaneously. That said, a given UiSettingsClient only has access to the specific space it was configured for. I think the simplest option would be to configure a RouteHandlerContextProvider on the server that fetches the UiSettings and configures the service with those settings, all before the route handler executes. This would allow for synchronous access without needing to worry about a complicated caching mechanism. Example: // Register a context provider
core.http.registerRouteHandlerContext('myService', async (context) => {
// Fetch all the settings for this request
const cachedUiSettings = await context.core.uiSettings.client.getAll();
// Wire up MyService with the cached settings for this request
// These can be accessed synchronously by MyService
const myService = new MyService({ uiSettings: cachedUiSettings });
return myService;
});
// Use context API
core.http.createRouter().get(
{ path: '/api/example', validate: false },
async (context, req, res) => {
const thing = context.myService.doThing();
return res.ok({ body: thing });
}
} It's also worth noting that the example above actually isn't valid since we don't expose a |
@lukeelmers do you have a concrete example of where we currently have such a dependency on sync uisettings? It feels like this would create a situation where kibana finishes the |
@rudolf It came to mind as we were working through plans to make the data plugin's aggs infrastructure ( Specifically, different agg types which depend on kibana/src/plugins/data/public/search/search_service.ts Lines 92 to 100 in 008b0fd
Both the registration & creation of the agg type definition occur synchronously. Some of the agg types rely on a value retrieved from kibana/src/plugins/data/public/search/aggs/buckets/filters.ts Lines 54 to 65 in 008b0fd
I'm sure this is something we could refactor around if necessary, but hopefully it illustrates the use case. We have a lot of synchronous registries floating around, and as |
It would work with a couple of limitations:
Yeah, uiSettings can be changed via rest API or another Kibana instance, so we cannot implement an in-memory cache.
@lukeelmers I think @rudolf meant that the use of |
It seems to me like moving On the server-side if we register an aggregation that uses |
Does ES / SO provide ability to emit update events?
|
Thanks for pointing this out, @restrry! I'll investigate further, sounds like a bug we hadn't noticed yet
Yeah, the
|
...he says before forgetting that there already is a |
Not that I'm aware of. We can optimistically emit if we receive a write, but would have to poll to be sure another node didn't perform a write. This would probably have to be rather frequent to be useful, but polling every minute for instance for a document that usually doesn't receive a lot of changes feels like a waste. I'm not sure if it's feasible, but it would be better if we could somehow only read the setting when the service / registry receives an incoming request. That would also make reading these ui settings spaces compatible. |
I'm running into the sync/async uiSettings access issue in some common code. Moving to async access in most places works well. However, field formatters rely on uiSettings values and field formatters can't be async. Therefore its necessary to snapshot uiSettings values and provide them to the formatter. I suspect this will need to happen in a few places and it would be nice to have it provided at the api level. |
Did a new audit today in #74191 to figure how many plugins will require significant changes to drop async lifecycles. Looking very promising! Cross posting my results here:
|
With #88981 merged, core now provides a synchronous API to retrieve the plugin's (and the legacy) configuration. This should unblock most of the plugins. |
Should we create an issue to migrate all the async lifecycles to the sync counterparts? It might be faster if the Core team performs most of the migrations. Afterward, we need to create a meta issue for all the remaining affected solutions and communicate the timeline. |
Yea, I was planning on doing that: try to adapt as many plugins as possible myself, and only then create a meta issue with the remaining unmigrated plugins. Should have the inventory in a few days. Will also change the |
#89562 has been merged. Only two plugins were not migrated to synchronous lifecycle ( I created separate issues for those, and updated the description of this one. |
From Lifecycles RFC: https://github.com/elastic/kibana/blob/6042a01f385078587e8e09418ef07f69ec2dadf7/rfcs/text/0007_lifecycle_unblocked.md
Subtasks
Plugin
interface and introduce the temporaryAsyncPlugin
interface Migrate most plugins to synchronous lifecycle #89562Unmigrated plugins
Plugins that still depend on async behaviour after #89562:
The text was updated successfully, but these errors were encountered: