Skip to content

Commit

Permalink
[8.x] [Fleet] Add <type>@Custom component template to integrati…
Browse files Browse the repository at this point in the history
…ons index te… (#192731) (#198808)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Add <type>@Custom component template to integrations
index te… (#192731)](#192731)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jill
Guyonnet","email":"jill.guyonnet@elastic.co"},"sourceCommit":{"committedDate":"2024-09-20T13:28:23Z","message":"[Fleet]
Add <type>@Custom component template to integrations index te…
(#192731)\n\n## Summary\r\n\r\nRelates
https://github.com/elastic/kibana/issues/190730\r\n\r\nThis PR adds a
`<type>@Custom `component template to integrations index\r\ntemplate's
`composed_of` array.\r\n\r\n### Testing\r\n\r\nIntegration
install/update should be tested.\r\n\r\nFrom my manual testing, Fleet
seems to behave normally and the new\r\ncomponent template is added to
the `composed_of` array. For example, the\r\noutput of `GET
/_index_template/logs-system.auth` is:\r\n```json\r\n{\r\n
\"index_templates\": [\r\n {\r\n \"name\": \"logs-system.auth\",\r\n
\"index_template\": {\r\n \"index_patterns\": [\r\n
\"logs-system.auth-*\"\r\n ],\r\n \"template\": {\r\n \"settings\":
{},\r\n \"mappings\": {\r\n \"_meta\": {\r\n \"package\": {\r\n
\"name\": \"system\"\r\n },\r\n \"managed_by\": \"fleet\",\r\n
\"managed\": true\r\n }\r\n }\r\n },\r\n \"composed_of\": [\r\n
\"logs@mappings\",\r\n \"logs@settings\",\r\n
\"logs-system.auth@package\",\r\n \"logs@custom\",\r\n
\"logs-system.auth@custom\",\r\n \"ecs@mappings\",\r\n
\".fleet_globals-1\",\r\n \".fleet_agent_id_verification-1\"\r\n ],\r\n
\"priority\": 200,\r\n \"_meta\": {\r\n \"package\": {\r\n \"name\":
\"system\"\r\n },\r\n \"managed_by\": \"fleet\",\r\n \"managed\":
true\r\n },\r\n \"data_stream\": {\r\n \"hidden\": false,\r\n
\"allow_custom_routing\": false,\r\n \"failure_store\": false\r\n },\r\n
\"ignore_missing_component_templates\": [\r\n \"logs@custom\",\r\n
\"logs-system.auth@custom\"\r\n ]\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n### Screenshot\r\n\r\n<img width=\"956\"
alt=\"Screenshot 2024-09-19 at 16 44
57\"\r\nsrc=\"https://github.com/user-attachments/assets/7e1d8e67-1d78-45a7-bc8d-8e509f1a2533\">\r\n\r\n<img
width=\"956\" alt=\"Screenshot 2024-09-19 at 17 04
45\"\r\nsrc=\"https://github.com/user-attachments/assets/8b6bbaf3-34b7-4169-8ca8-2bc6a38fe60d\">\r\n\r\n###
Checklist\r\n\r\n- [
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"c8ff7ea27ab02548c25c3c295bbd988e3adfbba4","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Fleet","v9.0.0","backport:prev-minor"],"title":"[Fleet]
Add <type>@Custom component template to integrations index
te…","number":192731,"url":"https://github.com/elastic/kibana/pull/192731","mergeCommit":{"message":"[Fleet]
Add <type>@Custom component template to integrations index te…
(#192731)\n\n## Summary\r\n\r\nRelates
https://github.com/elastic/kibana/issues/190730\r\n\r\nThis PR adds a
`<type>@Custom `component template to integrations index\r\ntemplate's
`composed_of` array.\r\n\r\n### Testing\r\n\r\nIntegration
install/update should be tested.\r\n\r\nFrom my manual testing, Fleet
seems to behave normally and the new\r\ncomponent template is added to
the `composed_of` array. For example, the\r\noutput of `GET
/_index_template/logs-system.auth` is:\r\n```json\r\n{\r\n
\"index_templates\": [\r\n {\r\n \"name\": \"logs-system.auth\",\r\n
\"index_template\": {\r\n \"index_patterns\": [\r\n
\"logs-system.auth-*\"\r\n ],\r\n \"template\": {\r\n \"settings\":
{},\r\n \"mappings\": {\r\n \"_meta\": {\r\n \"package\": {\r\n
\"name\": \"system\"\r\n },\r\n \"managed_by\": \"fleet\",\r\n
\"managed\": true\r\n }\r\n }\r\n },\r\n \"composed_of\": [\r\n
\"logs@mappings\",\r\n \"logs@settings\",\r\n
\"logs-system.auth@package\",\r\n \"logs@custom\",\r\n
\"logs-system.auth@custom\",\r\n \"ecs@mappings\",\r\n
\".fleet_globals-1\",\r\n \".fleet_agent_id_verification-1\"\r\n ],\r\n
\"priority\": 200,\r\n \"_meta\": {\r\n \"package\": {\r\n \"name\":
\"system\"\r\n },\r\n \"managed_by\": \"fleet\",\r\n \"managed\":
true\r\n },\r\n \"data_stream\": {\r\n \"hidden\": false,\r\n
\"allow_custom_routing\": false,\r\n \"failure_store\": false\r\n },\r\n
\"ignore_missing_component_templates\": [\r\n \"logs@custom\",\r\n
\"logs-system.auth@custom\"\r\n ]\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n### Screenshot\r\n\r\n<img width=\"956\"
alt=\"Screenshot 2024-09-19 at 16 44
57\"\r\nsrc=\"https://github.com/user-attachments/assets/7e1d8e67-1d78-45a7-bc8d-8e509f1a2533\">\r\n\r\n<img
width=\"956\" alt=\"Screenshot 2024-09-19 at 17 04
45\"\r\nsrc=\"https://github.com/user-attachments/assets/8b6bbaf3-34b7-4169-8ca8-2bc6a38fe60d\">\r\n\r\n###
Checklist\r\n\r\n- [
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"c8ff7ea27ab02548c25c3c295bbd988e3adfbba4"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192731","number":192731,"mergeCommit":{"message":"[Fleet]
Add <type>@Custom component template to integrations index te…
(#192731)\n\n## Summary\r\n\r\nRelates
https://github.com/elastic/kibana/issues/190730\r\n\r\nThis PR adds a
`<type>@Custom `component template to integrations index\r\ntemplate's
`composed_of` array.\r\n\r\n### Testing\r\n\r\nIntegration
install/update should be tested.\r\n\r\nFrom my manual testing, Fleet
seems to behave normally and the new\r\ncomponent template is added to
the `composed_of` array. For example, the\r\noutput of `GET
/_index_template/logs-system.auth` is:\r\n```json\r\n{\r\n
\"index_templates\": [\r\n {\r\n \"name\": \"logs-system.auth\",\r\n
\"index_template\": {\r\n \"index_patterns\": [\r\n
\"logs-system.auth-*\"\r\n ],\r\n \"template\": {\r\n \"settings\":
{},\r\n \"mappings\": {\r\n \"_meta\": {\r\n \"package\": {\r\n
\"name\": \"system\"\r\n },\r\n \"managed_by\": \"fleet\",\r\n
\"managed\": true\r\n }\r\n }\r\n },\r\n \"composed_of\": [\r\n
\"logs@mappings\",\r\n \"logs@settings\",\r\n
\"logs-system.auth@package\",\r\n \"logs@custom\",\r\n
\"logs-system.auth@custom\",\r\n \"ecs@mappings\",\r\n
\".fleet_globals-1\",\r\n \".fleet_agent_id_verification-1\"\r\n ],\r\n
\"priority\": 200,\r\n \"_meta\": {\r\n \"package\": {\r\n \"name\":
\"system\"\r\n },\r\n \"managed_by\": \"fleet\",\r\n \"managed\":
true\r\n },\r\n \"data_stream\": {\r\n \"hidden\": false,\r\n
\"allow_custom_routing\": false,\r\n \"failure_store\": false\r\n },\r\n
\"ignore_missing_component_templates\": [\r\n \"logs@custom\",\r\n
\"logs-system.auth@custom\"\r\n ]\r\n }\r\n }\r\n
]\r\n}\r\n```\r\n\r\n### Screenshot\r\n\r\n<img width=\"956\"
alt=\"Screenshot 2024-09-19 at 16 44
57\"\r\nsrc=\"https://github.com/user-attachments/assets/7e1d8e67-1d78-45a7-bc8d-8e509f1a2533\">\r\n\r\n<img
width=\"956\" alt=\"Screenshot 2024-09-19 at 17 04
45\"\r\nsrc=\"https://github.com/user-attachments/assets/8b6bbaf3-34b7-4169-8ca8-2bc6a38fe60d\">\r\n\r\n###
Checklist\r\n\r\n- [
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"c8ff7ea27ab02548c25c3c295bbd988e3adfbba4"}}]}]
BACKPORT-->

Co-authored-by: Jill Guyonnet <jill.guyonnet@elastic.co>
  • Loading branch information
kibanamachine and jillguyonnet authored Nov 4, 2024
1 parent 094c46d commit 8fdcef5
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/constants/fleet_es_assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getESAssetMetadata } from '../services/epm/elasticsearch/meta';

