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

[APM\ Update index template names considered in the diagnostics page #184343

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { IndicesGetIndexTemplateIndexTemplateItem } from '@elastic/elasticsearch/lib/api/types';

const suffix = 'template';
export function getApmIndexTemplateNames() {
const indexTemplateNames = [
'logs-apm.app',
Expand All @@ -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);

return {
name: templateName,
exists: Boolean(matchingTemplate),
isNonStandard: false,
};
});
const standardIndexTemplates = Object.entries(apmIndexTemplateNames).map(
([baseTemplateName, validIndexTemplateNames]) => {
const matchingTemplate = validIndexTemplateNames.find((templateName) =>
existingIndexTemplates.find(({ name }) => name === templateName)
);

return {
name: matchingTemplate ?? baseTemplateName,
exists: Boolean(matchingTemplate),
isNonStandard: false,
};
}
);

const nonStandardIndexTemplates = existingIndexTemplates
.filter(
Expand Down