mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[APM\ Update index template names considered in the diagnostics page (#184343)
closes [#184333](https://github.com/elastic/kibana/issues/184333) ## Summary This PR updates the index template names that the diagnostics page verifies the existence of. After the changes made in the [APM package](https://github.com/elastic/integrations/pull/9949), to favor APM indices and ingest pipelines configured by elasticsearch, the index templates now have a `@template` suffix. eg: `metrics-apm.service_destination.1m` is now `metrics-apm.service_destination.1m@template` <img width="709" alt="image" src="4608da37
-679a-411c-85c4-409b2af62cec"> <img width="709" alt="image" src="837c8ae0
-2c92-4763-811c-22fc619ba5f6"> **When no indices are found** <img width="709" alt="image" src="33d7264a
-dc90-49a0-a3f4-f169dcbda861"> ### How to test - Start a local ES and kibana instance - navigate to `/apm/diagnostics/index-templates?rangeFrom=now-15m&rangeTo=now` --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
cf1ff97c12
commit
ad27105af8
6 changed files with 43 additions and 25 deletions
|
@ -19,10 +19,12 @@ export async function getExistingApmIndexTemplates({
|
|||
}) {
|
||||
const apmIndexTemplateNames = getApmIndexTemplateNames();
|
||||
const values = await Promise.all(
|
||||
apmIndexTemplateNames.map(async (indexTemplateName) => {
|
||||
const res = await getIndexTemplate(esClient, { name: indexTemplateName });
|
||||
return res.index_templates[0];
|
||||
})
|
||||
Object.values(apmIndexTemplateNames)
|
||||
.flat()
|
||||
.map(async (indexTemplateName) => {
|
||||
const res = await getIndexTemplate(esClient, { name: indexTemplateName });
|
||||
return res.index_templates[0];
|
||||
})
|
||||
);
|
||||
|
||||
return values.filter((v) => v !== undefined);
|
||||
|
|
|
@ -79,12 +79,13 @@ async function getTemplatePriority(esClient: ElasticsearchClient, name: string)
|
|||
function getIsNonStandardIndexTemplate(templateName: string) {
|
||||
const apmIndexTemplateNames = getApmIndexTemplateNames();
|
||||
const stackIndexTemplateNames = ['logs', 'metrics'];
|
||||
const isNonStandard = [...apmIndexTemplateNames, ...stackIndexTemplateNames].every(
|
||||
(apmIndexTemplateName) => {
|
||||
const notMatch = templateName !== apmIndexTemplateName;
|
||||
return notMatch;
|
||||
}
|
||||
);
|
||||
const isNonStandard = [
|
||||
...Object.values(apmIndexTemplateNames).flat(),
|
||||
...stackIndexTemplateNames,
|
||||
].every((apmIndexTemplateName) => {
|
||||
const notMatch = templateName !== apmIndexTemplateName;
|
||||
return notMatch;
|
||||
});
|
||||
|
||||
return isNonStandard;
|
||||
}
|
||||
|
|
|
@ -85,8 +85,10 @@ export function validateIngestPipelineName(
|
|||
}
|
||||
|
||||
const indexTemplateNames = getApmIndexTemplateNames();
|
||||
return indexTemplateNames.some(
|
||||
(indexTemplateName) =>
|
||||
dataStream.startsWith(indexTemplateName) && ingestPipelineId.startsWith(indexTemplateName)
|
||||
);
|
||||
return Object.values(indexTemplateNames)
|
||||
.flat()
|
||||
.some(
|
||||
(indexTemplateName) =>
|
||||
dataStream.startsWith(indexTemplateName) && ingestPipelineId.startsWith(indexTemplateName)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import { IndicesGetIndexTemplateIndexTemplateItem } from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
const suffix = 'template';
|
||||
export function getApmIndexTemplateNames() {
|
||||
const indexTemplateNames = [
|
||||
'logs-apm.app',
|
||||
|
@ -27,22 +28,30 @@ export function getApmIndexTemplateNames() {
|
|||
].map((ds) => `${ds}.${interval}`);
|
||||
});
|
||||
|
||||
return [...indexTemplateNames, ...rollupIndexTemplateNames];
|
||||
// For retrocompatibility, it returns index template names both pre and post APM integration package v8.15.0
|
||||
return [...indexTemplateNames, ...rollupIndexTemplateNames].reduce((acc, indexTemplateName) => {
|
||||
acc[indexTemplateName] = [indexTemplateName, `${indexTemplateName}@${suffix}`];
|
||||
return acc;
|
||||
}, {} as Record<string, string[]>);
|
||||
}
|
||||
|
||||
export function getApmIndexTemplates(
|
||||
existingIndexTemplates: IndicesGetIndexTemplateIndexTemplateItem[]
|
||||
) {
|
||||
const apmIndexTemplateNames = getApmIndexTemplateNames();
|
||||
const standardIndexTemplates = apmIndexTemplateNames.map((templateName) => {
|
||||
const matchingTemplate = existingIndexTemplates.find(({ name }) => name === templateName);
|
||||
const standardIndexTemplates = Object.entries(apmIndexTemplateNames).map(
|
||||
([baseTemplateName, validIndexTemplateNames]) => {
|
||||
const matchingTemplate = validIndexTemplateNames.find((templateName) =>
|
||||
existingIndexTemplates.find(({ name }) => name === templateName)
|
||||
);
|
||||
|
||||
return {
|
||||
name: templateName,
|
||||
exists: Boolean(matchingTemplate),
|
||||
isNonStandard: false,
|
||||
};
|
||||
});
|
||||
return {
|
||||
name: matchingTemplate ?? baseTemplateName,
|
||||
exists: Boolean(matchingTemplate),
|
||||
isNonStandard: false,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const nonStandardIndexTemplates = existingIndexTemplates
|
||||
.filter(
|
||||
|
|
|
@ -24,7 +24,9 @@ export default function ApiTest({ getService }: FtrProviderContext) {
|
|||
describe('When there is no data', () => {
|
||||
before(async () => {
|
||||
// delete APM index templates
|
||||
await es.indices.deleteIndexTemplate({ name: getApmIndexTemplateNames() });
|
||||
await es.indices.deleteIndexTemplate({
|
||||
name: Object.values(getApmIndexTemplateNames()).flat(),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the built-in (non-APM) index templates`', async () => {
|
||||
|
|
|
@ -24,7 +24,9 @@ export default function ApiTest({ getService }: FtrProviderContext) {
|
|||
describe('When there is no data', () => {
|
||||
before(async () => {
|
||||
// delete APM index templates
|
||||
await es.indices.deleteIndexTemplate({ name: getApmIndexTemplateNames() });
|
||||
await es.indices.deleteIndexTemplate({
|
||||
name: Object.values(getApmIndexTemplateNames()).flat(),
|
||||
});
|
||||
});
|
||||
|
||||
it('verifies that none of the default APM index templates exists`', async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue