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

[Alerting] Fixing Failing test: X-Pack Alerting API Integration Tests.x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/rbac_legacy·ts - alerting api integration security and spaces enabled Alerts legacy alerts alerts superuser at space1 should schedule actions on legacy alerts #92549

Merged
merged 17 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -15,7 +15,10 @@ import {
import { schema } from '@kbn/config-schema';
import { InvalidatePendingApiKey } from '../../../../../../../plugins/alerts/server/types';
import { RawAlert } from '../../../../../../../plugins/alerts/server/types';
import { TaskInstance } from '../../../../../../../plugins/task_manager/server';
import {
ConcreteTaskInstance,
TaskInstance,
} from '../../../../../../../plugins/task_manager/server';
import { FixtureStartDeps } from './plugin';

export function defineRoutes(core: CoreSetup<FixtureStartDeps>) {
Expand Down Expand Up @@ -188,6 +191,40 @@ export function defineRoutes(core: CoreSetup<FixtureStartDeps>) {
}
);

router.put(
{
path: '/api/alerts_fixture/{id}/reset_task_status',
validate: {
params: schema.object({
id: schema.string(),
}),
body: schema.object({
status: schema.string(),
}),
},
},
async (
context: RequestHandlerContext,
req: KibanaRequest<any, any, any, any>,
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> => {
const { id } = req.params;
const { status } = req.body;

const [{ savedObjects }] = await core.getStartServices();
const savedObjectsWithTasksAndAlerts = await savedObjects.getScopedClient(req, {
includedHiddenTypes: ['task', 'alert'],
});
const alert = await savedObjectsWithTasksAndAlerts.get<RawAlert>('alert', id);
const result = await savedObjectsWithTasksAndAlerts.update<ConcreteTaskInstance>(
'task',
alert.attributes.scheduledTaskId!,
{ status }
);
return res.ok({ body: result });
}
);

router.get(
{
path: '/api/alerts_fixture/api_keys_pending_invalidation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { setupSpacesAndUsers, tearDown } from '..';
// eslint-disable-next-line import/no-default-export
export default function alertingTests({ loadTestFile, getService }: FtrProviderContext) {
describe('Alerts', () => {
// FLAKY: https://github.com/elastic/kibana/issues/86952
describe.skip('legacy alerts', () => {
describe('legacy alerts', () => {
before(async () => {
await setupSpacesAndUsers(getService);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
case 'space_1_all at space1':
case 'superuser at space1':
case 'space_1_all_with_restricted_fixture at space1':
await resetTaskStatus(migratedAlertId);
await ensureLegacyAlertHasBeenMigrated(migratedAlertId);

await updateMigratedAlertToUseApiKeyOfCurrentUser(migratedAlertId);
Expand All @@ -92,6 +93,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
await ensureAlertIsRunning();
break;
case 'global_read at space1':
await resetTaskStatus(migratedAlertId);
await ensureLegacyAlertHasBeenMigrated(migratedAlertId);

await updateMigratedAlertToUseApiKeyOfCurrentUser(migratedAlertId);
Expand All @@ -115,6 +117,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
});
break;
case 'space_1_all_alerts_none_actions at space1':
await resetTaskStatus(migratedAlertId);
await ensureLegacyAlertHasBeenMigrated(migratedAlertId);

await updateMigratedAlertToUseApiKeyOfCurrentUser(migratedAlertId);
Expand All @@ -140,6 +143,21 @@ export default function alertTests({ getService }: FtrProviderContext) {
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}

async function resetTaskStatus(alertId: string) {
// occasionally when the task manager starts running while the alert saved objects
// are mid-migration, the task will fail and set its status to "failed". this prevents
// the alert from running ever again and downstream tasks that depend on successful alert
// execution will fail. this ensures the task status is set to "idle" so the
// task manager will continue claiming and executing it.
await supertest
.put(`${getUrlPrefix(space.id)}/api/alerts_fixture/${alertId}/reset_task_status`)
.set('kbn-xsrf', 'foo')
.send({
status: 'idle',
})
.expect(200);
}

async function ensureLegacyAlertHasBeenMigrated(alertId: string) {
const getResponse = await supertestWithoutAuth
.get(`${getUrlPrefix(space.id)}/api/alerts/alert/${alertId}`)
Expand Down