[8.9] [ML] Anomaly detection wizard: ensure custom urls test functionality works as expected (#165055) (#165178)

# Backport

This will backport the following commits from `main` to `8.9`:
- [[ML] Anomaly detection wizard: ensure custom urls test functionality
works as expected
(#165055)](https://github.com/elastic/kibana/pull/165055)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Melissa
Alvarez","email":"melissa.alvarez@elastic.co"},"sourceCommit":{"committedDate":"2023-08-29T22:24:01Z","message":"[ML]
Anomaly detection wizard: ensure custom urls test functionality works as
expected (#165055)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/165051, ensuring the\r\ncorrect
time range is used in the target Dashboard or Discover pages\r\nwhen
testing custom URLs created in the Anomaly Detection job
wizards.\r\nPreviously on subsequent tests the page would always open to
show `Last\r\n15 minutes` rather than a time range for which there are
documents in\r\nthe data view used by the datafeed.\r\n\r\nThis PR
ensures the original job object is not affected when the\r\ndatafeed is
removed for sending off to the
endpoint.\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"501e9bda2a6c17732c525d557b97f12c48dfe345","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:Anomaly
Detection","v8.10.0","v8.11.0","v8.9.2"],"number":165055,"url":"https://github.com/elastic/kibana/pull/165055","mergeCommit":{"message":"[ML]
Anomaly detection wizard: ensure custom urls test functionality works as
expected (#165055)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/165051, ensuring the\r\ncorrect
time range is used in the target Dashboard or Discover pages\r\nwhen
testing custom URLs created in the Anomaly Detection job
wizards.\r\nPreviously on subsequent tests the page would always open to
show `Last\r\n15 minutes` rather than a time range for which there are
documents in\r\nthe data view used by the datafeed.\r\n\r\nThis PR
ensures the original job object is not affected when the\r\ndatafeed is
removed for sending off to the
endpoint.\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"501e9bda2a6c17732c525d557b97f12c48dfe345"}},"sourceBranch":"main","suggestedTargetBranches":["8.10","8.9"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/165055","number":165055,"mergeCommit":{"message":"[ML]
Anomaly detection wizard: ensure custom urls test functionality works as
expected (#165055)\n\n## Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/165051, ensuring the\r\ncorrect
time range is used in the target Dashboard or Discover pages\r\nwhen
testing custom URLs created in the Anomaly Detection job
wizards.\r\nPreviously on subsequent tests the page would always open to
show `Last\r\n15 minutes` rather than a time range for which there are
documents in\r\nthe data view used by the datafeed.\r\n\r\nThis PR
ensures the original job object is not affected when the\r\ndatafeed is
removed for sending off to the
endpoint.\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"501e9bda2a6c17732c525d557b97f12c48dfe345"}},{"branch":"8.9","label":"v8.9.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Melissa Alvarez <melissa.alvarez@elastic.co>
This commit is contained in:
Kibana Machine 2023-08-29 19:48:57 -04:00 committed by GitHub
parent e3110ec557
commit b89e9eeab0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import moment, { type Moment } from 'moment';
import { cloneDeep } from 'lodash';
import type { SerializableRecord } from '@kbn/utility-types';
import rison from '@kbn/rison';
import url from 'url';
@ -459,8 +460,8 @@ async function getAnomalyDetectionJobTestUrl(job: Job, customUrl: MlUrlConfig):
// No anomalies yet for this job, so do a preview of the search
// configured in the job datafeed to obtain sample docs.
let { datafeed_config: datafeedConfig } = job;
let jobConfig = job;
let jobConfig = cloneDeep(job);
let { datafeed_config: datafeedConfig } = jobConfig;
try {
// attempt load the non-combined job and datafeed so they can be used in the datafeed preview
const [{ jobs }, { datafeeds }] = await Promise.all([