Skip to content
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

[Fleet] Installation of hidden field #85703

Merged
merged 12 commits into from
Dec 14, 2020
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