Skip to content

Commit

Permalink
[ML] Fix Transforms not retaining _meta on clone (elastic#116206)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
qn895 authored and kibanamachine committed Oct 28, 2021
1 parent d3a2b4d commit 2a5297e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions x-pack/plugins/transform/common/api_schemas/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ function transformConfigPayloadValidator<
}
}

export const _metaSchema = schema.object(
{},
{
unknowns: 'allow',
}
);

// PUT transforms/{transformId}
export const putTransformsRequestSchema = schema.object(
{
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/transform/common/types/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type TransformBaseConfig = PutTransformsRequestSchema & {
create_time?: number;
version?: string;
alerting_rules?: TransformHealthAlertRule[];
_meta?: Record<string, unknown>;
};

export interface PivotConfigDefinition {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/transform/public/app/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export const getCreateTransformRequestBody = (
},
}
: {}),
...(transformDetailsState._meta ? { _meta: transformDetailsState._meta } : {}),
// conditionally add additional settings
...getCreateTransformSettingsRequestBody(transformDetailsState),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface StepDetailsExposedState {
transformSettingsDocsPerSecond?: number;
valid: boolean;
indexPatternTimeField?: string | undefined;
_meta?: Record<string, unknown>;
}

const defaultContinuousModeDelay = '60s';
Expand Down Expand Up @@ -94,6 +95,10 @@ export function applyTransformConfigToDetailsState(
state.transformSettingsDocsPerSecond = transformConfig.settings.docs_per_second;
}
}

if (transformConfig._meta) {
state._meta = transformConfig._meta;
}
}
return state;
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export const StepDetailsForm: FC<StepDetailsFormProps> = React.memo(
touched: true,
valid,
indexPatternTimeField,
_meta: defaults._meta,
});
// custom comparison
/* eslint-disable react-hooks/exhaustive-deps */
Expand Down

0 comments on commit 2a5297e

Please sign in to comment.