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] Data frame analytics: Adds map view #81666

Merged

Conversation

alvarezmelissa87
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 commented Oct 26, 2020

Summary

Meta issue with screenshots: #75295
Please add any feedback to the meta issue. Thank you!

This PR is the first part of the map view addition. Items addressed in this PR are the checked items in the meta issue above. Known issues are also included in the meta issue.

image

Includes fixes for issues found in original draft PR #76952

Delete action in flyout is temporarily commented out and will be addressed in a followup.

Checklist

Delete any items that are not applicable to this PR.

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-dfanalytics-map-view branch 2 times, most recently from 25ed802 to 5c69dc7 Compare October 29, 2020 16:28
@alvarezmelissa87 alvarezmelissa87 changed the title WIP: [ML] DF Analytics Map view [ML] DF Analytics Map view: Part one Oct 29, 2020
@peteharverson
Copy link
Contributor

peteharverson commented Oct 30, 2020

Opening the map off an outlier job created from a transform on the gallery data set, I always see this error:

image


Response from @alvarezmelissa87 --

@peteharverson I was not able to reproduce this so far. I can add it as a known issue to the meta issue and keep trying.

@peteharverson peteharverson mentioned this pull request Oct 30, 2020
48 tasks
@peteharverson
Copy link
Contributor

Are these arrows correct on here? I expected the gallery_clientip_outliers3 index pattern to come out of the outliers job node.

image

If I 'fetch related nodes' for the gallery_clientip_outliers2 node, it then rearranges to give the layout I expected:

image

x-pack/plugins/ml/common/constants/data_frame_analytics.ts Outdated Show resolved Hide resolved
const keys = Object.keys(analysis || {});

if (keys.length === 1) {
return keys[0] as DataFrameAnalysisConfigType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth checking the actual key value instead of typecasting?

}

