-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EPM] Add basics for creating the ILM setup (#50474)
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.
- Loading branch information
Showing
5 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../api_integration/ftr_provider_context'; | ||
import { getPolicy, getIndexWithWithAlias } from '../../../legacy/plugins/epm/server/lib/ilm/ilm'; | ||
|
||
export default function({ getService }: FtrProviderContext) { | ||
describe('ilm', () => { | ||
it('setup policy', async () => { | ||
const policyName = 'foo'; | ||
const es = getService('es'); | ||
const policy = getPolicy(); | ||
|
||
const data = await es.transport.request({ | ||
method: 'PUT', | ||
path: '/_ilm/policy/' + policyName, | ||
body: policy, | ||
}); | ||
|
||
expect(data.body.acknowledged).to.eql(true); | ||
expect(data.statusCode).to.eql(200); | ||
}); | ||
|
||
it('setup index with alias', async () => { | ||
const indexName = 'test-index-with-alias'; | ||
const aliasName = 'alias-to-index'; | ||
const es = getService('es'); | ||
|
||
// Delete index first if it exists as otherwise we get an error | ||
const existsBody = await es.indices.exists({ index: indexName }); | ||
if (existsBody.statusCode === 200) { | ||
const response = await es.indices.delete({ index: indexName }); | ||
|
||
// Sanity check to make sure removal work as expected | ||
// If it didn't we already know where the problem lays in the test | ||
expect(response.statusCode).to.eql(200); | ||
} | ||
|
||
// Calls the given esClient, creates and index and sets it as write index on the given alias. | ||
// | ||
// This should be moved later to the ilm lib but have it here for now as passing the client | ||
// does not work. | ||
const body = getIndexWithWithAlias(aliasName); | ||
const data = await es.indices.create({ | ||
index: indexName, | ||
body, | ||
}); | ||
|
||
// Sanity checks to make sure ES confirmed the data we sent is sane | ||
// and the index with the alias was created. | ||
expect(data.body.acknowledged).to.eql(true); | ||
expect(data.statusCode).to.eql(200); | ||
|
||
// Retreiving the index information again to see if the is_write_index | ||
// is set correctly for the alias. | ||
const indexData = await es.indices.get({ index: indexName }); | ||
expect(indexData.body[indexName].aliases[aliasName].is_write_index).to.eql(true); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters