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] Move mappings from index template to component template #124013

Merged
merged 32 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c28b89a
cherry pick from old branch
hop-dev Jan 28, 2022
f826fd6
use global template
hop-dev Jan 28, 2022
cfbf18d
re-add _meta to index template
hop-dev Jan 28, 2022
197cb06
simplify merge
hop-dev Jan 28, 2022
fee70b8
fix component_template test
hop-dev Jan 28, 2022
5a7a516
add settings to mapping component template
hop-dev Jan 28, 2022
2f5ff81
put mapping settings on @mapping component template
hop-dev Jan 31, 2022
7c99da4
fix snapshot
hop-dev Jan 31, 2022
9b01189
fix integration tests
hop-dev Jan 31, 2022
aa11922
fix component template order and test
hop-dev Jan 31, 2022
d00189f
use mapping component template for updating backing indices
hop-dev Feb 4, 2022
a9950a3
fix tests
hop-dev Feb 4, 2022
bbd973f
move code to util functions
hop-dev Feb 4, 2022
e10054e
add comment
hop-dev Feb 4, 2022
5ded642
split global templates
hop-dev Feb 23, 2022
d9d25dc
update snaphsot
hop-dev Feb 24, 2022
e52e168
rename variables
hop-dev Feb 24, 2022
9f91941
fix tests again
hop-dev Feb 24, 2022
627f101
reinstall bundled packages when component templates change
hop-dev Mar 1, 2022
6b7c00c
combine compoised_of generation statements
hop-dev Mar 2, 2022
064a9d6
remove duplicated global fields
hop-dev Mar 2, 2022
bbd8730
remove unnecessary rollover call
hop-dev Mar 2, 2022
65cec55
use rollover API
hop-dev Mar 2, 2022
c067e5e
use simulate API to get template content
hop-dev Mar 7, 2022
74ccc14
remove unused parameters
hop-dev Mar 7, 2022
8ddebf0
fix unit test
hop-dev Mar 7, 2022
7bd7db2
Merge branch 'main' into 121184-move-mappings-to-component-tmpl
hop-dev Mar 10, 2022
8270184
improve simulate error handling
hop-dev Mar 10, 2022
b98aa0c
re-add removed mapping assertions
hop-dev Mar 10, 2022
cca119e
Merge branch 'main' into 121184-move-mappings-to-component-tmpl
hop-dev Mar 10, 2022
43568ce
fix test
hop-dev Mar 14, 2022
67aafbb
Merge branch 'main' into 121184-move-mappings-to-component-tmpl
hop-dev Mar 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,25 @@ export interface IndexTemplate {
_meta: object;
}

export interface ESAssetMetadata {
package?: {
name: string;
};
managed_by: string;
managed: boolean;
}
export interface TemplateMapEntry {
_meta: ESAssetMetadata;
template:
| {
mappings: NonNullable<RegistryElasticsearch['index_template.mappings']>;
}
| {
settings: NonNullable<RegistryElasticsearch['index_template.settings']> | object;
};
}

export type TemplateMap = Record<string, TemplateMapEntry>;
export interface IndexTemplateEntry {
templateName: string;
indexTemplate: IndexTemplate;
Expand Down
44 changes: 42 additions & 2 deletions x-pack/plugins/fleet/server/constants/fleet_es_assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,44 @@
import { getESAssetMetadata } from '../services/epm/elasticsearch/meta';

const meta = getESAssetMetadata();
export const MAPPINGS_TEMPLATE_SUFFIX = '@mappings';

export const SETTINGS_TEMPLATE_SUFFIX = '@settings';

export const USER_SETTINGS_TEMPLATE_SUFFIX = '@custom';

export const FLEET_FINAL_PIPELINE_ID = '.fleet_final_pipeline-1';

export const FLEET_GLOBAL_COMPONENT_TEMPLATE_NAME = '.fleet_component_template-1';
export const FLEET_GLOBALS_COMPONENT_TEMPLATE_NAME = '.fleet_globals-1';

export const FLEET_GLOBALS_COMPONENT_TEMPLATE_CONTENT = {
_meta: meta,
template: {
settings: {},
mappings: {
_meta: meta,
// All the dynamic field mappings
dynamic_templates: [
// This makes sure all mappings are keywords by default
{
strings_as_keyword: {
mapping: {
ignore_above: 1024,
type: 'keyword',
},
match_mapping_type: 'string',
},
},
],
// As we define fields ahead, we don't need any automatic field detection
// This makes sure all the fields are mapped to keyword by default to prevent mapping conflicts
date_detection: false,
},
},
};
export const FLEET_AGENT_ID_VERIFY_COMPONENT_TEMPLATE_NAME = '.fleet_agent_id_verification-1';

export const FLEET_GLOBAL_COMPONENT_TEMPLATE_CONTENT = {
export const FLEET_AGENT_ID_VERIFY_COMPONENT_TEMPLATE_CONTENT = {
_meta: meta,
template: {
settings: {
Expand All @@ -40,6 +72,14 @@ export const FLEET_GLOBAL_COMPONENT_TEMPLATE_CONTENT = {
},
};

export const FLEET_COMPONENT_TEMPLATES = [
{ name: FLEET_GLOBALS_COMPONENT_TEMPLATE_NAME, body: FLEET_GLOBALS_COMPONENT_TEMPLATE_CONTENT },
{
name: FLEET_AGENT_ID_VERIFY_COMPONENT_TEMPLATE_NAME,
body: FLEET_AGENT_ID_VERIFY_COMPONENT_TEMPLATE_CONTENT,
},
];

export const FLEET_FINAL_PIPELINE_VERSION = 2;

// If the content is updated you probably need to update the FLEET_FINAL_PIPELINE_VERSION too to allow upgrade of the pipeline
Expand Down
10 changes: 8 additions & 2 deletions x-pack/plugins/fleet/server/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ export {
} from '../../common';

export {
FLEET_GLOBAL_COMPONENT_TEMPLATE_NAME,
FLEET_GLOBAL_COMPONENT_TEMPLATE_CONTENT,
FLEET_GLOBALS_COMPONENT_TEMPLATE_NAME,
FLEET_GLOBALS_COMPONENT_TEMPLATE_CONTENT,
FLEET_AGENT_ID_VERIFY_COMPONENT_TEMPLATE_NAME,
FLEET_AGENT_ID_VERIFY_COMPONENT_TEMPLATE_CONTENT,
FLEET_COMPONENT_TEMPLATES,
FLEET_FINAL_PIPELINE_ID,
FLEET_FINAL_PIPELINE_CONTENT,
FLEET_FINAL_PIPELINE_VERSION,
MAPPINGS_TEMPLATE_SUFFIX,
SETTINGS_TEMPLATE_SUFFIX,
USER_SETTINGS_TEMPLATE_SUFFIX,
} from './fleet_es_assets';
10 changes: 2 additions & 8 deletions x-pack/plugins/fleet/server/services/epm/elasticsearch/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@

import { safeLoad, safeDump } from 'js-yaml';

const MANAGED_BY_DEFAULT = 'fleet';
import type { ESAssetMetadata } from '../../../../common/types';

export interface ESAssetMetadata {
package?: {
name: string;
};
managed_by: string;
managed: boolean;
}
const MANAGED_BY_DEFAULT = 'fleet';

/**
* Build common metadata object for Elasticsearch assets installed by Fleet. Result should be
Expand Down
Loading