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] added time_series_metric mapping for metric_type package field #126322

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -714,42 +714,53 @@ 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: {
metric_type: 'gauge',
unit: 'percent',
},
time_series_metric: '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 +776,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 +791,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 = field.metric_type;
}
break;
case 'text':
const textMapping = generateTextMapping(field);
Expand Down