Skip to content

[Alerting] event log is not "disabled" when initialization fails #68309

@pmuellr

Description

@pmuellr

When the event log ES initialization fails, the event log itself should be in a "disabled" state where it won't write event documents to the index. But it appears we've only done some of the work on this.

The code below is where the documents are indexed:

async function indexLogEventDoc(esContext: EsContext, doc: unknown) {
esContext.logger.debug(`writing to event log: ${JSON.stringify(doc)}`);
await esContext.waitTillReady();
await esContext.esAdapter.indexDocument(doc);
esContext.logger.debug(`writing to event log complete`);
}

The waitTillReady() call actually returns a boolean indicating whether initialized completed successfully, but we don't check it. We should check the result and not write when it returns false.

The value returned by waitTillReady() is set here:

initialize() {
// only run the initialization method once
if (this.initialized) return;
this.initialized = true;
this.logger.debug('initializing EsContext');
setImmediate(async () => {
try {
await this._initialize();
this.logger.debug('readySignal.signal(true)');
this.readySignal.signal(true);
} catch (err) {
this.logger.debug('readySignal.signal(false)');
this.readySignal.signal(false);
}
});
}
async waitTillReady(): Promise<boolean> {
return await this.readySignal.wait();
}
private async _initialize() {
await initializeEs(this);
}
}

It's only set to false when _initialize() throws an error, but the initializeEs() call in _initialize() (scroll down to the bottom of this snippet) can also return false when an error is detected.

Not immediately clear if we should even bother with these booleans set on the inner calls, when we could just throw an error instead of returning the boolean. Probably worth looking at them a little closer to see if that would be a simplification.

Metadata

Metadata

Assignees

Labels

Feature:AlertingTeam:ResponseOpsPlatform ResponseOps team (formerly the Cases and Alerting teams) t//bugFixes for quality problems that affect the customer experience

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions