-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Embeddable telemetry and reference extraction/injection #74352
Conversation
Pinging @elastic/kibana-app-arch (Team:AppArch) |
412dfc9
to
28b78c7
Compare
28b78c7
to
9192a0a
Compare
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.
Just picked around during our meeting ( when you presented it )
Will try to play and understand a bit later.
We have this one place where we do migration for dashboard drilldown:
https://github.com/elastic/kibana/blob/master/x-pack/plugins/embeddable_enhanced/public/embeddables/embeddable_action_storage.ts#L122
Should we try to refactor it to use new approach in this pr?
src/plugins/embeddable/public/lib/embeddables/default_embeddable_factory_provider.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/ui_actions_enhanced/public/drilldowns/drilldown_definition.ts
Outdated
Show resolved
Hide resolved
src/plugins/embeddable/public/lib/embeddables/embeddable_factory.ts
Outdated
Show resolved
Hide resolved
Can you add tests for migrating base, extended and enhanced state? |
}; | ||
} | ||
|
||
public stop() {} | ||
|
||
private migrateEmbeddableInput = (input: Serializable) => { | ||
const enhancements: Record<string, any> = (input as any).enhanecemnts || {}; | ||
const factory = this.getEmbeddableFactory((input as SerializableRecord).id as string); |
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.
input.id != type - this won't work.
I think the migrate function will have to ask for type, separate from input.
This is generally inline with my thinking. Few things though:
Example: migrate(state: unknown, version: number) {
if (version === 1 && isValid1State(state)) {
return state;
} else if (version === 0 && isValid0State(state)) {
return migrateBarChart0(state);
} else {
throw new Error("Invalid state");
}
}
}
|
9192a0a
to
3408f1d
Compare
7f06f38
to
60cf0b1
Compare
@elasticmachine merge upstream |
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,
thanks for addressing latest feedback and merging clean up pr
P.S.: not sure why CI is going crazy. I assume small ts export / reexport mistake
@@ -4,10 +4,11 @@ | |||
* you may not use this file except in compliance with the Elastic License. | |||
*/ | |||
|
|||
export interface UrlDrilldownConfig { | |||
// eslint-disable-next-line |
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.
// disable can be also remove?
@@ -9,7 +9,8 @@ import { ApplyGlobalFilterActionContext } from '../../../../../src/plugins/data/ | |||
|
|||
export type ActionContext = ApplyGlobalFilterActionContext; | |||
|
|||
export interface Config { | |||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions |
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 also worth disabling this rule for ui_actions_enhanced_examples
be0a8dd
to
43438c3
Compare
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 few more comments. Especially the ones about ts-ignore
and the way telemetry
works should be addressed before merging this
@@ -44,7 +45,8 @@ export interface EmbeddableFactory< | |||
TEmbeddableOutput | |||
>, | |||
TSavedObjectAttributes extends SavedObjectAttributes = SavedObjectAttributes | |||
> { | |||
// @ts-ignore |
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 is worrying in such a basic type - can we avoid it to make sure we don't introduce actually wrong types here in the future?
return { | ||
telemetry: this.telemetry, | ||
extract: this.extract, | ||
inject: this.inject, |
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 can probably live without it for now, but as Tim mentioned once we have migrations on that level we also need to add them on the server as well and migrate everything before fetching telemetry
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.
adding migrations is the next step for this which will be done in a followup
|
||
telemetryBaseEmbeddableInput(state, telemetryData); | ||
if (factory) { | ||
factory.telemetry(state, telemetryData); |
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 implementation seems strange to me - telemetry
returns an updated telemetryData
object, but we are simply discarding and probably assume the passed in object will be mutated.
I really don't like relying on object reference here and mutation the object passed into the function. This is not how reduce is typically implemented - can we make telemetry
return a new object with added information instead of mutating the existing one? This can lead to hard to catch bugs.
id: 'dynamicActions', | ||
telemetry: (state: SerializableState, telemetry: Record<string, any>) => { | ||
(state as DynamicActionsState).events.forEach((event: SerializedEvent) => { | ||
if (uiActionsEnhanced.getActionFactory(event.action.factoryId)) { |
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.
nit: Can be shortened to
uiActionsEnhanced.getActionFactory(event.action.factoryId)?.telemetry(event, telemetry);
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.
that might assign void to telemetryData
): EnhancementRegistryDefinition => { | ||
return { | ||
id: 'dynamicActions', | ||
telemetry: (state: SerializableState, telemetryData: Record<string, 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.
No strong opinion, just interested - why did you keep the telemetry
API on the client even if it's not used?
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.
so we can keep the same persistable state definition type on both sides
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💚 Build SucceededBuild metrics@kbn/optimizer bundle module count
page load bundle size
distributable file count
History
To update your PR or re-run it, just comment with: |
Summary
adds
.telemetry
.extract
and.inject
functions to embeddable service, which can take in any embeddable input and perform associated action on it.embeddable service exposes
.telemetry
.inject
and.extract
function which then:same set of function was also added to dynamic actions registry:
As we need this functionality on the server as well and embeddable plugin and uiActionEnhanced plugins didn't have server contract until now, that was added as well, together with all the mentioned registried and functions.
note that telemetry/extract/inject functions were not added for any embeddable and should be done as a followup. most of them also have nested state dependency tree (for example visualize embeddable will need to check visualizations registry (which will need to provide all above functions, as well as every visualization registered), and some visualizations will need to go further like getting search source functions, which in turn shall get filter, query and timerange functions.
Checklist
Delete any items that are not applicable to this PR.
For maintainers