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 Anomaly Chart #183456

Merged
merged 40 commits into from
May 27, 2024

Conversation

qn895
Copy link
Member

@qn895 qn895 commented May 14, 2024

Summary

This PR addresses #174966 and migrates Anomaly charts embeddable to the new React architecture.

Adding a new Anomaly chart panel in Dashboard:

Screen.Recording.2024-05-20.at.11.20.14.mov

Saving dashboard with settings like anomaly threshold persisted

Screenshot 2024-05-15 at 23 07 54

Adding a new Anomaly chart to a case

Screenshot 2024-05-15 at 23 08 01

Changes include:

  • Migrate embeddable framework to React rebuild
  • Detach UI create chart action
  • Remove Edit UI action
  • Update case attachment for anomaly charts to no longer need embeddable
  • Changes also include a refactor in how the Anomaly charts update cursor sync data. Previously, when cursor is updated, the whole chart will re-render. The new refactor optimizes so that the chart is rendered only when needed, and the cursor line will update independently.

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@qn895 qn895 added :ml Feature:Embeddables Relating to the Embeddable system v8.15.0 labels May 14, 2024
@qn895 qn895 self-assigned this May 14, 2024
qn895 added 2 commits May 14, 2024 19:00
…bed-migrate

# Conflicts:
#	x-pack/plugins/ml/public/ui_actions/edit_single_metric_viewer_panel_action.tsx
#	x-pack/plugins/ml/public/ui_actions/index.ts
@qn895 qn895 changed the title [ML][Embeddables Rebuild] WIP - Migrate Anomaly Chart [ML][Embeddables Rebuild] Migrate Anomaly Chart May 17, 2024
@qn895
Copy link
Member Author

qn895 commented May 17, 2024

/ci

@qn895 qn895 added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:fix labels May 17, 2024
@qn895
Copy link
Member Author

qn895 commented May 17, 2024

/ci

@qn895
Copy link
Member Author

qn895 commented May 17, 2024

/ci

@qn895 qn895 force-pushed the ml-anomaly-chart-embed-migrate branch from 7d16ae2 to 5aef100 Compare May 17, 2024 19:54
@qn895
Copy link
Member Author

qn895 commented May 21, 2024

Thanks @peteharverson and @alvarezmelissa87 for testing. I've fixed the 'unsaved changes', chart text overflowing/cutting off, and timeout warning in the data report in the latest changes.

Screen.Recording.2024-05-21.at.14.32.53.mov
Screenshot 2024-05-21 at 14 32 40

@@ -62,7 +62,9 @@ export const ExplorerAnomaliesContainer: FC<ExplorerAnomaliesContainerProps> = (
timeRange,
}) => {
return (
<>
// TODO: Remove data-shared-item and data-rendering-count as part of https://github.com/elastic/kibana/issues/179376
Copy link
Member Author

@qn895 qn895 May 21, 2024

Choose a reason for hiding this comment

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

Note for reviewers: Leaving this here as todo for future when referenced Kibana issue is closed

const factory: ReactEmbeddableFactory<
AnomalyChartsEmbeddableState,
AnomalyChartsEmbeddableApi,
AnomalyChartsEmbeddableState
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You don't need this third type argument. The runtime state type defaults to the same as the serialized state.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the hint. Updated here 1ed16a4

}
);

const appliedTimeRange$: Observable<TimeRange | undefined> = combineLatest({
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes this is very true. Ideally fetch$ can simplify this code quite a lot!

@alvarezmelissa87
Copy link
Contributor

Confirmed everything is working as expected now except the text overflow only in dashboard and only when it's multiple charts.
image

The pdf/png export appears to be working but, as with other embeddables, seeing the completed with issues warning.
image
This might require more digging and should be okay to do in a follow up as it's an existing issue.

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 change and LGTM.

Comment on lines 135 to +138
const isMaxSeriesToPlotValid =
maxSeriesToPlot >= 1 && maxSeriesToPlot <= MAX_ANOMALY_CHARTS_ALLOWED;
typeof maxSeriesToPlot === 'number' &&
maxSeriesToPlot >= 1 &&
maxSeriesToPlot <= MAX_ANOMALY_CHARTS_ALLOWED;
Copy link
Contributor

Choose a reason for hiding this comment

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

did you consider using numberValidator?

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

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

Latest changes LGTM ⚡

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.

Changes LGTM! Thank you for using the fetch$ interface. Left a few questions / nits.

const timeRange$ = useMemo(
() => new BehaviorSubject(initialState.timeRange),
// eslint-disable-next-line react-hooks/exhaustive-deps
[initialState.timeRange?.from, initialState.timeRange?.to]
Copy link
Contributor

Choose a reason for hiding this comment

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

here we're creating a new behaviour subject every time the initialState timeRange changes? Instead, why not just .next the existing subject when those change?

Copy link
Member Author

Choose a reason for hiding this comment

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

We actually don't need this anymore so I've removed it here 34c2e07

return combined;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Because we've disabled exhaustive deps here, this component will not respond at all to changes in filters or query. Is this intentional?

If not, I'd suggest using a useEffect that updates these values with .next whenever the reactive variables change.

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 the purpose for this attachment to case UI, the chart is static, not changing, and is rendered based on the initial state only. The query or filters don't and should not be be updated, so initializing these behaviors upon mounting is ok.

@qn895
Copy link
Member Author

qn895 commented May 26, 2024

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
ml 4.2MB 4.1MB -101.9KB

Page load bundle

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

id before after diff
ml 80.1KB 80.1KB -28.0B
Unknown metric groups

async chunk count

id before after diff
ml 106 105 -1

ESLint disabled line counts

id before after diff
ml 549 556 +7

References to deprecated APIs

id before after diff
ml 37 35 -2

Total ESLint disabled count

id before after diff
ml 552 559 +7

History

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

cc @qn895

@qn895 qn895 merged commit d901467 into elastic:main May 27, 2024
18 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 27, 2024
rshen91 pushed a commit to rshen91/kibana that referenced this pull request May 30, 2024
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:Embeddables Relating to the Embeddable system :ml project:embeddableRebuild release_note:skip Skip the PR/issue when compiling release notes v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants