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

[Entity Analytics] API changes for right placement of deleting the old component template #199734

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -136,14 +136,6 @@ export class RiskScoreDataClient {
});
}

// Delete the component template without the namespace in the name
await esClient.cluster.deleteComponentTemplate(
{
name: mappingComponentName,
},
{ ignore: [404] }
);

// Update the new component template with the required data
await Promise.all([
createOrUpdateComponentTemplate({
Expand Down Expand Up @@ -210,6 +202,14 @@ export class RiskScoreDataClient {
},
});

// Delete the component template without the namespace in the name
abhishekbhatia1710 marked this conversation as resolved.
Show resolved Hide resolved
await esClient.cluster.deleteComponentTemplate(
{
name: mappingComponentName,
},
{ ignore: [404] }
);

this.options.auditLogger?.log({
message: 'System installed risk engine Elasticsearch components',
event: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,86 @@ export default ({ getService }: FtrProviderContext) => {
firstResponse?.saved_objects?.[0]?.id
);
});

it('should update the existing component template and index template without any errors', async () => {
abhishekbhatia1710 marked this conversation as resolved.
Show resolved Hide resolved
const componentTemplateName = '.risk-score-mappings';
const indexTemplateName = '.risk-score.risk-score-default-index-template';
const newComponentTemplateName = '.risk-score-mappings-default';

// Call API to put the component template and index template

await es.cluster.putComponentTemplate({
name: componentTemplateName,
body: {
template: {
settings: {
number_of_shards: 1,
},
mappings: {
properties: {
timestamp: {
type: 'date',
},
user: {
properties: {
id: {
type: 'keyword',
},
name: {
type: 'text',
},
},
},
},
},
},
version: 1,
},
});

// Call an API to put the index template

await es.indices.putIndexTemplate({
name: indexTemplateName,
body: {
index_patterns: [indexTemplateName],
composed_of: [componentTemplateName],
template: {
settings: {
number_of_shards: 1,
},
mappings: {
properties: {
timestamp: {
type: 'date',
},
user: {
properties: {
id: {
type: 'keyword',
},
name: {
type: 'text',
},
},
},
},
},
},
},
});

const response = await riskEngineRoutes.init();
expect(response.status).to.eql(200);
expect(response.body.result.errors).to.eql([]);

const response2 = await es.cluster.getComponentTemplate({
name: newComponentTemplateName,
});
expect(response2.component_templates.length).to.eql(1);
expect(response2.component_templates[0].name).to.eql(newComponentTemplateName);
});

// Failing: See https://github.com/elastic/kibana/issues/191637
describe.skip('remove legacy risk score transform', function () {
this.tags('skipFIPS');
Expand Down