Skip to content

Commit

Permalink
Registering all rule types with alerting and conditionally having fra…
Browse files Browse the repository at this point in the history
…mework install context specific resources
  • Loading branch information
ymao1 committed Feb 27, 2023
1 parent dcf752e commit cc24f4d
Show file tree
Hide file tree
Showing 64 changed files with 1,390 additions and 565 deletions.
1 change: 1 addition & 0 deletions packages/kbn-alerts-as-data-utils/src/field_maps/index.ts
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 @@
/*
* 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;
}
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

0 comments on commit cc24f4d

Please sign in to comment.