export const MapButton: FC<MapButtonProps> = ({ item }) => {
const toolTipContent = i18n.translate(
Copy link
Contributor

Choose a reason for hiding this comment

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

should be defined inside of the disabled condition

boxSelectionEnabled: false,
maxZoom: 3,
minZoom: 0.2,
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

quite some @ts-ignore here 🤔 . is it possible to avoid it? or at least specify the reason

Comment on lines +24 to +29
// if (isDataFrameAnalyticsFailed(d.stats.state)) {
// await ml.dataFrameAnalytics.stopDataFrameAnalytics(d.config.id, true);
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

commented code

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Nov 2, 2020

Choose a reason for hiding this comment

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

The delete functionality will be added in in a follow up as it requires some refactoring and I'm trying to keep this PR from getting too big.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense trying to keep the PR concise! But I believe we should not commit commented code. You can always stash it locally. This article provides an explanation of why, and there are plenty of others

import React, { FC } from 'react';
import { EuiButton } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { ml } from '../../../../services/ml_api_service';
Copy link
Contributor

Choose a reason for hiding this comment

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

please use

  const {
    services: {
      mlServices: { mlApiServices },
    },
  } = useMlKibana();

instead of a static import

</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="xs" color="subdued">
{'inference model'}
Copy link
Contributor

Choose a reason for hiding this comment

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

should we provide a translation for this string?

Copy link
Contributor

Choose a reason for hiding this comment

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

As above, this should probably be 'trained model'. As @darnautov mentioned, do these legend labels need translations?

import { useRef } from 'react';
import { useWindowSize } from 'react-use';

export function useRefDimensions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

useRefDimensions seems like a misleading name for this hook. And I'm not sure if you need it at all.
Have you tried to use EuiResizeObserver instead?

import { Cytoscape, Controls, JobMapLegend } from './components';
import { ml } from '../../../services/ml_api_service';
// TODO: don't use dep cache - switch to hook
import { getToastNotifications } from '../../../util/dependency_cache';
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, please use toastNotifications from the hook :)

Comment on lines +209 to +249
while (complete === false) {
count++;
if (count >= 100) {
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For the fixed amount of iterations, a for loop is used

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Nov 2, 2020

Choose a reason for hiding this comment

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

The problem is we don't know how many iteration we need since we're working backwards from the job/model id. We need to keep going until we've hit the source index/transform. The count is just to protect against infinite loops in case something changes or a new case is introduced that we haven't accounted for yet. The 100 limit is just an arbitrary value right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

for loop also supports the break statement.

if (currentElem !== undefined && nextElem !== undefined) {
result.elements.push({
data: {
id: `${currentElem.data.id}~${nextElem.data.id}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you use ~ as a separator here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a way to denote that the edge connects one node id to another node id. It doesn't have any particular significance.

export type MapElements = AnalyticsMapNodeElement | AnalyticsMapEdgeElement;
export interface AnalyticsMapReturnType {
elements: MapElements[];
details: object; // transform, job, or index details
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please specify it as a union type instead?

mlLicense.fullLicenseAPIGuard(async ({ client, request, response }) => {
try {
const { analyticsId } = request.params;
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to avoid this @ts-ignore

@darnautov
Copy link
Contributor

image
shall we wrap JSON with https://elastic.github.io/eui/#/editors-syntax/code#code-block ?

@darnautov
Copy link
Contributor

darnautov commented Nov 2, 2020

Noticed this bug when I can't open the flyout again after I closed it
Nov-02-2020 11-49-05


Response from @alvarezmelissa87 - This has been added to the meta issue.

@darnautov
Copy link
Contributor

darnautov commented Nov 2, 2020

  • I've noticed "Refresh" indicator keeps spinning
  • Should we support a dark theme?
  • There are 2 scroll bars appear on the page

image


@darnautov - thanks for taking a look! 👍 The refresh indicator stuck in loading has been fixed. I've removed it as we don't need it for the job map. bc2b0f82f908f3958c99ca90d3e5da46f1356b9e

What browser are you using when you see the double scroll bars?

Yes, dark theme support is a good point - I'll add that as an item in the meta issue.

@darnautov
Copy link
Contributor

Regarding the dark theme, check the APM Service Map for inspiration
image

@darnautov
Copy link
Contributor

@alvarezmelissa87 Also worth checking why bundle size has been increased by 1.4MB. webpack-bundle-analyzer is a great tool for that

@walterra
Copy link
Contributor

walterra commented Nov 2, 2020

Great work, users can really benefit from getting an overview how all their resources rely to each other!

I noticed this layout problem when's there's lots of jobs based off the same source index:

image

Could this maybe improved by making the layout horizontal so that the labels don't overlap on the same line?

It also look like there's an issue with the graphs height, it overflows the panels bottom.

@walterra
Copy link
Contributor

walterra commented Nov 2, 2020

I'm seeing these warnings in dev console:
image


@walterra - thanks for taking a look! 😄 This is an item in the meta issue (near the bottom under Known Issues) and will be addressed in a follow up once the default icon is available.

@walterra
Copy link
Contributor

walterra commented Nov 2, 2020

Design Nits:

  • Suggest to tweak the padding of the legend to not stick to the bottom
  • Or make the legend background white, then the padding should be fine
  • The nodes of the graph have a white fill, the legend items don't have that

image

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-dfanalytics-map-view branch 2 times, most recently from 1bafe2e to 725ef83 Compare November 4, 2020 20:13
export const JOB_MAP_NODE_TYPES = {
ANALYTICS: 'analytics',
TRANSFORM: 'transform',
INDEX_PATTERN: 'index-pattern',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the map actually looking for Kibana index patterns, or Elasticsearch indexes? Wondering as I deleted the outliers-clientip-03 index pattern here, but the node still shows up on the map. Maybe the legend should be labelled as index rather than index-pattern ?

image

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Nov 6, 2020

Choose a reason for hiding this comment

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

Oh good catch - it's the index - I've updated it to reflect that 👍 bc2b0f82f908f3958c99ca90d3e5da46f1356b9e

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-dfanalytics-map-view branch 2 times, most recently from bc2b0f8 to 05273b8 Compare November 10, 2020 17:31
ANALYTICS: 'analytics',
TRANSFORM: 'transform',
INDEX: 'index',
INFERENCE_MODEL: 'inferenceModel',
Copy link
Contributor

Choose a reason for hiding this comment

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

'Trained model' is the term we are generally using now, so should probably rename these to be consistent.

display: 'inline-block';
}

.mlJobMapLegend__inferenceModel {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might need renaming to trainedModel if you switch 'inference model' node type to 'trained model' - see above.

</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="xs" color="subdued">
{'inference model'}
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, this should probably be 'trained model'. As @darnautov mentioned, do these legend labels need translations?

@alvarezmelissa87 alvarezmelissa87 changed the title [ML] DF Analytics Map view: Part one [ML] Data frame analytics: Adds map view Nov 12, 2020
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 edits and LGTM.

Happy for the layout issue when the map is a single row of nodes to be done in a follow-up. For now, it is easy enough for the user to drag the selection into the middle of the view.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
ml 1242 1558 +316

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.5MB 5.2MB ⚠️ +732.2KB

Distributable file count

id before after diff
default 42793 42800 +7

Page load bundle

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

id before after diff
ml 66.0KB 66.8KB +885.0B

History

  • 💚 Build #87257 succeeded 853be2f7915cc08c1e01db13065f4ae1334b948e
  • 💚 Build #87157 succeeded 05273b8b2d2a2e51bc5ec0dec9c2351b6e8524c7
  • 💚 Build #87152 succeeded bc2b0f82f908f3958c99ca90d3e5da46f1356b9e
  • 💔 Build #86533 failed bf4250c869540c2a11e8d6563b363b838ce271d6
  • 💔 Build #86498 failed 2b98ae971388bcaeb53ff7eda0d0d48c25869d3f

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

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.

LGTM

@alvarezmelissa87 alvarezmelissa87 merged commit 6519b83 into elastic:master Nov 12, 2020
alvarezmelissa87 added a commit that referenced this pull request Nov 12, 2020
* add analytics map endpoint and server model

* add map action to job and models list

* wip:fetch models for jobs. Use url generator

* get models when extending node. deduplicate elements

* add job type icons. disable map action if job not finished.

* move shared const to common dir

* persist map tab. handle indexPattern from visualizer

* use url generator in models list

* temporarily disable delete action in flyout

* update legend style. make map horizontal

* update dfa model to use spaces changes

* format creation time

* update from indexPattern to index.remove refresh button

* handle index patterns with wildcard
@alvarezmelissa87 alvarezmelissa87 deleted the ml-dfanalytics-map-view branch November 12, 2020 20:01
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 16, 2020
* master:
  [Security Solution][Detections] Adds framework for replacing API schemas (elastic#82462)
  [Enterprise Search] Share Loading component (elastic#83246)
  Consolidates Jest configuration files and scripts (elastic#82671)
  APM header changes (elastic#82870)
  [Security Solutions] Adds a default for indicator match custom query of *:* (elastic#81727)
  [Security Solution] Note 10k object paging limit on Endpoint list (elastic#82889)
  [packerCache] fix gulp usage, don't archive node_modules (elastic#83327)
  Upgrade Node.js to version 12 (elastic#61587)
  [Actions] Removing placeholders and updating validation messages on connector forms (elastic#82734)
  [Fleet] Rename ingest_manager_api_integration tests fleet_api_integration (elastic#83011)
  [DOCS] Updates Discover docs (elastic#82773)
  [ML] Data frame analytics: Adds map view (elastic#81666)
  enables actions scoped within the stack to register at Basic license (elastic#82931)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants