Skip to content

Commit

Permalink
[Fleet] Installation of hidden field (#85703)
Browse files Browse the repository at this point in the history
Co-authored-by: nnamdifrankie <franklin.ejoh@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 14, 2020
1 parent d909a96 commit 06993c4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export type ElasticsearchAssetTypeToParts = Record<

export interface RegistryDataStream {
type: string;
hidden?: boolean;
dataset: string;
title: string;
release: string;
Expand Down Expand Up @@ -319,7 +320,7 @@ export interface IndexTemplate {
mappings: any;
aliases: object;
};
data_stream: object;
data_stream: { hidden?: boolean };
composed_of: string[];
_meta: object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export async function installTemplate({
pipelineName,
packageName,
composedOfTemplates,
hidden: dataStream.hidden,
});

// TODO: Check return values for errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ test('adds empty composed_of correctly', () => {
expect(template.composed_of).toStrictEqual(composedOfTemplates);
});

test('adds hidden field correctly', () => {
const templateWithHiddenName = 'logs-nginx-access-abcd';

const templateWithHidden = getTemplate({
type: 'logs',
templateName: templateWithHiddenName,
packageName: 'nginx',
mappings: { properties: {} },
composedOfTemplates: [],
hidden: true,
});
expect(templateWithHidden.data_stream.hidden).toEqual(true);

const templateWithoutHiddenName = 'logs-nginx-access-efgh';

const templateWithoutHidden = getTemplate({
type: 'logs',
templateName: templateWithoutHiddenName,
packageName: 'nginx',
mappings: { properties: {} },
composedOfTemplates: [],
});
expect(templateWithoutHidden.data_stream.hidden).toEqual(undefined);
});

test('tests loading base.yml', () => {
const ymlPath = path.join(__dirname, '../../fields/tests/base.yml');
const fieldsYML = readFileSync(ymlPath, 'utf-8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,24 @@ export function getTemplate({
pipelineName,
packageName,
composedOfTemplates,
hidden,
}: {
type: string;
templateName: string;
mappings: IndexTemplateMappings;
pipelineName?: string | undefined;
packageName: string;
composedOfTemplates: string[];
hidden?: boolean;
}): IndexTemplate {
const template = getBaseTemplate(type, templateName, mappings, packageName, composedOfTemplates);
const template = getBaseTemplate(
type,
templateName,
mappings,
packageName,
composedOfTemplates,
hidden
);
if (pipelineName) {
template.template.settings.index.default_pipeline = pipelineName;
}
Expand Down Expand Up @@ -253,7 +262,8 @@ function getBaseTemplate(
templateName: string,
mappings: IndexTemplateMappings,
packageName: string,
composedOfTemplates: string[]
composedOfTemplates: string[],
hidden?: boolean
): IndexTemplate {
// Meta information to identify Ingest Manager's managed templates and indices
const _meta = {
Expand Down Expand Up @@ -324,7 +334,7 @@ function getBaseTemplate(
// To be filled with the aliases that we need
aliases: {},
},
data_stream: {},
data_stream: { hidden },
composed_of: composedOfTemplates,
_meta,
};
Expand Down

0 comments on commit 06993c4

Please sign in to comment.