[Uptime] Remove synthetics-* pattern from uptime settings (#159012)

Co-authored-by: Dominique Clarke <dominique.clarke@elastic.co>
This commit is contained in:
Shahzad 2023-06-08 10:24:46 +02:00 committed by GitHub
parent 8ff30aa604
commit e967bb5a9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 130 additions and 29 deletions

View file

@ -150,7 +150,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"ui-metric": "d227284528fd19904e9d972aea0a13716fc5fe24",
"upgrade-assistant-ml-upgrade-operation": "421f52731cb24e242d70672ba4725e169277efb3",
"upgrade-assistant-reindex-operation": "01f3c3e051659ace56492a73928987e717537a93",
"uptime-dynamic-settings": "a9e9c42d8c1b6643946f32558478b274de0f89e0",
"uptime-dynamic-settings": "b6756ff71d6b5258971b1c8fd433d167affbde52",
"uptime-synthetics-api-key": "7ae976a461248f9dbd8442af14a179bdbc229eca",
"url": "c923a4a5002a09c0080c9095e958f07d518e6704",
"usage-counters": "48782b3bcb6b5a23ba6f2bfe3a380d835e68890a",

View file

@ -8,7 +8,7 @@
import { DynamicSettings, DynamicSettingsAttributes } from '../runtime_types';
export const DYNAMIC_SETTINGS_DEFAULTS: DynamicSettings = {
heartbeatIndices: 'heartbeat-8*,heartbeat-7*,synthetics-*',
heartbeatIndices: 'heartbeat-8*,heartbeat-7*',
certAgeThreshold: 730,
certExpirationThreshold: 30,
defaultConnectors: [],
@ -20,6 +20,6 @@ export const DYNAMIC_SETTINGS_DEFAULTS: DynamicSettings = {
};
// `DYNAMIC_SETTINGS_DEFAULT_ATTRIBUTES` helps isolate the Saved Object attributes from `DynamicSettings`
// which represents API response type. It may initially be a duplcate of `DYNAMIC_SETTINGS_DEFAULTS`
// which represents API response type. It may initially be a duplicate of `DYNAMIC_SETTINGS_DEFAULTS`
export const DYNAMIC_SETTINGS_DEFAULT_ATTRIBUTES: DynamicSettingsAttributes =
DYNAMIC_SETTINGS_DEFAULTS;

View file

@ -44,7 +44,7 @@ export class SyntheticsServices {
async enableMonitorManagedViaApi() {
try {
await axios.post(this.kibanaUrl + '/internal/uptime/service/enablement', undefined, {
await axios.put(this.kibanaUrl + '/internal/uptime/service/enablement', undefined, {
auth: { username: 'elastic', password: 'changeme' },
headers: { 'kbn-xsrf': 'true' },
});

View file

@ -10,6 +10,7 @@ import { isValidCertVal, SettingsPage } from './settings';
import { render } from '../lib/helper/rtl_helpers';
import { fireEvent, waitFor } from '@testing-library/dom';
import * as alertApi from '../state/api/alerts';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../common/constants';
describe('settings', () => {
describe('form', () => {
@ -30,7 +31,7 @@ describe('settings', () => {
it('handles no spaces error', async () => {
const { getByText, getByTestId } = render(<SettingsPage />);
expect(getByText('heartbeat-8*,heartbeat-7*,synthetics-*'));
expect(getByText(DYNAMIC_SETTINGS_DEFAULTS.heartbeatIndices));
fireEvent.input(getByTestId('heartbeat-indices-input-loaded'), {
target: { value: 'heartbeat-8*, synthetics-*' },
@ -42,7 +43,7 @@ describe('settings', () => {
it('it show select a connector flyout', async () => {
const { getByText, getByTestId } = render(<SettingsPage />);
expect(getByText('heartbeat-8*,heartbeat-7*,synthetics-*'));
expect(getByText(DYNAMIC_SETTINGS_DEFAULTS.heartbeatIndices));
fireEvent.click(getByTestId('createConnectorButton'));
await waitFor(() => expect(getByText('Select a connector')));

View file

@ -55,7 +55,7 @@ Array [
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,
@ -106,7 +106,7 @@ Array [
},
],
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,

View file

@ -55,7 +55,7 @@ Array [
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,

View file

@ -232,7 +232,7 @@ describe('getCerts', () => {
},
],
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,

View file

@ -246,7 +246,7 @@ describe('monitor availability', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
});
@ -397,7 +397,7 @@ describe('monitor availability', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
@ -723,7 +723,7 @@ describe('monitor availability', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
@ -826,7 +826,7 @@ describe('monitor availability', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,
@ -964,7 +964,7 @@ describe('monitor availability', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
});

View file

@ -209,7 +209,7 @@ describe('getMonitorStatus', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
});
@ -335,7 +335,7 @@ describe('getMonitorStatus', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
});
@ -546,7 +546,7 @@ describe('getMonitorStatus', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
});
@ -677,7 +677,7 @@ describe('getMonitorStatus', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
});
@ -814,7 +814,7 @@ describe('getMonitorStatus', () => {
},
"size": 0,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
}
`);
expect(result.length).toBe(3);

View file

@ -213,7 +213,7 @@ describe('getNetworkEvents', () => {
"size": 1000,
"track_total_hits": true,
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,

View file

@ -173,7 +173,7 @@ describe('getAll', () => {
},
],
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,
@ -245,7 +245,7 @@ describe('getAll', () => {
},
],
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,
@ -317,7 +317,7 @@ describe('getAll', () => {
},
],
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,
@ -394,7 +394,7 @@ describe('getAll', () => {
},
],
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,
@ -516,7 +516,7 @@ describe('getAll', () => {
},
],
},
"index": "heartbeat-8*,heartbeat-7*,synthetics-*",
"index": "heartbeat-8*,heartbeat-7*",
},
Object {
"meta": true,

View file

@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { add820Indices } from './migrations';
import { add820Indices, remove890Indices } from './migrations';
import { SavedObject, SavedObjectMigrationContext } from '@kbn/core/server';
import { DynamicSettingsAttributes } from '../../../../common/runtime_types';
@ -91,3 +91,75 @@ describe('add820Indices migration', () => {
});
});
});
describe('remove890Indices migration', () => {
const context = { log: { warning: () => {} } } as unknown as SavedObjectMigrationContext;
const makeSettings = (heartbeatIndices: string): SavedObject<DynamicSettingsAttributes> => {
return {
id: '1',
type: 't',
references: [],
attributes: {
heartbeatIndices,
certAgeThreshold: 1,
certExpirationThreshold: 2,
defaultConnectors: ['example'],
},
};
};
it("removes the synthetics-* index if it's in the indices settings", () => {
const doc = makeSettings('heartbeat-8*,synthetics-*,something_else');
const result = remove890Indices(doc, context);
expect(result).toEqual({
...doc,
attributes: {
...doc.attributes,
heartbeatIndices: 'heartbeat-8*,something_else',
},
});
});
it("adds the heartbeat-8* index if it's not in the indices settings", () => {
const doc = makeSettings('synthetics-*,something_else');
const result = remove890Indices(doc, context);
expect(result).toEqual({
...doc,
attributes: {
...doc.attributes,
heartbeatIndices: 'something_else,heartbeat-8*',
},
});
});
it('works for empty heartbeat indices fields', () => {
const doc = makeSettings('');
const result = remove890Indices(doc, context);
expect(result).toEqual({
...doc,
attributes: {
...doc.attributes,
heartbeatIndices: 'heartbeat-8*',
},
});
});
it('works for undefined heartbeat indices fields', () => {
const doc = makeSettings('');
// We must TS ignore this so that we can delete this
// non-optional field and test that the migration still works
// when the field does not exist in the document
// @ts-expect-error
delete doc.attributes.heartbeatIndices;
const result = remove890Indices(doc, context);
expect(result).toEqual({
...doc,
attributes: {
...doc.attributes,
heartbeatIndices: 'heartbeat-8*',
},
});
});
});

View file

@ -34,3 +34,30 @@ export const add820Indices: SavedObjectMigrationFn<
return migratedObj;
};
export const remove890Indices: SavedObjectMigrationFn<
DynamicSettingsAttributes,
DynamicSettingsAttributes
> = (doc) => {
const heartbeatIndices = doc.attributes?.heartbeatIndices;
const indicesArr = !heartbeatIndices ? [] : heartbeatIndices.split(',');
// remove synthetics-* from the array
const indexToRemove = indicesArr.indexOf('synthetics-*');
if (indexToRemove > -1) {
indicesArr.splice(indexToRemove, 1);
}
if (!indicesArr.includes('heartbeat-8*')) {
indicesArr.push('heartbeat-8*');
}
return {
...doc,
attributes: {
...doc.attributes,
heartbeatIndices: indicesArr.join(','),
},
};
};

View file

@ -7,7 +7,7 @@
import { SavedObjectsType } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import { add820Indices } from './migrations';
import { add820Indices, remove890Indices } from './migrations';
export const settingsObjectType = 'uptime-dynamic-settings';
export const settingsObjectId = 'uptime-dynamic-settings-singleton';
@ -48,5 +48,6 @@ export const umDynamicSettings: SavedObjectsType = {
migrations: {
// Takes a pre 8.2.0 doc, and converts it to 8.2.0
'8.2.0': add820Indices,
'8.9.0': remove890Indices,
},
};

View file

@ -18,7 +18,7 @@ export default function ({ getService }: FtrProviderContext) {
const data = apiResponse.body;
expect(data).to.eql({
indexExists: true,
indices: 'heartbeat-8*,heartbeat-7*,synthetics-*',
indices: 'heartbeat-8*,heartbeat-7*',
});
});
});