[Fleet] added time_series_metric mapping for metric_type package field (#126322)

* moved metric_type to time_series_metric mapping

* added back meta.metric_type for bwc, made time_series_metric to string
This commit is contained in:
Julia Bardi 2022-02-24 17:35:16 +01:00 committed by GitHub
parent 28bf2aaa26
commit bb0e70f1c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 29 deletions

View file

@ -714,19 +714,52 @@ describe('EPM template', () => {
expect(mappings).toEqual(expectedMapping);
});
it('tests processing metric_type field', () => {
const literalYml = `
- name: total.norm.pct
type: scaled_float
metric_type: gauge
unit: percent
format: percent
`;
const expectedMapping = {
properties: {
total: {
properties: {
norm: {
properties: {
pct: {
scaling_factor: 1000,
type: 'scaled_float',
meta: {
metric_type: 'gauge',
unit: 'percent',
},
time_series_metric: 'gauge',
},
},
},
},
},
},
};
const fields: Field[] = safeLoad(literalYml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
});
it('processes meta fields', () => {
const metaFieldLiteralYaml = `
- name: fieldWithMetas
type: integer
unit: byte
metric_type: gauge
`;
const metaFieldMapping = {
properties: {
fieldWithMetas: {
type: 'long',
meta: {
metric_type: 'gauge',
unit: 'byte',
},
},
@ -738,43 +771,18 @@ describe('EPM template', () => {
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(metaFieldMapping));
});
it('processes meta fields with only one meta value', () => {
const metaFieldLiteralYaml = `
- name: fieldWithMetas
type: integer
metric_type: gauge
`;
const metaFieldMapping = {
properties: {
fieldWithMetas: {
type: 'long',
meta: {
metric_type: 'gauge',
},
},
},
};
const fields: Field[] = safeLoad(metaFieldLiteralYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(metaFieldMapping));
});
it('processes grouped meta fields', () => {
const metaFieldLiteralYaml = `
- name: groupWithMetas
type: group
unit: byte
metric_type: gauge
fields:
- name: fieldA
type: integer
unit: byte
metric_type: gauge
- name: fieldB
type: integer
unit: byte
metric_type: gauge
`;
const metaFieldMapping = {
properties: {
@ -783,14 +791,12 @@ describe('EPM template', () => {
fieldA: {
type: 'long',
meta: {
metric_type: 'gauge',
unit: 'byte',
},
},
fieldB: {
type: 'long',
meta: {
metric_type: 'gauge',
unit: 'byte',
},
},

View file

@ -132,6 +132,9 @@ export function generateMappings(fields: Field[]): IndexTemplateMappings {
case 'scaled_float':
fieldProps.type = 'scaled_float';
fieldProps.scaling_factor = field.scaling_factor || DEFAULT_SCALING_FACTOR;
if (field.metric_type) {
fieldProps.time_series_metric = field.metric_type;
}
break;
case 'text':
const textMapping = generateTextMapping(field);