Skip to content

Commit

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

## Summary

Relates #190730

This PR adds a `<type>@Custom `component template to integrations index
template's `composed_of` array.

### Testing

Integration install/update should be tested.

From my manual testing, Fleet seems to behave normally and the new
component template is added to the `composed_of` array. For example, the
output of `GET /_index_template/logs-system.auth` is:
```json
{
  "index_templates": [
    {
      "name": "logs-system.auth",
      "index_template": {
        "index_patterns": [
          "logs-system.auth-*"
        ],
        "template": {
          "settings": {},
          "mappings": {
            "_meta": {
              "package": {
                "name": "system"
              },
              "managed_by": "fleet",
              "managed": true
            }
          }
        },
        "composed_of": [
          "logs@mappings",
          "logs@settings",
          "logs-system.auth@package",
          "logs@custom",
          "logs-system.auth@custom",
          "ecs@mappings",
          ".fleet_globals-1",
          ".fleet_agent_id_verification-1"
        ],
        "priority": 200,
        "_meta": {
          "package": {
            "name": "system"
          },
          "managed_by": "fleet",
          "managed": true
        },
        "data_stream": {
          "hidden": false,
          "allow_custom_routing": false,
          "failure_store": false
        },
        "ignore_missing_component_templates": [
          "logs@custom",
          "logs-system.auth@custom"
        ]
      }
    }
  ]
}
```

### Screenshot

<img width="956" alt="Screenshot 2024-09-19 at 16 44 57"
src="https://github.com/user-attachments/assets/7e1d8e67-1d78-45a7-bc8d-8e509f1a2533">

<img width="956" alt="Screenshot 2024-09-19 at 17 04 45"
src="https://github.com/user-attachments/assets/8b6bbaf3-34b7-4169-8ca8-2bc6a38fe60d">

### Checklist

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
  • Loading branch information
jillguyonnet authored Sep 20, 2024
1 parent 52aa453 commit c8ff7ea
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 c8ff7ea

Please sign in to comment.