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] Add option to Advanced Settings to set default time range filter for AD jobs #76347

Merged
merged 16 commits into from
Sep 4, 2020

Conversation

qn895
Copy link
Member

@qn895 qn895 commented Sep 1, 2020

Summary

This PR adds Advanced Setting for anomaly detection default time filter time range.
Screen Shot 2020-09-02 at 11 22 30 AM

When the setting is enabled, links to the Single Metric Viewer and the Anomaly Explorer from the Jobs Management list would be using the filter by default.

Current it supports quick options as well as "absolute" options:

{
  "from": "now-30d",
  "to": "now-15m"
}

Although more validations would be needed if there's any invalid terms for either "from" or "to".

Also updated:

  • Apply timerange -> Apply time range
  • The pixels for the job group controls to match the one for the job controls

Checklist

Delete any items that are not applicable to this PR.

@qn895 qn895 added :ml Feature:Anomaly Detection ML anomaly detection labels Sep 1, 2020
@qn895 qn895 self-assigned this Sep 1, 2020
@@ -5,3 +5,5 @@
*/

export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize';
export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeEnable';
Copy link
Member Author

Choose a reason for hiding this comment

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

Setting the name this way because seems like the settings are ordered by these strings alphabetically.

@peteharverson
Copy link
Contributor

If I try and open the Jobs lists on the Stack Management page, I get this error saying the uiSettings haven't been initialized:

image

The links on that page should also use this new setting.

@@ -5,3 +5,5 @@
*/

export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize';
export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeEnable';
export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeSet';
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this setting looks very similar to timepicker:timeDefaults, I wonder if we should give it a similar name?

Suggested change
export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeSet';
export const ANOMALY_DETECTION_DEFAULT_TIME_RANGE = 'ml:anomalyDetectionTimeDefaults';

Copy link
Contributor

@lcawl lcawl left a comment

Choose a reason for hiding this comment

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

I've added some text suggestions.

