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

[Response Ops][Alerting] Migrate installation of context-specific component templates, index templates and concrete write index to framework for alerts-as-data #151792

Merged
merged 15 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
export * from './alert_field_map';
export * from './ecs_field_map';
export * from './legacy_alert_field_map';
export * from './legacy_experimental_field_map';
export type { FieldMap, MultiField } from './types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from x-pack/plugins/rule_registry/common/assets/field_maps/experimental_rule_field_map.ts

* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { ALERT_EVALUATION_THRESHOLD, ALERT_EVALUATION_VALUE } from '@kbn/rule-data-utils';

export const legacyExperimentalFieldMap = {
[ALERT_EVALUATION_THRESHOLD]: {
type: 'scaled_float',
scaling_factor: 100,
required: false,
},
[ALERT_EVALUATION_VALUE]: { type: 'scaled_float', scaling_factor: 100, required: false },
} as const;

export type ExperimentalRuleFieldMap = typeof legacyExperimentalFieldMap;
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { getComponentTemplateFromFieldMap } from './component_template_from_field_map';
import { testFieldMap, expectedTestMapping } from './mapping_from_field_map.test';

describe('getComponentTemplateFromFieldMap', () => {
it('correctly creates component template from field map', () => {
expect(
getComponentTemplateFromFieldMap({ name: 'test-mappings', fieldMap: testFieldMap })
).toEqual({
name: 'test-mappings',
_meta: {
managed: true,
},
template: {
settings: {},
mappings: {
dynamic: 'strict',
...expectedTestMapping,
},
},
});
});

it('correctly creates component template with settings when includeSettings = true', () => {
expect(
getComponentTemplateFromFieldMap({
name: 'test-mappings',
fieldMap: testFieldMap,
includeSettings: true,
})
).toEqual({
name: 'test-mappings',
_meta: {
managed: true,
},
template: {
settings: {
number_of_shards: 1,
'index.mapping.total_fields.limit': 1500,
},
mappings: {
dynamic: 'strict',
...expectedTestMapping,
},
},
});
});

it('correctly creates component template with dynamic setting when defined', () => {
expect(
getComponentTemplateFromFieldMap({
name: 'test-mappings',
fieldMap: testFieldMap,
includeSettings: true,
dynamic: false,
})
).toEqual({
name: 'test-mappings',
_meta: {
managed: true,
},
template: {
settings: {
number_of_shards: 1,
'index.mapping.total_fields.limit': 1500,
},
mappings: {
dynamic: false,
...expectedTestMapping,
},
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { mappingFromFieldMap } from './mapping_from_field_map';

export interface GetComponentTemplateFromFieldMapOpts {
name: string;
fieldLimit?: number;
fieldMap: FieldMap;
includeSettings?: boolean;
dynamic?: 'strict' | boolean;
mikecote marked this conversation as resolved.
Show resolved Hide resolved
}
export const getComponentTemplateFromFieldMap = ({
name,
fieldMap,
fieldLimit,
dynamic,
includeSettings,
}: GetComponentTemplateFromFieldMapOpts): ClusterPutComponentTemplateRequest => {
return {
name,
Expand All @@ -26,10 +28,16 @@ export const getComponentTemplateFromFieldMap = ({
},
template: {
settings: {
number_of_shards: 1,
'index.mapping.total_fields.limit': fieldLimit ?? 1000,
...(includeSettings
? {
number_of_shards: 1,
'index.mapping.total_fields.limit':
Math.ceil(Object.keys(fieldMap).length / 1000) * 1000 + 500,
}
: {}),
},
mappings: mappingFromFieldMap(fieldMap, 'strict'),

mappings: mappingFromFieldMap(fieldMap, dynamic ?? 'strict'),
},
};
};
Loading