const meta = getESAssetMetadata();

export const FLEET_INSTALL_FORMAT_VERSION = '1.2.0';
export const FLEET_INSTALL_FORMAT_VERSION = '1.3.0';

export const FLEET_AGENT_POLICIES_SCHEMA_VERSION = '1.1.1';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export function buildComponentTemplates(params: {
experimentalDataStreamFeature?: ExperimentalDataStreamFeature;
lifecycle?: IndexTemplate['template']['lifecycle'];
fieldCount?: number;
type?: string;
}) {
const {
templateName,
Expand All @@ -330,6 +331,7 @@ export function buildComponentTemplates(params: {
experimentalDataStreamFeature,
lifecycle,
fieldCount,
type,
} = params;
const packageTemplateName = `${templateName}${PACKAGE_TEMPLATE_SUFFIX}`;
const userSettingsTemplateName = `${templateName}${USER_SETTINGS_TEMPLATE_SUFFIX}`;
Expand Down Expand Up @@ -417,6 +419,17 @@ export function buildComponentTemplates(params: {
_meta,
};

// Stub custom template
if (type) {
const customTemplateName = `${type}${USER_SETTINGS_TEMPLATE_SUFFIX}`;
templatesMap[customTemplateName] = {
template: {
settings: {},
},
_meta,
};
}

// return empty/stub template
templatesMap[userSettingsTemplateName] = {
template: {
Expand Down Expand Up @@ -580,6 +593,7 @@ export function prepareTemplate({
experimentalDataStreamFeature,
lifecycle: lifecyle,
fieldCount: countFields(validFields),
type: dataStream.type,
});

const template = getTemplate({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('updateLatestExecutedState', () => {
'epm-packages',
'test-integration',
{
install_format_schema_version: '1.2.0',
install_format_schema_version: '1.3.0',
install_status: 'installed',
install_version: '1.0.0',
latest_install_failed_attempts: [],
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('updateLatestExecutedState', () => {
'epm-packages',
'test-integration',
{
install_format_schema_version: '1.2.0',
install_format_schema_version: '1.3.0',
install_status: 'installed',
install_version: '1.0.0',
latest_install_failed_attempts: [],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function (providerContext: FtrProviderContext) {

it('should install a tar archive correctly', async function () {
const res = await uploadPackage();
expect(res.body.items.length).to.be(30);
expect(res.body.items.length).to.be(32);
});

it('should upgrade when uploading a newer zip archive', async () => {
Expand All @@ -111,7 +111,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/zip')
.send(buf)
.expect(200);
expect(res.body.items.length).to.be(30);
expect(res.body.items.length).to.be(32);
expect(res.body.items.some((item: any) => item.id.includes(testPkgNewVersion)));

await deletePackage(testPkgName, testPkgNewVersion);
Expand Down Expand Up @@ -182,7 +182,7 @@ export default function (providerContext: FtrProviderContext) {
.type('application/zip')
.send(buf)
.expect(200);
expect(res.body.items.length).to.be(30);
expect(res.body.items.length).to.be(32);
});

it('should throw an error if the archive is zip but content type is gzip', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function (providerContext: FtrProviderContext) {
`logs@mappings`,
`logs@settings`,
`${templateName}@package`,
'logs@custom',
`${templateName}@custom`,
`ecs@mappings`,
'.fleet_globals-1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ const expectAssetsInstalled = ({
id: 'logs-all_assets.test_logs@package',
type: 'component_template',
},
{
id: 'logs@custom',
type: 'component_template',
},
{
id: 'logs-all_assets.test_logs@custom',
type: 'component_template',
Expand All @@ -607,6 +611,10 @@ const expectAssetsInstalled = ({
id: 'metrics-all_assets.test_metrics@package',
type: 'component_template',
},
{
id: 'metrics@custom',
type: 'component_template',
},
{
id: 'metrics-all_assets.test_metrics@custom',
type: 'component_template',
Expand Down
9 changes: 9 additions & 0 deletions x-pack/test/fleet_api_integration/apis/epm/update_assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ export default function (providerContext: FtrProviderContext) {
id: 'logs-all_assets.test_logs@package',
type: 'component_template',
},
{
id: 'logs@custom',
type: 'component_template',
},
{
id: 'logs-all_assets.test_logs@custom',
type: 'component_template',
Expand All @@ -441,6 +445,11 @@ export default function (providerContext: FtrProviderContext) {
id: 'metrics-all_assets.test_metrics@package',
type: 'component_template',
},

{
id: 'metrics@custom',
type: 'component_template',
},
{
id: 'metrics-all_assets.test_metrics@custom',
type: 'component_template',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export default function (providerContext: FtrProviderContext) {
{ id: 'logs-dataset1', type: 'index_template' },
{ id: 'logs-dataset1@package', type: 'component_template' },
{ id: 'logs-dataset1@custom', type: 'component_template' },
{ id: 'logs@custom', type: 'component_template' },
]);

// now check the package component template was created correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ export default function (providerContext: FtrProviderContext) {
{ id: 'logs-somedataset', type: 'index_template' },
{ id: 'logs-somedataset@package', type: 'component_template' },
{ id: 'logs-somedataset@custom', type: 'component_template' },
{ id: 'logs@custom', type: 'component_template' },
]);

const dataset3PkgComponentTemplate = await getComponentTemplate('logs-somedataset@package');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,8 @@ export default function (providerContext: FtrProviderContext) {
for (let i = 0; i < POLICY_COUNT; i++) {
await createPackagePolicy(i.toString());
}

expectedAssets.push({ id: 'logs@custom', type: 'component_template' });
});

afterEach(async function () {
Expand Down

0 comments on commit 8fdcef5

Please sign in to comment.