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

[ML][Embeddables Rebuild] Migrate Change Point Charts embeddable #182246

Merged
merged 25 commits into from
May 13, 2024

Conversation

darnautov
Copy link
Contributor

@darnautov darnautov commented May 1, 2024

Summary

Closes #174963

  • Decouples UI actions from the embeddable framework
  • Removes custom Edit action and makes use of the default one
  • Adds Add action
  • Migrates Change point detection charts to the react embeddable registry
  • Replaces the modal for initializing and editing embeddable config with the flyout
image

Checklist

@darnautov darnautov added :ml release_note:skip Skip the PR/issue when compiling release notes Team:ML Team label for ML (also use :ml) Feature:ML/AIOps ML AIOps features: Change Point Detection, Log Pattern Analysis, Log Rate Analysis v8.15.0 labels May 1, 2024
@darnautov darnautov self-assigned this May 1, 2024
@darnautov darnautov marked this pull request as ready for review May 2, 2024 15:51
@darnautov darnautov requested a review from a team as a code owner May 2, 2024 15:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested and LGTM. Agree about renaming the embeddable folder and just spotted the typo in the filename.

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Great work! It's really nice to see more embeddable conversions coming along!

Left a few nits and comments.

const blockingError = new BehaviorSubject<Error | undefined>(undefined);

const dataViews$ = new BehaviorSubject<DataView[] | undefined>([
await deps.data.dataViews.get(state.dataViewId),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if you're storing a dataViewId, it should really be stored as a reference. This is so that if a user exports the Dashboard, the data view used in your change point chart is exported as well. You can take a look at examples/embeddable_examples/public/react_embeddables/field_list/field_list_react_embeddable.tsx to see how to accomplish this.

Copy link
Contributor Author

@darnautov darnautov May 13, 2024

Choose a reason for hiding this comment

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

Added in 9323cbf

api.partitions
);

const reload$ = useMemo(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a neat way to translate the fetch pipe into a lastReloadRequestTime. If this ends up being a common pattern, we could make a helper for it - something like useFetch(api) - which would return all of the fetch context as reactive vars.


let embeddingOrigin;
if (apiHasExecutionContext(parentApi)) {
embeddingOrigin = parentApi.executionContext.type;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering why you're using the executionContext type here instead of the parentApi.type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question, are there any differences/preferences for that?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have formal best practices around this, but I think the execution context should really only be used for things that are related to data. Like the inspector, telemetry etc. For any other reason - checking if something is rendered on Dashboard etc, the Embeddable parent type should be used.

tagging @nreese for some discussion here.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree. Use parentApi.type if you need to identify the parent


export async function resolveEmbeddableChangePointUserInput(
coreStart: CoreStart,
pluginStart: AiopsPluginStartDeps,
input?: EmbeddableChangePointChartInput
): Promise<EmbeddableChangePointChartExplicitInput> {
input?: ChangePointEmbeddableState
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to rename this file? ExplicitInput is a concept that is very much tied to the old system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed in 9323cbf

const { overlays } = coreStart;

return new Promise(async (resolve, reject) => {
try {
const modalSession = overlays.openModal(
const flyoutSession = overlays.openFlyout(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: If you're opening a flyout, you can let the Dashboard know. This allows the Dashboard to blur other panels, disable buttons on the top of the page, and close the flyout if the user navigates away.

You can do this with the following code:

if (apiHasParentApi(api) && tracksOverlays(api.parentApi)) {
  api.parentApi.openOverlay(overlay, { focusedPanelId: api.uuid });
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 585cfae

x-pack/plugins/aiops/public/embeddables/index.ts Outdated Show resolved Hide resolved
onRenderComplete?: () => void;
}>;

export interface ChangePointComponentApi {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: every item you put in here is completely exposed to any other panel or action in the page's context. This isn't necessarily bad, but I'd recommend trying to avoid putting internal state management details on the embeddable's API if possible.

This can be accomplished by passing these things down as props, or by passing a separate stateManager object. You can even pass these things to an editor etc internally without having them on the external API.

maxSeriesToPlot?: number;
}

export type ChangePointEmbeddableRuntimeState = ChangePointEmbeddableState &
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are the time range and titles only part of the runtime state? Usually these would be part of the SerializedState because custom panel time ranges and panel titles are saved into the Dashboard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in 9d47fe5

@darnautov darnautov requested a review from a team as a code owner May 13, 2024 09:59
Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested latest styling changes (resize of charts, focus for panel when being edited) and LGTM

@darnautov darnautov enabled auto-merge (squash) May 13, 2024 14:02
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
aiops 492 543 +51

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
aiops 422.6KB 436.0KB +13.4KB
ml 4.2MB 4.2MB +4.0KB
total +17.4KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
aiops 7.3KB 7.1KB -214.0B
Unknown metric groups

async chunk count

id before after diff
aiops 18 23 +5

ESLint disabled line counts

id before after diff
aiops 25 26 +1

References to deprecated APIs

id before after diff
aiops 6 4 -2

Total ESLint disabled count

id before after diff
aiops 25 26 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @darnautov

@darnautov darnautov merged commit bbd1017 into elastic:main May 13, 2024
18 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 13, 2024
@darnautov darnautov deleted the ml-174963-change-point-refactor branch May 13, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:ML/AIOps ML AIOps features: Change Point Detection, Log Pattern Analysis, Log Rate Analysis :ml release_note:skip Skip the PR/issue when compiling release notes Team:ML Team label for ML (also use :ml) v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Embeddables Rebuild] Migrate Change Point Chart
9 participants