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] DFA: ensure at least one field is included in analysis before job can be created #65320

Merged

Conversation

alvarezmelissa87
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 commented May 5, 2020

Summary

Fixes #64783

Checks the field_selection return from the _explain api to ensure that there is at least one other field included that is not also required.

If there is not at least one field available for the analysis creation will be disabled and user will see an error message.

image

Checklist

Delete any items that are not applicable to this PR.

@alvarezmelissa87 alvarezmelissa87 requested a review from a team as a code owner May 5, 2020 17:59
@alvarezmelissa87 alvarezmelissa87 self-assigned this May 5, 2020
@alvarezmelissa87 alvarezmelissa87 changed the title ensure at least one field besides depVar included in analysis [ML] DFA: ensure at least one field is included in analysis before job can be created May 5, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

Copy link
Member

@jgowdyelastic jgowdyelastic 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

@@ -48,6 +48,8 @@ import {
} from '../../../../common/analytics';
import { shouldAddAsDepVarOption, OMIT_FIELDS } from './form_options_validation';

const requiredFieldsErrorText = 'At least one field must be included in the analysis.';
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be internationalized.

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 592d875

@@ -565,7 +587,9 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
<Fragment>
<EuiFormRow
fullWidth
isInvalid={maxDistinctValuesError !== undefined}
isInvalid={
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it might make more sense to show the invalid field warning below the 'Excluded fields' control, as it's most likely to appear when the user selects too many fields to exclude?

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 May 6, 2020

Choose a reason for hiding this comment

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

🤔 Good point, @peteharverson. Updated in 592d875

const fieldSelection: FieldSelectionItem[] = resp.field_selection;

let hasRequiredFields = false;
if (fieldSelection) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this if part necessary? Asking because the assignment looks like it will always be an array. Maybe this whole part can even become something like:

const hasRequiredFields = resp.field_selection.some(field => field.is_included === true && field.is_required === false);

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 May 6, 2020

Choose a reason for hiding this comment

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

Wrapping in an if statement is mostly an extra safety precaution for something going wrong silently in the backend or changes to it that would make field_selection undefined. Looking at the docs, there doesn't seem to be a guarantee that that field will always be populated. The for loop prevents us from having to create a function on every go through. Though in this case the optimization is probably not significant. 🤔

I think for now I'd lean toward keeping it though I'm happy to update if you feel strongly (the readability is a bit better with your suggestion)

Copy link
Contributor

@walterra walterra May 7, 2020

Choose a reason for hiding this comment

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

Thanks for clarifying! Maybe we can then update the response type DfAnalyticsExplainResponse to something like field_selection?: FieldSelectionItem[]; so TypeScript will force us to consider that the field could be not returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Type updated in 4477264

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

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.

LGTM pending the discussed TS update

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@alvarezmelissa87 alvarezmelissa87 merged commit 034f259 into elastic:master May 7, 2020
alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request May 7, 2020
…b can be created (elastic#65320)

* ensure at least one field besides depVar included in analysis

* show requiredFieldsError above excluded fields

* update jest test

* update fieldSelection explainResponse type
alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request May 7, 2020
…b can be created (elastic#65320)

* ensure at least one field besides depVar included in analysis

* show requiredFieldsError above excluded fields

* update jest test

* update fieldSelection explainResponse type
@alvarezmelissa87 alvarezmelissa87 deleted the ml-analytics-index-check branch May 7, 2020 20:57
alvarezmelissa87 added a commit that referenced this pull request May 8, 2020
…b can be created (#65320) (#65773)

* ensure at least one field besides depVar included in analysis

* show requiredFieldsError above excluded fields

* update jest test

* update fieldSelection explainResponse type
alvarezmelissa87 added a commit that referenced this pull request May 8, 2020
…b can be created (#65320) (#65774)

* ensure at least one field besides depVar included in analysis

* show requiredFieldsError above excluded fields

* update jest test

* update fieldSelection explainResponse type
jloleysens added a commit to jloleysens/kibana that referenced this pull request May 8, 2020
…or-part-mvp-2

* 'master' of github.com:elastic/kibana: (259 commits)
  SavedObjects bulkCreate API should return migrationVersion and strip the type & namespace from the id (elastic#65150)
  Drilldown count tooltip (elastic#65105)
  plugins logs start with "plugins." prefix (elastic#65710)
  [ML] Fix pagination reset on search query update. (elastic#65668)
  [SIEM] Add types to the mappings objects so extra keys cannot be introduced
  [apm] Update machine learning flyout and service maps docs (elastic#65517)
  change api endpoint and throw error (elastic#65790)
  [Maps] remove SLA percentage metric (elastic#65718)
  [Reporting] APM integration for baseline performance measurements (elastic#59967)
  fix(NA): noParse regex for windows on kbn optimizer (elastic#65755)
  [ML] DFA: ensure at least one field is included in analysis before job can be created (elastic#65320)
  [Data plugin] cleanup - remove unused getRoutes / routes from indexPattern object (elastic#65683)
  Removed skip to enable test. (elastic#65575)
  [Lens] Type safe migrations (elastic#65576)
  [Canvas] Fix nav link behavior in Canvas  (elastic#65590)
  [Event log] Fix flaky test (elastic#65658)
  [Alerting] changes preconfigured actions config from array to object (elastic#65397)
  remove immediate functions from esqueue worker cycles (elastic#65375)
  [Metrics UI] Fix isAbove to only display when threshold set (elastic#65540)
  draft search profiler accessibility tests (elastic#62357)
  ...

# Conflicts:
#	x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx
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.

[ML] DFA job fails on start when no field except the dependent variable is included in the analysis
6 participants