Skip to content

Commit

Permalink
Call flapping in the task runner
Browse files Browse the repository at this point in the history
  • Loading branch information
doakalexi committed Feb 27, 2023
1 parent 271b602 commit f80335b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createAlertFactory, getPublicAlertFactory } from '../alert/create_alert
import { Alert } from '../alert/alert';
import { alertingEventLoggerMock } from '../lib/alerting_event_logger/alerting_event_logger.mock';
import { ruleRunMetricsStoreMock } from '../lib/rule_run_metrics_store.mock';
import { getAlertsForNotification, processAlerts, setFlapping } from '../lib';
import { getAlertsForNotification, processAlerts } from '../lib';
import { logAlerts } from '../task_runner/log_alerts';
import { DEFAULT_FLAPPING_SETTINGS } from '../../common/rules_settings';

Expand Down Expand Up @@ -254,19 +254,6 @@ describe('Legacy Alerts Client', () => {
flappingSettings: DEFAULT_FLAPPING_SETTINGS,
});

expect(setFlapping).toHaveBeenCalledWith(
{
enabled: true,
lookBackWindow: 20,
statusChangeThreshold: 4,
},
{
'1': new Alert<AlertInstanceContext, AlertInstanceContext>('1', testAlert1),
'2': new Alert<AlertInstanceContext, AlertInstanceContext>('2', testAlert2),
},
{}
);

expect(getAlertsForNotification).toHaveBeenCalledWith(
{
enabled: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@ export class LegacyAlertsClient<
canSetRecoveryContext: this.options.ruleType.doesSetRecoveryContext ?? false,
shouldPersistAlerts: shouldLogAndScheduleActionsForAlerts,
});

setFlapping<State, Context, ActionGroupIds, RecoveryActionGroupId>(
flappingSettings,
this.processedAlerts.active,
this.processedAlerts.recovered
);
}

public getProcessedAlerts(
Expand Down Expand Up @@ -213,4 +207,12 @@ export class LegacyAlertsClient<
public getExecutorServices() {
return getPublicAlertFactory(this.alertFactory!);
}

public setFlapping(flappingSettings: RulesSettingsFlappingProperties) {
setFlapping<State, Context, ActionGroupIds, RecoveryActionGroupId>(
flappingSettings,
this.processedAlerts.active,
this.processedAlerts.recovered
);
}
}
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ export class TaskRunner<
}
});

this.legacyAlertsClient.setFlapping(flappingSettings);

let alertsToReturn: Record<string, RawAlertInstance> = {};
let recoveredAlertsToReturn: Record<string, RawAlertInstance> = {};
// Only serialize alerts into task state if we're auto-recovering, otherwise
Expand Down

0 comments on commit f80335b

Please sign in to comment.