mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `8.9`: - [[Synthetics] Handle a case where settings were never saved (#161834)](https://github.com/elastic/kibana/pull/161834) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2023-07-18T16:09:11Z","message":"[Synthetics] Handle a case where settings were never saved (#161834)\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"41a8a1db011c63107921c8446d33d94991cfb67b","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v8.9.0","v8.10.0"],"number":161834,"url":"https://github.com/elastic/kibana/pull/161834","mergeCommit":{"message":"[Synthetics] Handle a case where settings were never saved (#161834)\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"41a8a1db011c63107921c8446d33d94991cfb67b"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161834","number":161834,"mergeCommit":{"message":"[Synthetics] Handle a case where settings were never saved (#161834)\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"41a8a1db011c63107921c8446d33d94991cfb67b"}}]}] BACKPORT--> --------- Co-authored-by: Shahzad <shahzad31comp@gmail.com> Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
b9e0e5a673
commit
83d9c3dd10
2 changed files with 63 additions and 7 deletions
|
@ -8,7 +8,8 @@
|
|||
import { UptimeEsClient } from './lib';
|
||||
import { savedObjectsClientMock, uiSettingsServiceMock } from '@kbn/core/server/mocks';
|
||||
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
|
||||
import { savedObjectsAdapter } from './saved_objects';
|
||||
import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server';
|
||||
import { settingsObjectId, umDynamicSettings } from './saved_objects/uptime_settings';
|
||||
|
||||
describe('UptimeEsClient', () => {
|
||||
let uptimeEsClient: UptimeEsClient;
|
||||
|
@ -140,9 +141,44 @@ describe('UptimeEsClient', () => {
|
|||
});
|
||||
describe('heartbeatIndices', () => {
|
||||
it('appends synthetics-* in index for legacy alerts', async () => {
|
||||
savedObjectsAdapter.getUptimeDynamicSettings = jest.fn().mockResolvedValue({
|
||||
heartbeatIndices: 'heartbeat-8*,heartbeat-7*',
|
||||
syntheticsIndexRemoved: true,
|
||||
savedObjectsClient.get = jest.fn().mockResolvedValue({
|
||||
attributes: {
|
||||
heartbeatIndices: 'heartbeat-8*,heartbeat-7*',
|
||||
syntheticsIndexRemoved: true,
|
||||
},
|
||||
});
|
||||
uptimeEsClient = new UptimeEsClient(savedObjectsClient, esClient, { isLegacyAlert: true });
|
||||
|
||||
const mockSearchParams = {
|
||||
body: {
|
||||
query: {
|
||||
match_all: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await uptimeEsClient.search({
|
||||
body: {
|
||||
query: {
|
||||
match_all: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(esClient.search).toHaveBeenCalledWith(
|
||||
{
|
||||
index: 'heartbeat-8*,heartbeat-7*,synthetics-*',
|
||||
...mockSearchParams,
|
||||
},
|
||||
{ meta: true }
|
||||
);
|
||||
});
|
||||
it('appends synthetics-* in index for legacy alerts when settings are never saved', async () => {
|
||||
savedObjectsClient.get = jest.fn().mockImplementation(() => {
|
||||
throw SavedObjectsErrorHelpers.createGenericNotFoundError(
|
||||
umDynamicSettings.name,
|
||||
settingsObjectId
|
||||
);
|
||||
});
|
||||
uptimeEsClient = new UptimeEsClient(savedObjectsClient, esClient, { isLegacyAlert: true });
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
SavedObjectsClientContract,
|
||||
KibanaRequest,
|
||||
CoreRequestHandlerContext,
|
||||
SavedObjectsErrorHelpers,
|
||||
} from '@kbn/core/server';
|
||||
import chalk from 'chalk';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
|
@ -18,9 +19,11 @@ import { RequestStatus } from '@kbn/inspector-plugin/common';
|
|||
import { InspectResponse } from '@kbn/observability-plugin/typings/common';
|
||||
import { enableInspectEsQueries } from '@kbn/observability-plugin/common';
|
||||
import { getInspectResponse } from '@kbn/observability-shared-plugin/common';
|
||||
import { DYNAMIC_SETTINGS_DEFAULT_ATTRIBUTES } from '../../constants/settings';
|
||||
import { DynamicSettingsAttributes } from '../../runtime_types/settings';
|
||||
import { settingsObjectId, umDynamicSettings } from './saved_objects/uptime_settings';
|
||||
import { API_URLS } from '../../../common/constants';
|
||||
import { UptimeServerSetup } from './adapters';
|
||||
import { savedObjectsAdapter } from './saved_objects/saved_objects';
|
||||
|
||||
export type { UMServerLibs } from '../uptime_server';
|
||||
|
||||
|
@ -202,14 +205,31 @@ export class UptimeEsClient {
|
|||
// if isLegacyAlert appends synthetics-* if it's not already there
|
||||
let indices = '';
|
||||
let syntheticsIndexRemoved = false;
|
||||
let settingsChangedByUser = true;
|
||||
let settings: DynamicSettingsAttributes = DYNAMIC_SETTINGS_DEFAULT_ATTRIBUTES;
|
||||
if (this.heartbeatIndices) {
|
||||
indices = this.heartbeatIndices;
|
||||
} else {
|
||||
const settings = await savedObjectsAdapter.getUptimeDynamicSettings(this.savedObjectsClient);
|
||||
try {
|
||||
const obj = await this.savedObjectsClient.get<DynamicSettingsAttributes>(
|
||||
umDynamicSettings.name,
|
||||
settingsObjectId
|
||||
);
|
||||
settings = obj.attributes;
|
||||
} catch (getErr) {
|
||||
if (SavedObjectsErrorHelpers.isNotFoundError(getErr)) {
|
||||
settingsChangedByUser = false;
|
||||
}
|
||||
}
|
||||
|
||||
indices = settings?.heartbeatIndices || '';
|
||||
syntheticsIndexRemoved = settings.syntheticsIndexRemoved ?? false;
|
||||
}
|
||||
if (this.isLegacyAlert && !indices.includes('synthetics-') && syntheticsIndexRemoved) {
|
||||
if (
|
||||
this.isLegacyAlert &&
|
||||
!indices.includes('synthetics-') &&
|
||||
(syntheticsIndexRemoved || !settingsChangedByUser)
|
||||
) {
|
||||
indices = indices + ',synthetics-*';
|
||||
}
|
||||
return indices;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue