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

[Infrastructure UI][Rules] Add recovery context to Log Threshold rule #131279

Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -163,6 +163,42 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) =>
startedAt.valueOf()
);
}

const { getRecoveredAlerts } = services.alertFactory.done();
const recoveredAlerts = getRecoveredAlerts();
for (const alert of recoveredAlerts) {
simianhacker marked this conversation as resolved.
Show resolved Hide resolved
const recoveredAlertId = alert.getId();
const indexedStartedAt = getAlertStartedDate(recoveredAlertId) ?? startedAt.toISOString();
const relativeViewInAppUrl = getLogsAppAlertUrl(new Date(indexedStartedAt).getTime());
const viewInAppUrl = basePath.publicBaseUrl
? new URL(basePath.prepend(relativeViewInAppUrl), basePath.publicBaseUrl).toString()
: relativeViewInAppUrl;

const baseContext = {
group: hasGroupBy(validatedParams) ? recoveredAlertId : null,
timestamp: startedAt.toISOString(),
viewInAppUrl,
};

if (isRatioRuleParams(validatedParams)) {
const { criteria } = validatedParams;
const context = {
...baseContext,
numeratorConditions: createConditionsMessageForCriteria(getNumerator(criteria)),
denominatorConditions: createConditionsMessageForCriteria(getDenominator(criteria)),
isRatio: true,
};
alert.setContext(context);
} else {
const { criteria } = validatedParams;
const context = {
...baseContext,
conditions: createConditionsMessageForCriteria(criteria),
isRatio: false,
};
alert.setContext(context);
}
}
} catch (e) {
throw new Error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export async function registerLogThresholdRuleType(
minimumLicenseRequired: 'basic',
isExportable: true,
executor: createLogThresholdExecutor(libs),
doesSetRecoveryContext: true,
actionVariables: {
context: [
{ name: 'timestamp', description: timestampActionVariableDescription },
Expand Down