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

[event log] setting event log index mappings when creating initial index #128293

Closed
pmuellr opened this issue Mar 22, 2022 · 2 comments
Closed

[event log] setting event log index mappings when creating initial index #128293

pmuellr opened this issue Mar 22, 2022 · 2 comments
Labels
Feature:EventLog Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@pmuellr
Copy link
Member

pmuellr commented Mar 22, 2022

Currently when a new set of event log elasticsearch resources are being created (because a new deployment, or deployment upgraded their stack version), we perform the following steps:

  • create index template that includes mappings
  • create initial index that should reference the index template for default settings, including the mappings

full steps:

async function initializeEsResources(esContext: EsContext) {
const steps = new EsInitializationSteps(esContext);
await steps.setExistingAssetsToHidden();
await steps.createIlmPolicyIfNotExists();
await steps.createIndexTemplateIfNotExists();
await steps.createInitialIndexIfNotExists();
}

The assumption is that the mappings will be in the template, and then used when we create the initial index. So we don't set the mappings in the create index call:

async createInitialIndexIfNotExists(): Promise<void> {
const exists = await this.esContext.esAdapter.doesAliasExist(this.esContext.esNames.alias);
if (!exists) {
await this.esContext.esAdapter.createIndex(this.esContext.esNames.initialIndex, {
aliases: {
[this.esContext.esNames.alias]: {
is_write_index: true,
is_hidden: true,
},
},
});
}
}

However, we do have an issue from a user where the default auto-mapping policy was used for the initial event log index, which ends up creating an event log index that we can't search over correctly (because the auto-mapped field names don't correspond to what we're using for keyword/text, etc).

It's not clear HOW this happened. But in case there was some kind of race condition going on (the user we saw this with had two Kibana's running / restarting after an upgrade simultaneously), it seems safer to just set the mappings in the create call itself - as well as in the template (for ILM-created indices once ILM rolls over an index).

I suspect we'll want to chat with Elasticsearch folks on the best approach here. Maybe it's safer to create the index with the mappings, and THEN create the template? The mappings will be same for both. And I'd guess we want to apply ALL the template settings, not just mappings. Here's what we currently set in the template:

export function getIndexTemplate(esNames: EsNames) {
const indexTemplateBody = {
index_patterns: [esNames.indexPatternWithVersion],
template: {
settings: {
number_of_shards: 1,
auto_expand_replicas: '0-1',
'index.lifecycle.name': esNames.ilmPolicy,
'index.lifecycle.rollover_alias': esNames.alias,
'index.hidden': true,
},
mappings,
},
};
return indexTemplateBody;
}

It's possible the problem encountered by the user could have happened through human intervention. Perhaps the user removed some of the event log resources (like the template), then restored the actual event log index and with no template, the auto-mapping got applied. I think any solution we're looking for here should hopefully prevent the auto-mapping from occurring via scenarios like this.

related: #127029

@pmuellr pmuellr added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:EventLog labels Mar 22, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@mikecote
Copy link
Contributor

Closing in favour of #127029.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:EventLog Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
None yet
Development

No branches or pull requests

3 participants