-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esArchiver datastream support (#132853)
* aliases fallback * nasty datastream support implementation * datastreams stats method * update filter stream * datastream support for unload action * create-index datastream support * index records data stream support * doc records data streams support * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * lint * pull composable templates * set data_stream as a separate property on documents * force create bulk operation when datastream record * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * lint * getIndexTemplate tests * [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' * share cache across transform executions Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
e921693
commit 4c4f0f5
Showing
20 changed files
with
476 additions
and
45 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
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
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
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
105 changes: 105 additions & 0 deletions
105
packages/kbn-es-archiver/src/lib/index_template.test.ts
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,105 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import type { Client } from '@elastic/elasticsearch'; | ||
|
||
import sinon from 'sinon'; | ||
import { getIndexTemplate } from './index_template'; | ||
|
||
describe('esArchiver: index template', () => { | ||
describe('getIndexTemplate', () => { | ||
it('returns the index template', async () => { | ||
const client = { | ||
indices: { | ||
getIndexTemplate: sinon.stub().resolves({ | ||
index_templates: [ | ||
{ | ||
index_template: { | ||
index_patterns: ['pattern-*'], | ||
template: { | ||
mappings: { properties: { foo: { type: 'keyword' } } }, | ||
}, | ||
priority: 500, | ||
composed_of: [], | ||
data_stream: { hidden: false }, | ||
}, | ||
}, | ||
], | ||
}), | ||
}, | ||
} as unknown as Client; | ||
|
||
const template = await getIndexTemplate(client, 'template-foo'); | ||
|
||
expect(template).toEqual({ | ||
name: 'template-foo', | ||
index_patterns: ['pattern-*'], | ||
template: { | ||
mappings: { properties: { foo: { type: 'keyword' } } }, | ||
}, | ||
priority: 500, | ||
data_stream: { hidden: false }, | ||
}); | ||
}); | ||
|
||
it('resolves component templates', async () => { | ||
const client = { | ||
indices: { | ||
getIndexTemplate: sinon.stub().resolves({ | ||
index_templates: [ | ||
{ | ||
index_template: { | ||
index_patterns: ['pattern-*'], | ||
composed_of: ['the-settings', 'the-mappings'], | ||
}, | ||
}, | ||
], | ||
}), | ||
}, | ||
cluster: { | ||
getComponentTemplate: sinon | ||
.stub() | ||
.onFirstCall() | ||
.resolves({ | ||
component_templates: [ | ||
{ | ||
component_template: { | ||
template: { | ||
aliases: { 'foo-alias': {} }, | ||
}, | ||
}, | ||
}, | ||
], | ||
}) | ||
.onSecondCall() | ||
.resolves({ | ||
component_templates: [ | ||
{ | ||
component_template: { | ||
template: { | ||
mappings: { properties: { foo: { type: 'keyword' } } }, | ||
}, | ||
}, | ||
}, | ||
], | ||
}), | ||
}, | ||
} as unknown as Client; | ||
|
||
const template = await getIndexTemplate(client, 'template-foo'); | ||
|
||
expect(template).toEqual({ | ||
name: 'template-foo', | ||
index_patterns: ['pattern-*'], | ||
template: { | ||
aliases: { 'foo-alias': {} }, | ||
mappings: { properties: { foo: { type: 'keyword' } } }, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
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,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { merge } from 'lodash'; | ||
import type { Client } from '@elastic/elasticsearch'; | ||
|
||
import { ES_CLIENT_HEADERS } from '../client_headers'; | ||
|
||
export const getIndexTemplate = async (client: Client, templateName: string) => { | ||
const { index_templates: indexTemplates } = await client.indices.getIndexTemplate( | ||
{ name: templateName }, | ||
{ headers: ES_CLIENT_HEADERS } | ||
); | ||
const { | ||
index_template: { template, composed_of: composedOf = [], ...indexTemplate }, | ||
} = indexTemplates[0]; | ||
|
||
const components = await Promise.all( | ||
composedOf.map(async (component) => { | ||
const { component_templates: componentTemplates } = await client.cluster.getComponentTemplate( | ||
{ name: component } | ||
); | ||
return componentTemplates[0].component_template.template; | ||
}) | ||
); | ||
|
||
return { | ||
...indexTemplate, | ||
name: templateName, | ||
template: merge(template, ...components), | ||
}; | ||
}; |
Oops, something went wrong.