Skip to content

Commit

Permalink
moved metric_type to time_series_metric mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Feb 24, 2022
1 parent a8fb874 commit 3679b56
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -714,42 +714,54 @@ describe('EPM template', () => {
expect(mappings).toEqual(expectedMapping);
});

it('processes meta fields', () => {
const metaFieldLiteralYaml = `
- name: fieldWithMetas
type: integer
unit: byte
it('tests processing metric_type field', () => {
const literalYml = `
- name: total.norm.pct
type: scaled_float
metric_type: gauge
`;
const metaFieldMapping = {
unit: percent
format: percent
`;
const expectedMapping = {
properties: {
fieldWithMetas: {
type: 'long',
meta: {
metric_type: 'gauge',
unit: 'byte',
total: {
properties: {
norm: {
properties: {
pct: {
scaling_factor: 1000,
type: 'scaled_float',
meta: {
unit: 'percent',
},
time_series_metric: {
type: 'gauge',
},
},
},
},
},
},
},
};
const fields: Field[] = safeLoad(metaFieldLiteralYaml);
const fields: Field[] = safeLoad(literalYml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(metaFieldMapping));
expect(mappings).toEqual(expectedMapping);
});

it('processes meta fields with only one meta value', () => {
it('processes meta fields', () => {
const metaFieldLiteralYaml = `
- name: fieldWithMetas
type: integer
metric_type: gauge
unit: byte
`;
const metaFieldMapping = {
properties: {
fieldWithMetas: {
type: 'long',
meta: {
metric_type: 'gauge',
unit: 'byte',
},
},
},
Expand All @@ -765,16 +777,13 @@ describe('EPM template', () => {
- 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: {
Expand All @@ -783,14 +792,12 @@ describe('EPM template', () => {
fieldA: {
type: 'long',
meta: {
metric_type: 'gauge',
unit: 'byte',
},
},
fieldB: {
type: 'long',
meta: {
metric_type: 'gauge',
unit: 'byte',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { type: field.metric_type };
}
break;
case 'text':
const textMapping = generateTextMapping(field);
Expand Down Expand Up @@ -193,7 +196,6 @@ export function generateMappings(fields: Field[]): IndexTemplateMappings {
break;
default: {
const meta = {};
if ('metric_type' in field) Reflect.set(meta, 'metric_type', field.metric_type);
if ('unit' in field) Reflect.set(meta, 'unit', field.unit);
fieldProps.meta = meta;
}
Expand Down

0 comments on commit 3679b56

Please sign in to comment.