@@ -30,5 +34,41 @@ export function registerKibanaSettings(coreSetup: CoreSetup) {
}),
},
},
[ANOMALY_DETECTION_ENABLE_TIME_RANGE]: {
name: i18n.translate('xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeName', {
defaultMessage: 'Enable default time range for anomaly detection jobs.',
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding correctly and these two settings must be used together, I suggest synching the title more closely:

Suggested change
defaultMessage: 'Enable default time range for anomaly detection jobs.',
defaultMessage: 'Enable time filter defaults',

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to 'Enable time filter defaults for anomaly detection jobs' because this setting is specific to that area

41af491

description: i18n.translate(
'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc',
{
defaultMessage: 'Use a default time range to view anomaly detection jobs.',
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding correctly that this applies only to specific interfaces, I suggest we mention them here:

Suggested change
defaultMessage: 'Use a default time range to view anomaly detection jobs.',
defaultMessage: 'Use the default time filter in the Single Metric Viewer and Anomaly Explorer.',

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 41af491

description: i18n.translate(
'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc',
{
defaultMessage: 'The default time range to view anomaly detection jobs.',
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest we use text closer to what's used for the timepicker:timeDefaults. For example:

Suggested change
defaultMessage: 'The default time range to view anomaly detection jobs.',
defaultMessage: 'The time filter selection to use when viewing anomaly detection job results.',

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 41af491

description: i18n.translate(
'xpack.ml.advancedSettings.anomalyDetectionDefaultTimeRangeDesc',
{
defaultMessage: 'The default time range to view anomaly detection jobs.',
Copy link
Contributor

Choose a reason for hiding this comment

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

The default time range...

If you want a link to the list of accepted formats, perhaps it can be copied from the way data.advancedSettings.timepicker.quickRangesText uses {acceptedFormatsLink} in ui_settings.ts. I'm not convinced that link is necessary here, however.

@@ -5,3 +5,5 @@
*/

export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize';
export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeEnable';
Copy link
Contributor

Choose a reason for hiding this comment

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

If you accept my suggestion for renaming the other setting, this one should be updated to match:

Suggested change
export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionDefaultTimeRangeEnable';
export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetectionTimeDefaultsEnable';

Copy link
Member Author

@qn895 qn895 Sep 1, 2020

Choose a reason for hiding this comment

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

Updated here 4155201 ... although now the order is changed where the toggle to set it comes after the json field. Not totally ideal but I'm not sure what's a good solution around making the names in alphabetical order.

2020-09-01 at 2 43 PM

@qn895
Copy link
Member Author

qn895 commented Sep 1, 2020

If I try and open the Jobs lists on the Stack Management page, I get this error saying the uiSettings haven't been initialized:

Thanks for catching that Pete. I removed the cache dependency entirely for these link generating utils and instead pass in the useMlKibana contexts to prevent this problem in the future.

The links should now work as intended in the Job Management as well as the Overview Page.

I also made it so that if the user sets the date format incorrect (e.g. 'now-15mzzz'), the job will resets to the full range of the data, and show the following warn toast notification in AE/SMV pages:
Screen Shot 2020-09-01 at 4 25 20 PM

@qn895 qn895 marked this pull request as ready for review September 1, 2020 21:26
@qn895 qn895 requested a review from a team as a code owner September 1, 2020 21:26
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

'xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeDesc',
{
defaultMessage:
'Use the default time filter in the Single Metric Viewer and Anomaly Explorer.',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs an extra sentence to explain what happens if this is not enabled. Something like If not enabled, the results for the full time range of the job will be displayed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Something like ... "If not enabled, the results....

LGTM, except I'd replace "will be" with "are".

Copy link
Member Author

@qn895 qn895 Sep 2, 2020

Choose a reason for hiding this comment

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

Updated it to Use the default time filter in the Single Metric Viewer and Anomaly Explorer. If not enabled, the results for the full time range of the job are displayed. here 1118b3e

@@ -30,5 +34,43 @@ export function registerKibanaSettings(coreSetup: CoreSetup) {
}),
},
},
[ANOMALY_DETECTION_ENABLE_TIME_RANGE]: {
name: i18n.translate('xpack.ml.advancedSettings.enableAnomalyDetectionDefaultTimeRangeName', {
defaultMessage: 'Enable time filter defaults for anomaly detection jobs',
Copy link
Contributor

Choose a reason for hiding this comment

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

Or as this only applies to the results pages, should this be Enable time filter defaults for anomaly detection results?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here 1118b3e

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.

Some more text suggestions!

toastNotifications.addWarning(
i18n.translate('xpack.ml.explorer.invalidTimeRangeInUrlCallout', {
defaultMessage:
'The time filter changed to the full range for this job due to invalid default time filter. Please check the advanced settings for {field}.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - suggest changing to The time filter was changed to the full range for this job due to an invalid default time filter. Please check the advanced settings for {field}.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the advanced settings.

Another nit: The style guidelines recommend omitting "Please". I'd suggest "Check the advanced settings...".

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated it to The time filter was changed to the full range due to an invalid default time filter. Check the advanced settings for {field}. here 1118b3e

defaultMessage:
'The time filter changed to the full range for this job due to invalid default time filter. Please check the advanced settings for {field}.',
values: {
field: ANOMALY_DETECTION_DEFAULT_TIME_RANGE,
Copy link
Contributor

Choose a reason for hiding this comment

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

The message either needs changing to remove for this job or else you need to pass in the number of jobs selected in the view and change to for these jobs if more than one is selected.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the for this job part to make it more concise and I think it reads okay. Updated here 1118b3e

Copy link
Contributor

Choose a reason for hiding this comment

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

I removed the "for this job" part...

Should it be removed from the UI text on the Advanced Settings page too?

import { MlSummaryJobs } from '../../../../../common/types/anomaly_detection_jobs';
import { useCreateADLinks } from '../../../components/custom_hooks/use_create_ad_links';

// @ts-ignore no module file
Copy link
Member

Choose a reason for hiding this comment

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

looks like this comment can go

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed here 1118b3e

defaultMessage: 'Time filter defaults',
}),
type: 'json',
value: `{
Copy link
Member

Choose a reason for hiding this comment

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

is it worth pulling these defaults out into constants like our existing file data viz setting.
this could be stored as a real json object constant and stringified when adding it here.
JSON.stringify(FOO, null, 2) for the correct formatting.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is super neat! Updated here 1118b3e

Although I put the new settings in the settings constants instead of creating a new file because I didn't think it was big enough. Although I'm happy to create a new file for them!

@@ -5,3 +5,11 @@
*/

export const FILE_DATA_VISUALIZER_MAX_FILE_SIZE = 'ml:fileDataVisualizerMaxFileSize';
export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetection:results:enableTmeDefaults';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a letter missing:

Suggested change
export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetection:results:enableTmeDefaults';
export const ANOMALY_DETECTION_ENABLE_TIME_RANGE = 'ml:anomalyDetection:results:enableTimeDefaults';

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! Fixed in ab8b130

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
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.

LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
ml 1386 +1 1385

async chunks size

id value diff baseline
ml 8.2MB +5.9KB 8.2MB

page load bundle size

id value diff baseline
ml 584.2KB +1.5KB 582.7KB

History

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

@qn895 qn895 merged commit ee3c8d0 into elastic:master Sep 4, 2020
@qn895 qn895 deleted the default-adv-time-settings branch September 4, 2020 16:46
qn895 added a commit to qn895/kibana that referenced this pull request Sep 4, 2020
qn895 added a commit that referenced this pull request Sep 4, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Sep 4, 2020
* master: (47 commits)
  Do not require id & description when creating a logstash pipeline (elastic#76616)
  Remove commented src/core/tsconfig file (elastic#76792)
  Replaced whitelistedHosts with allowedHosts in actions ascii docs (elastic#76731)
  [Dashboard First] Genericize Attribute Service (elastic#76057)
  [ci-metrics] unify distributable file count metrics (elastic#76448)
  [Security Solution][Detections] Handle conflicts on alert status update (elastic#75492)
  [eslint] convert to @typescript-eslint/no-unused-expressions (elastic#76471)
  [DOCS] Add default time range filter to advanced settings (elastic#76414)
  [Security Solution] Refactor NetworkTopNFlow to use Search Strategy (elastic#76249)
  [Dashboard] Update Index Patterns when Child Index Patterns Change (elastic#76356)
  [ML] Add option to Advanced Settings to set default time range filter for AD jobs (elastic#76347)
  Add CSM app to CODEOWNERS (elastic#76793)
  [Security Solution][Exceptions] - Updates exception item find sort field (elastic#76685)
  [Security Solution][Detections][Tech Debt] - Move to using common io-ts types (elastic#75009)
  [Lens] Drag dimension to replace (elastic#75895)
  URI encode the index names we fetch in the fetchIndices lib function. (elastic#76584)
  [Security Solution] Resolver retrieve entity id of documents without field mapped (elastic#76562)
  [Ingest Manager] validate agent route using AJV instead kbn-config-schema (elastic#76546)
  Updated non-dev usages of node-forge (elastic#76699)
  [Ingest Pipelines] Processor forms for processors K-S (elastic#75638)
  ...
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