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

## Summary

Fixes https://github.com/elastic/kibana/issues/165051, ensuring the
correct time range is used in the target Dashboard or Discover pages
when testing custom URLs created in the Anomaly Detection job wizards.
Previously on subsequent tests the page would always open to show `Last
15 minutes` rather than a time range for which there are documents in
the data view used by the datafeed.

This PR ensures the original job object is not affected when the
datafeed is removed for sending off to the endpoint.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Melissa Alvarez 2023-08-29 16:24:01 -06:00 committed by GitHub
parent 8fec1d100e
commit 501e9bda2a
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([