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] Single Metric Viewer embeddable: add open and edit panel actions #179364

Merged

Conversation

alvarezmelissa87
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 commented Mar 25, 2024

Summary

Part of #176651

This PR:

  • adds the 'Open in Single Metric Viewer' and 'Edit' panel actions to the Single Metric Viewer embeddable for dashboards.
  • detector index fix moved to separate PR

Screen shots

image

Checklist

Delete any items that are not applicable to this PR.

@alvarezmelissa87 alvarezmelissa87 changed the title Ml smv embeddable enhancements [ML] Single Metric Viewer embeddable: add open and edit panel actions Mar 25, 2024
Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

Code LGTM, also tested this with some datasets.

@walterra
Copy link
Contributor

/ci

@alvarezmelissa87 alvarezmelissa87 marked this pull request as ready for review March 28, 2024 01:25
@alvarezmelissa87 alvarezmelissa87 requested a review from a team as a code owner March 28, 2024 01:25
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@alvarezmelissa87
Copy link
Contributor Author

@elasticmachine merge upstream

@alvarezmelissa87
Copy link
Contributor Author

alvarezmelissa87 commented Mar 28, 2024

Did a bit of refactoring to fully decouple actions from old embeddable system and fixed a bug where the selectedDetectorIndex wasn't being passed correctly in a separate PR - I'll update this PR after the fix has gone in. This is ready for another test and look when you get a chance 🙏
cc @darnautov, @walterra

Comment on lines +53 to +68
const isTimeBasedIndex: boolean = selectedDataView.isTimeBased();

useEffect(() => {
if (!isTimeBasedIndex) {
toasts.addWarning({
title: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationTitle', {
defaultMessage: 'The data view {dataViewIndexPattern} is not based on a time series',
values: { dataViewIndexPattern: selectedDataView.getIndexPattern() },
}),
text: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationDescription', {
defaultMessage: 'Anomaly detection only runs over time-based indices',
}),
});
}
}, [isTimeBasedIndex, selectedDataView, toasts]);

Copy link
Contributor

@darnautov darnautov Apr 2, 2024

Choose a reason for hiding this comment

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

nit: can be simplified even further, preventing access to the isTImeBased method on each render!

Suggested change
const isTimeBasedIndex: boolean = selectedDataView.isTimeBased();
useEffect(() => {
if (!isTimeBasedIndex) {
toasts.addWarning({
title: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationTitle', {
defaultMessage: 'The data view {dataViewIndexPattern} is not based on a time series',
values: { dataViewIndexPattern: selectedDataView.getIndexPattern() },
}),
text: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationDescription', {
defaultMessage: 'Anomaly detection only runs over time-based indices',
}),
});
}
}, [isTimeBasedIndex, selectedDataView, toasts]);
useEffect(function warnNonTimeSeriesData() {
if (!selectedDataView.isTimeBased()) {
toasts.addWarning({
title: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationTitle', {
defaultMessage: 'The data view {dataViewIndexPattern} is not based on a time series',
values: { dataViewIndexPattern: selectedDataView.getIndexPattern() },
}),
text: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationDescription', {
defaultMessage: 'Anomaly detection only runs over time-based indices',
}),
});
}
}, [selectedDataView, toasts]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a reliance on the isTimeBasedIndex variable a few lines down - I considered wrapping in a useEffect but I think the addition of the function would negate any small optimization we'd get from that, in my opinion. Happy to discuss further if you feel strongly. 😄

@@ -14,7 +14,7 @@ import type { JobId, CombinedJob } from '../../../common/types/anomaly_detection
*/
export function getControlsForDetector(
selectedDetectorIndex: number,
selectedEntities: Record<string, any>,
selectedEntities: Record<string, any> | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please use the MlEntityField type instead of any

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Apr 2, 2024

Choose a reason for hiding this comment

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

Went back to double check and the original Record<string, any> type is correct - went back to ensure the types are correct. All types should now be correct. Updated in c39b883

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think any is correct. If you don't know the incoming type - it should be unknown and covered with a type guard. Otherwise you should be aware of the expected type.

this.jobId = embeddableInputToSubject<JobId, SingleMetricViewerEmbeddableInput>(
this.apiSubscriptions,
this,
'jobId'
Copy link
Contributor

Choose a reason for hiding this comment

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

With the already released embeddable version in 8.13, you need to provide backward compatibility.
The input prop used to be named jobIds and contained an array of strings instead of a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR has a change in single_metric_viewer_setup_flyout.tsx which resolves the array to a string when setting up the panel jobId: jobIds[0],.

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 call! Going to keep the original API for now to prevent any issues c39b883

Comment on lines 86 to 90
this.title = embeddableInputToSubject<string, SingleMetricViewerEmbeddableInput>(
this.apiSubscriptions,
this,
'title'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

title is a common prop and is handled by the embeddable framework

Suggested change
this.title = embeddableInputToSubject<string, SingleMetricViewerEmbeddableInput>(
this.apiSubscriptions,
this,
'title'
);

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Apr 2, 2024

Choose a reason for hiding this comment

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

Yes, it can be handled via Panel settings but is also editable when using the Edit panel action that has been added.
When converting to the new framework, this will be removed, but right now it's still handled by the edit action.
I will remove this when refactoring to the new framework in a follow up PR to ensure full functionality at every step.

Copy link
Contributor

Choose a reason for hiding this comment

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

Anomaly swim lane has exactly the same - editable via Panel settings and Edit panel actions, but it does not duplicate title API.

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 call - removed in c39b883

@alvarezmelissa87
Copy link
Contributor Author

This has been updated and is ready for a final look/test when you get a chance, cc @walterra, @darnautov

@alvarezmelissa87
Copy link
Contributor Author

@elasticmachine merge upstream

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 changes and LGTM

@@ -14,7 +14,7 @@ import type { JobId, CombinedJob } from '../../../common/types/anomaly_detection
*/
export function getControlsForDetector(
selectedDetectorIndex: number,
selectedEntities: Record<string, any>,
selectedEntities: Record<string, any> | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think any is correct. If you don't know the incoming type - it should be unknown and covered with a type guard. Otherwise you should be aware of the expected type.

Copy link
Contributor

@darnautov darnautov 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, thanks for improving types!

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #10 / useGetCaseUsers calls the api when invoked with the correct parameters

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
ml 1974 1976 +2

Async chunks

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

id before after diff
ml 3.7MB 3.7MB +3.1KB

History

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

cc @alvarezmelissa87

@alvarezmelissa87 alvarezmelissa87 merged commit 339e24f into elastic:main Apr 4, 2024
17 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Apr 4, 2024
@alvarezmelissa87 alvarezmelissa87 deleted the ml-smv-embeddable-enhancements branch April 4, 2024 17:27
alvarezmelissa87 added a commit that referenced this pull request Apr 5, 2024
… set correctly for 'Open' action (#180086)

## Summary

Follow up to #179364

This PR ensures the detector index is set correctly the url in the `Open
in single metric viewer` action to link from dashboards to ML > Single
metric viewer.

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
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:Anomaly Detection ML anomaly detection :ml release_note:enhancement v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants