mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Backport https://github.com/elastic/kibana/pull/171712 to 8.11
This commit is contained in:
parent
7f1b79c580
commit
eec5208619
5 changed files with 143 additions and 64 deletions
|
@ -534,7 +534,7 @@ export function prepareTemplate({
|
|||
|
||||
const validFields = processFields(fields);
|
||||
|
||||
const mappings = generateMappings(validFields);
|
||||
const mappings = generateMappings(validFields, isIndexModeTimeSeries);
|
||||
const templateName = generateTemplateName(dataStream);
|
||||
const templateIndexPattern = generateTemplateIndexPattern(dataStream);
|
||||
const templatePriority = getTemplatePriority(dataStream);
|
||||
|
|
|
@ -851,7 +851,30 @@ describe('EPM template', () => {
|
|||
};
|
||||
const fields: Field[] = safeLoad(literalYml);
|
||||
const processedFields = processFields(fields);
|
||||
const mappings = generateMappings(processedFields);
|
||||
const mappings = generateMappings(processedFields, true);
|
||||
expect(mappings).toEqual(expectedMapping);
|
||||
});
|
||||
|
||||
it('tests processing dimension field on a keyword - tsdb disabled', () => {
|
||||
const literalYml = `
|
||||
- name: example.id
|
||||
type: keyword
|
||||
dimension: true
|
||||
`;
|
||||
const expectedMapping = {
|
||||
properties: {
|
||||
example: {
|
||||
properties: {
|
||||
id: {
|
||||
type: 'keyword',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const fields: Field[] = safeLoad(literalYml);
|
||||
const processedFields = processFields(fields);
|
||||
const mappings = generateMappings(processedFields, false);
|
||||
expect(mappings).toEqual(expectedMapping);
|
||||
});
|
||||
|
||||
|
@ -875,7 +898,7 @@ describe('EPM template', () => {
|
|||
};
|
||||
const fields: Field[] = safeLoad(literalYml);
|
||||
const processedFields = processFields(fields);
|
||||
const mappings = generateMappings(processedFields);
|
||||
const mappings = generateMappings(processedFields, true);
|
||||
expect(mappings).toEqual(expectedMapping);
|
||||
});
|
||||
|
||||
|
@ -909,7 +932,40 @@ describe('EPM template', () => {
|
|||
};
|
||||
const fields: Field[] = safeLoad(literalYml);
|
||||
const processedFields = processFields(fields);
|
||||
const mappings = generateMappings(processedFields);
|
||||
const mappings = generateMappings(processedFields, true);
|
||||
expect(mappings).toEqual(expectedMapping);
|
||||
});
|
||||
|
||||
it('tests processing metric_type field - tsdb disabled', () => {
|
||||
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: {
|
||||
unit: 'percent',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const fields: Field[] = safeLoad(literalYml);
|
||||
const processedFields = processFields(fields);
|
||||
const mappings = generateMappings(processedFields, false);
|
||||
expect(mappings).toEqual(expectedMapping);
|
||||
});
|
||||
|
||||
|
@ -936,7 +992,7 @@ describe('EPM template', () => {
|
|||
};
|
||||
const fields: Field[] = safeLoad(literalYml);
|
||||
const processedFields = processFields(fields);
|
||||
const mappings = generateMappings(processedFields);
|
||||
const mappings = generateMappings(processedFields, true);
|
||||
expect(mappings).toEqual(expectedMapping);
|
||||
});
|
||||
|
||||
|
|
|
@ -119,46 +119,53 @@ export function getTemplate({
|
|||
*
|
||||
* @param fields
|
||||
*/
|
||||
export function generateMappings(fields: Field[]): IndexTemplateMappings {
|
||||
export function generateMappings(
|
||||
fields: Field[],
|
||||
isIndexModeTimeSeries = false
|
||||
): IndexTemplateMappings {
|
||||
const dynamicTemplates: Array<Record<string, Properties>> = [];
|
||||
const dynamicTemplateNames = new Set<string>();
|
||||
const runtimeFields: RuntimeFields = {};
|
||||
|
||||
const { properties } = _generateMappings(fields, {
|
||||
addDynamicMapping: (dynamicMapping: {
|
||||
path: string;
|
||||
matchingType: string;
|
||||
pathMatch: string;
|
||||
properties: string;
|
||||
runtimeProperties?: string;
|
||||
}) => {
|
||||
const name = dynamicMapping.path;
|
||||
if (dynamicTemplateNames.has(name)) {
|
||||
return;
|
||||
}
|
||||
const { properties } = _generateMappings(
|
||||
fields,
|
||||
{
|
||||
addDynamicMapping: (dynamicMapping: {
|
||||
path: string;
|
||||
matchingType: string;
|
||||
pathMatch: string;
|
||||
properties: string;
|
||||
runtimeProperties?: string;
|
||||
}) => {
|
||||
const name = dynamicMapping.path;
|
||||
if (dynamicTemplateNames.has(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dynamicTemplate: Properties = {};
|
||||
if (dynamicMapping.runtimeProperties !== undefined) {
|
||||
dynamicTemplate.runtime = dynamicMapping.runtimeProperties;
|
||||
} else {
|
||||
dynamicTemplate.mapping = dynamicMapping.properties;
|
||||
}
|
||||
const dynamicTemplate: Properties = {};
|
||||
if (dynamicMapping.runtimeProperties !== undefined) {
|
||||
dynamicTemplate.runtime = dynamicMapping.runtimeProperties;
|
||||
} else {
|
||||
dynamicTemplate.mapping = dynamicMapping.properties;
|
||||
}
|
||||
|
||||
if (dynamicMapping.matchingType) {
|
||||
dynamicTemplate.match_mapping_type = dynamicMapping.matchingType;
|
||||
}
|
||||
if (dynamicMapping.matchingType) {
|
||||
dynamicTemplate.match_mapping_type = dynamicMapping.matchingType;
|
||||
}
|
||||
|
||||
if (dynamicMapping.pathMatch) {
|
||||
dynamicTemplate.path_match = dynamicMapping.pathMatch;
|
||||
}
|
||||
if (dynamicMapping.pathMatch) {
|
||||
dynamicTemplate.path_match = dynamicMapping.pathMatch;
|
||||
}
|
||||
|
||||
dynamicTemplateNames.add(name);
|
||||
dynamicTemplates.push({ [dynamicMapping.path]: dynamicTemplate });
|
||||
dynamicTemplateNames.add(name);
|
||||
dynamicTemplates.push({ [dynamicMapping.path]: dynamicTemplate });
|
||||
},
|
||||
addRuntimeField: (runtimeField: { path: string; properties: Properties }) => {
|
||||
runtimeFields[`${runtimeField.path}`] = runtimeField.properties;
|
||||
},
|
||||
},
|
||||
addRuntimeField: (runtimeField: { path: string; properties: Properties }) => {
|
||||
runtimeFields[`${runtimeField.path}`] = runtimeField.properties;
|
||||
},
|
||||
});
|
||||
isIndexModeTimeSeries
|
||||
);
|
||||
|
||||
const indexTemplateMappings: IndexTemplateMappings = { properties };
|
||||
if (dynamicTemplates.length > 0) {
|
||||
|
@ -184,7 +191,8 @@ function _generateMappings(
|
|||
addDynamicMapping: any;
|
||||
addRuntimeField: any;
|
||||
groupFieldName?: string;
|
||||
}
|
||||
},
|
||||
isIndexModeTimeSeries: boolean
|
||||
): {
|
||||
properties: IndexTemplateMappings['properties'];
|
||||
hasNonDynamicTemplateMappings: boolean;
|
||||
|
@ -206,7 +214,7 @@ function _generateMappings(
|
|||
if (type === 'object' && field.object_type) {
|
||||
const pathMatch = path.includes('*') ? path : `${path}.*`;
|
||||
|
||||
let dynProperties: Properties = getDefaultProperties(field);
|
||||
const dynProperties: Properties = getDefaultProperties(field);
|
||||
let matchingType: string | undefined;
|
||||
switch (field.object_type) {
|
||||
case 'keyword':
|
||||
|
@ -216,10 +224,10 @@ function _generateMappings(
|
|||
case 'double':
|
||||
case 'long':
|
||||
case 'boolean':
|
||||
dynProperties = {
|
||||
type: field.object_type,
|
||||
time_series_metric: field.metric_type,
|
||||
};
|
||||
dynProperties.type = field.object_type;
|
||||
if (isIndexModeTimeSeries) {
|
||||
dynProperties.time_series_metric = field.metric_type;
|
||||
}
|
||||
matchingType = field.object_type_mapping_type ?? field.object_type;
|
||||
default:
|
||||
break;
|
||||
|
@ -272,10 +280,10 @@ function _generateMappings(
|
|||
case 'long':
|
||||
case 'short':
|
||||
case 'boolean':
|
||||
dynProperties = {
|
||||
type: field.object_type,
|
||||
time_series_metric: field.metric_type,
|
||||
};
|
||||
dynProperties.type = field.object_type;
|
||||
if (isIndexModeTimeSeries) {
|
||||
dynProperties.time_series_metric = field.metric_type;
|
||||
}
|
||||
matchingType = field.object_type_mapping_type ?? field.object_type;
|
||||
default:
|
||||
break;
|
||||
|
@ -294,12 +302,16 @@ function _generateMappings(
|
|||
|
||||
switch (type) {
|
||||
case 'group':
|
||||
const mappings = _generateMappings(field.fields!, {
|
||||
...ctx,
|
||||
groupFieldName: ctx.groupFieldName
|
||||
? `${ctx.groupFieldName}.${field.name}`
|
||||
: field.name,
|
||||
});
|
||||
const mappings = _generateMappings(
|
||||
field.fields!,
|
||||
{
|
||||
...ctx,
|
||||
groupFieldName: ctx.groupFieldName
|
||||
? `${ctx.groupFieldName}.${field.name}`
|
||||
: field.name,
|
||||
},
|
||||
isIndexModeTimeSeries
|
||||
);
|
||||
if (!mappings.hasNonDynamicTemplateMappings) {
|
||||
return;
|
||||
}
|
||||
|
@ -311,12 +323,16 @@ function _generateMappings(
|
|||
break;
|
||||
case 'group-nested':
|
||||
fieldProps = {
|
||||
properties: _generateMappings(field.fields!, {
|
||||
...ctx,
|
||||
groupFieldName: ctx.groupFieldName
|
||||
? `${ctx.groupFieldName}.${field.name}`
|
||||
: field.name,
|
||||
}).properties,
|
||||
properties: _generateMappings(
|
||||
field.fields!,
|
||||
{
|
||||
...ctx,
|
||||
groupFieldName: ctx.groupFieldName
|
||||
? `${ctx.groupFieldName}.${field.name}`
|
||||
: field.name,
|
||||
},
|
||||
isIndexModeTimeSeries
|
||||
).properties,
|
||||
...generateNestedProps(field),
|
||||
type: 'nested',
|
||||
};
|
||||
|
@ -404,10 +420,10 @@ function _generateMappings(
|
|||
}
|
||||
}
|
||||
|
||||
if ('metric_type' in field) {
|
||||
if ('metric_type' in field && isIndexModeTimeSeries) {
|
||||
fieldProps.time_series_metric = field.metric_type;
|
||||
}
|
||||
if (field.dimension) {
|
||||
if (field.dimension && isIndexModeTimeSeries) {
|
||||
fieldProps.time_series_dimension = field.dimension;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,14 @@ export default function (providerContext: FtrProviderContext) {
|
|||
setupFleetAndAgents(providerContext);
|
||||
|
||||
after(async () => {
|
||||
await deletePackage('istio', '0.3.3');
|
||||
await deletePackage('no_tsdb_to_tsdb', '0.2.0');
|
||||
});
|
||||
|
||||
it('should install with metric_type added as time_series_metric', async function () {
|
||||
const templateName = 'metrics-istio.istiod_metrics@package';
|
||||
const templateName = 'metrics-no_tsdb_to_tsdb.test@package';
|
||||
|
||||
await supertest
|
||||
.post(`/api/fleet/epm/packages/istio/0.3.3`)
|
||||
.post(`/api/fleet/epm/packages/no_tsdb_to_tsdb/0.2.0`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.send({ force: true })
|
||||
.expect(200);
|
||||
|
@ -46,7 +46,7 @@ export default function (providerContext: FtrProviderContext) {
|
|||
|
||||
const template = resp.component_templates[0].component_template;
|
||||
const dynamicTemplates = template.template.mappings.dynamic_templates;
|
||||
const mappingName = 'istio.istiod.metrics.*.counter';
|
||||
const mappingName = 'test.metrics.*.counter';
|
||||
const counter = dynamicTemplates.find((tmpl: any) => Object.keys(tmpl)[0] === mappingName);
|
||||
|
||||
expect(counter[mappingName].mapping.time_series_metric).to.eql('counter');
|
||||
|
|
|
@ -20,3 +20,10 @@
|
|||
- name: 'some_metric_field'
|
||||
type: integer
|
||||
metric_type: gauge
|
||||
- name: test.metrics.*.counter
|
||||
type: object
|
||||
object_type: double
|
||||
object_type_mapping_type: "*"
|
||||
metric_type: counter
|
||||
description: >
|
||||
Istiod counter metric
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue