[ML] Fix Transforms not retaining _meta on clone (#116206) (#116598)

* [ML] Retain _meta on clone

* [ML] Fix validation on schema to only check it it's defined/not null

* [ML] Remove validation because es should handle the validation already

* Change type to unknown

Co-authored-by: Quynh Nguyen <43350163+qn895@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2021-11-01 19:05:35 -04:00 committed by GitHub
parent 02faf630b0
commit bd75d8047a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 0 deletions

View file

@ -94,6 +94,13 @@ function transformConfigPayloadValidator<
}
}
export const _metaSchema = schema.object(
{},
{
unknowns: 'allow',
}
);
// PUT transforms/{transformId}
export const putTransformsRequestSchema = schema.object(
{
@ -112,6 +119,11 @@ export const putTransformsRequestSchema = schema.object(
settings: schema.maybe(settingsSchema),
source: sourceSchema,
sync: schema.maybe(syncSchema),
/**
* This _meta field stores an arbitrary key-value map
* where keys are strings and values are arbitrary objects (possibly also maps).
*/
_meta: schema.maybe(_metaSchema),
},
{
validate: transformConfigPayloadValidator,

View file

@ -24,6 +24,7 @@ export type TransformBaseConfig = PutTransformsRequestSchema & {
create_time?: number;
version?: string;
alerting_rules?: TransformHealthAlertRule[];
_meta?: Record<string, unknown>;
};
export interface PivotConfigDefinition {

View file

@ -242,6 +242,7 @@ export const getCreateTransformRequestBody = (
},
}
: {}),
...(transformDetailsState._meta ? { _meta: transformDetailsState._meta } : {}),
// conditionally add additional settings
...getCreateTransformSettingsRequestBody(transformDetailsState),
});

View file

@ -27,6 +27,7 @@ export interface StepDetailsExposedState {
transformSettingsDocsPerSecond?: number;
valid: boolean;
indexPatternTimeField?: string | undefined;
_meta?: Record<string, unknown>;
}
const defaultContinuousModeDelay = '60s';
@ -94,6 +95,10 @@ export function applyTransformConfigToDetailsState(
state.transformSettingsDocsPerSecond = transformConfig.settings.docs_per_second;
}
}
if (transformConfig._meta) {
state._meta = transformConfig._meta;
}
}
return state;
}

View file

@ -289,6 +289,7 @@ export const StepDetailsForm: FC<StepDetailsFormProps> = React.memo(
touched: true,
valid,
indexPatternTimeField,
_meta: defaults._meta,
});
// custom comparison
/* eslint-disable react-hooks/exhaustive-deps */