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

[EPM] Add basics for creating the ILM setup #50474

Merged
merged 13 commits into from
Nov 28, 2019
Next Next commit
[EPM] Add basics for creating the ILM setup
This contains the basic objects to setup ILM

* Create index and alias with a write index
* Get the policy

The code does not contain any functional tests yet as it is still open on how to do it best. I suggest to get this in as a foundation and then iterate on top of it.
ruflin committed Nov 28, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit c07fe58b5844fe04bc410f4f64c83977efd0710c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { getIndexWithWithAlias } from './ilm';

test('get index with alias', () => {
const aliasName = 'bar';

const data = getIndexWithWithAlias(aliasName);
// Verifies that the bar key exists and write index is set to true
expect(data.aliases.bar.is_write_index).toStrictEqual(true);
});
49 changes: 49 additions & 0 deletions x-pack/legacy/plugins/integrations_manager/server/lib/ilm/ilm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/**
* Calls the given esClient, creates and index and sets it as write index on the given alias.
*/
export function createIndexWithAlias(esClient: object, indexName: string, aliasName: string) {
// TODO: replace esClient by an actual client
const query = '/' + indexName;
const method = 'PUT';
const body = getIndexWithWithAlias(indexName, aliasName);
// TODO: API request go create it
}

export function getIndexWithWithAlias(aliasName: string) {
return {
aliases: {
[aliasName]: {
is_write_index: true,
},
},
};
}

/**
* Returns the current default policy used for Beats.
* This will later be replaced by the default policies.
*
* This policy will have to be pushed to PUT /_ilm/policy/{policy-name}
*/
export function getPolicy() {
return {
policy: {
phases: {
hot: {
actions: {
rollover: {
max_size: '50gb',
max_age: '30d',
},
},
},
},
},
};
}