-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
esArchiver datastream support #132853
Merged
klacabane
merged 20 commits into
elastic:main
from
klacabane:es-archiver-save-no-aliases
Jun 2, 2022
Merged
esArchiver datastream support #132853
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
bd058e2
aliases fallback
klacabane 12e5148
nasty datastream support implementation
klacabane 29ec303
datastreams stats method
klacabane aebfe90
update filter stream
klacabane 0a34b00
datastream support for unload action
klacabane de896bc
create-index datastream support
klacabane 313b7a7
index records data stream support
klacabane 187d74c
doc records data streams support
klacabane c625231
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 2501806
lint
klacabane 7764051
Merge branch 'main' into es-archiver-save-no-aliases
kibanamachine d68d25a
pull composable templates
klacabane 795334c
set data_stream as a separate property on documents
klacabane 8ec501b
force create bulk operation when datastream record
klacabane d09c349
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine a2625b3
lint
klacabane 3cde7ce
getIndexTemplate tests
klacabane fc8acc1
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine e1f3fb0
share cache across transform executions
klacabane dfa66dc
Merge branch 'main' into es-archiver-save-no-aliases
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Part of me would prefer that docs either had an index or a data_stream, but I'm not opposed to keeping the index if there's some use for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mainly kept it for traceability when debugging or inspecting archived data, besides that there's no real use for it :)