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

[ILM] Relax POST policy route validation #84203

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,114 +23,20 @@ async function createPolicy(client: ElasticsearchClient, name: string, phases: a
return client.ilm.putLifecycle({ policy: name, body }, options);
}

const minAgeSchema = schema.maybe(schema.string());

const setPrioritySchema = schema.maybe(
schema.object({
priority: schema.nullable(schema.number()),
})
);

const unfollowSchema = schema.maybe(schema.object({})); // Unfollow has no options

const migrateSchema = schema.maybe(schema.object({ enabled: schema.literal(false) }));

const allocateNodeSchema = schema.maybe(schema.recordOf(schema.string(), schema.string()));
const allocateSchema = schema.maybe(
schema.object({
number_of_replicas: schema.maybe(schema.number()),
include: allocateNodeSchema,
exclude: allocateNodeSchema,
require: allocateNodeSchema,
})
);

const forcemergeSchema = schema.maybe(
schema.object({
max_num_segments: schema.number(),
index_codec: schema.maybe(schema.literal('best_compression')),
})
);

const hotPhaseSchema = schema.object({
min_age: minAgeSchema,
actions: schema.object({
set_priority: setPrioritySchema,
unfollow: unfollowSchema,
rollover: schema.maybe(
schema.object({
max_age: schema.maybe(schema.string()),
max_size: schema.maybe(schema.string()),
max_docs: schema.maybe(schema.number()),
})
),
forcemerge: forcemergeSchema,
}),
});

const warmPhaseSchema = schema.maybe(
schema.object({
min_age: minAgeSchema,
actions: schema.object({
migrate: migrateSchema,
set_priority: setPrioritySchema,
unfollow: unfollowSchema,
readonly: schema.maybe(schema.object({})), // Readonly has no options
allocate: allocateSchema,
shrink: schema.maybe(
schema.object({
number_of_shards: schema.number(),
})
),
forcemerge: forcemergeSchema,
}),
})
);

const coldPhaseSchema = schema.maybe(
schema.object({
min_age: minAgeSchema,
actions: schema.object({
migrate: migrateSchema,
set_priority: setPrioritySchema,
unfollow: unfollowSchema,
allocate: allocateSchema,
freeze: schema.maybe(schema.object({})), // Freeze has no options
searchable_snapshot: schema.maybe(
schema.object({
snapshot_repository: schema.string(),
})
),
}),
})
);

const deletePhaseSchema = schema.maybe(
schema.object({
min_age: minAgeSchema,
actions: schema.object({
wait_for_snapshot: schema.maybe(
schema.object({
policy: schema.string(),
})
),
delete: schema.maybe(
schema.object({
delete_searchable_snapshot: schema.maybe(schema.boolean()),
})
),
}),
})
);

// Per https://www.elastic.co/guide/en/elasticsearch/reference/current/_actions.html
/**
* We intentionally do not deeply validate the posted policy object to avoid erroring on valid ES
* policy configuration Kibana UI does not know or should not know about. For instance, the
* `force_merge_index` setting of the `searchable_snapshot` action.
*
* We only specify a rough structure based on https://www.elastic.co/guide/en/elasticsearch/reference/current/_actions.html.
*/
const bodySchema = schema.object({
name: schema.string(),
phases: schema.object({
hot: hotPhaseSchema,
warm: warmPhaseSchema,
cold: coldPhaseSchema,
delete: deletePhaseSchema,
hot: schema.any(),
warm: schema.maybe(schema.any()),
cold: schema.maybe(schema.any()),
delete: schema.maybe(schema.any()),
}),
});

Expand Down