mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
removed ESO migration from alerting (#73420)
This PR removes the use of ESO migration from alerting as we do not actually need this until the RBAC work lands, which should be 7.10. This allows us to concentrate the challenges of introducing RBAC into one single release which hopefully will help us better mitigate potential regressions.
This commit is contained in:
parent
fb4ee91f0c
commit
5e8e01fd0f
5 changed files with 0 additions and 222 deletions
|
@ -6,7 +6,6 @@
|
|||
|
||||
import { SavedObjectsServiceSetup } from 'kibana/server';
|
||||
import mappings from './mappings.json';
|
||||
import { getMigrations } from './migrations';
|
||||
import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';
|
||||
|
||||
export function setupSavedObjects(
|
||||
|
@ -17,7 +16,6 @@ export function setupSavedObjects(
|
|||
name: 'alert',
|
||||
hidden: true,
|
||||
namespaceType: 'single',
|
||||
migrations: getMigrations(encryptedSavedObjects),
|
||||
mappings: mappings.alert,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import uuid from 'uuid';
|
||||
import { getMigrations } from './migrations';
|
||||
import { RawAlert } from '../types';
|
||||
import { SavedObjectUnsanitizedDoc } from 'kibana/server';
|
||||
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/mocks';
|
||||
import { migrationMocks } from 'src/core/server/mocks';
|
||||
|
||||
const { log } = migrationMocks.createContext();
|
||||
const encryptedSavedObjectsSetup = encryptedSavedObjectsMock.createSetup();
|
||||
|
||||
describe('7.9.0', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
encryptedSavedObjectsSetup.createMigration.mockImplementation(
|
||||
(shouldMigrateWhenPredicate, migration) => migration
|
||||
);
|
||||
});
|
||||
|
||||
test('changes nothing on alerts by other plugins', () => {
|
||||
const migration790 = getMigrations(encryptedSavedObjectsSetup)['7.9.0'];
|
||||
const alert = getMockData({});
|
||||
expect(migration790(alert, { log })).toMatchObject(alert);
|
||||
|
||||
expect(encryptedSavedObjectsSetup.createMigration).toHaveBeenCalledWith(
|
||||
expect.any(Function),
|
||||
expect.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
test('migrates the consumer for alerting', () => {
|
||||
const migration790 = getMigrations(encryptedSavedObjectsSetup)['7.9.0'];
|
||||
const alert = getMockData({
|
||||
consumer: 'alerting',
|
||||
});
|
||||
expect(migration790(alert, { log })).toMatchObject({
|
||||
...alert,
|
||||
attributes: {
|
||||
...alert.attributes,
|
||||
consumer: 'alerts',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('7.10.0', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
encryptedSavedObjectsSetup.createMigration.mockImplementation(
|
||||
(shouldMigrateWhenPredicate, migration) => migration
|
||||
);
|
||||
});
|
||||
|
||||
test('changes nothing on alerts by other plugins', () => {
|
||||
const migration710 = getMigrations(encryptedSavedObjectsSetup)['7.10.0'];
|
||||
const alert = getMockData({});
|
||||
expect(migration710(alert, { log })).toMatchObject(alert);
|
||||
|
||||
expect(encryptedSavedObjectsSetup.createMigration).toHaveBeenCalledWith(
|
||||
expect.any(Function),
|
||||
expect.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
test('migrates the consumer for metrics', () => {
|
||||
const migration710 = getMigrations(encryptedSavedObjectsSetup)['7.10.0'];
|
||||
const alert = getMockData({
|
||||
consumer: 'metrics',
|
||||
});
|
||||
expect(migration710(alert, { log })).toMatchObject({
|
||||
...alert,
|
||||
attributes: {
|
||||
...alert.attributes,
|
||||
consumer: 'infrastructure',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getMockData(
|
||||
overwrites: Record<string, unknown> = {}
|
||||
): SavedObjectUnsanitizedDoc<RawAlert> {
|
||||
return {
|
||||
attributes: {
|
||||
enabled: true,
|
||||
name: 'abc',
|
||||
tags: ['foo'],
|
||||
alertTypeId: '123',
|
||||
consumer: 'bar',
|
||||
apiKey: '',
|
||||
apiKeyOwner: '',
|
||||
schedule: { interval: '10s' },
|
||||
throttle: null,
|
||||
params: {
|
||||
bar: true,
|
||||
},
|
||||
muteAll: false,
|
||||
mutedInstanceIds: [],
|
||||
createdBy: new Date().toISOString(),
|
||||
updatedBy: new Date().toISOString(),
|
||||
createdAt: new Date().toISOString(),
|
||||
actions: [
|
||||
{
|
||||
group: 'default',
|
||||
actionRef: '1',
|
||||
actionTypeId: '1',
|
||||
params: {
|
||||
foo: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
...overwrites,
|
||||
},
|
||||
id: uuid.v4(),
|
||||
type: 'alert',
|
||||
};
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import {
|
||||
SavedObjectMigrationMap,
|
||||
SavedObjectUnsanitizedDoc,
|
||||
SavedObjectMigrationFn,
|
||||
} from '../../../../../src/core/server';
|
||||
import { RawAlert } from '../types';
|
||||
import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';
|
||||
|
||||
export function getMigrations(
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup
|
||||
): SavedObjectMigrationMap {
|
||||
return {
|
||||
/**
|
||||
* In v7.9.0 we changed the Alerting plugin so it uses the `consumer` value of `alerts`
|
||||
* prior to that we were using `alerting` and we need to keep these in sync
|
||||
*/
|
||||
'7.9.0': changeAlertingConsumer(encryptedSavedObjects, 'alerting', 'alerts'),
|
||||
/**
|
||||
* In v7.10.0 we changed the Matrics plugin so it uses the `consumer` value of `infrastructure`
|
||||
* prior to that we were using `metrics` and we need to keep these in sync
|
||||
*/
|
||||
'7.10.0': changeAlertingConsumer(encryptedSavedObjects, 'metrics', 'infrastructure'),
|
||||
};
|
||||
}
|
||||
|
||||
function changeAlertingConsumer(
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup,
|
||||
from: string,
|
||||
to: string
|
||||
): SavedObjectMigrationFn<RawAlert, RawAlert> {
|
||||
return encryptedSavedObjects.createMigration<RawAlert, RawAlert>(
|
||||
function shouldBeMigrated(doc): doc is SavedObjectUnsanitizedDoc<RawAlert> {
|
||||
return doc.attributes.consumer === from;
|
||||
},
|
||||
(doc: SavedObjectUnsanitizedDoc<RawAlert>): SavedObjectUnsanitizedDoc<RawAlert> => {
|
||||
const {
|
||||
attributes: { consumer },
|
||||
} = doc;
|
||||
return {
|
||||
...doc,
|
||||
attributes: {
|
||||
...doc.attributes,
|
||||
consumer: consumer === from ? to : consumer,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
|
@ -27,8 +27,5 @@ export default function alertingTests({ loadTestFile }: FtrProviderContext) {
|
|||
loadTestFile(require.resolve('./alerts_space1'));
|
||||
loadTestFile(require.resolve('./alerts_default_space'));
|
||||
loadTestFile(require.resolve('./builtin_alert_types'));
|
||||
|
||||
// note that this test will destroy existing spaces
|
||||
loadTestFile(require.resolve('./migrations'));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { getUrlPrefix } from '../../../common/lib';
|
||||
import { FtrProviderContext } from '../../../common/ftr_provider_context';
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default function createGetTests({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
||||
describe('migrations', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('alerts');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('alerts');
|
||||
});
|
||||
|
||||
it('7.9.0 migrates the `alerting` consumer to be the `alerts`', async () => {
|
||||
const response = await supertest.get(
|
||||
`${getUrlPrefix(``)}/api/alerts/alert/74f3e6d7-b7bb-477d-ac28-92ee22728e6e`
|
||||
);
|
||||
|
||||
expect(response.status).to.eql(200);
|
||||
expect(response.body.consumer).to.equal('alerts');
|
||||
});
|
||||
|
||||
it('7.10.0 migrates the `metrics` consumer to be the `infrastructure`', async () => {
|
||||
const response = await supertest.get(
|
||||
`${getUrlPrefix(``)}/api/alerts/alert/74f3e6d7-b7bb-477d-ac28-fdf248d5f2a4`
|
||||
);
|
||||
|
||||
expect(response.status).to.eql(200);
|
||||
expect(response.body.consumer).to.equal('infrastructure');
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue