mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
e0944d17ec
commit
ae8b6c8beb
4 changed files with 75 additions and 4 deletions
|
@ -53,6 +53,7 @@ describe('formatMonitorConfig', () => {
|
||||||
expect(yamlConfig).toEqual({
|
expect(yamlConfig).toEqual({
|
||||||
'check.request.method': 'GET',
|
'check.request.method': 'GET',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
locations: [],
|
||||||
max_redirects: '0',
|
max_redirects: '0',
|
||||||
name: 'Test',
|
name: 'Test',
|
||||||
password: '3z9SBOQWW5F0UrdqLVFqlF6z',
|
password: '3z9SBOQWW5F0UrdqLVFqlF6z',
|
||||||
|
@ -110,6 +111,7 @@ describe('formatMonitorConfig', () => {
|
||||||
'filter_journeys.tags': ['dev'],
|
'filter_journeys.tags': ['dev'],
|
||||||
ignore_https_errors: false,
|
ignore_https_errors: false,
|
||||||
name: 'Test',
|
name: 'Test',
|
||||||
|
locations: [],
|
||||||
schedule: '@every 3m',
|
schedule: '@every 3m',
|
||||||
screenshots: 'on',
|
screenshots: 'on',
|
||||||
'source.inline.script':
|
'source.inline.script':
|
||||||
|
|
|
@ -15,7 +15,6 @@ const UI_KEYS_TO_SKIP = [
|
||||||
ConfigKey.DOWNLOAD_SPEED,
|
ConfigKey.DOWNLOAD_SPEED,
|
||||||
ConfigKey.LATENCY,
|
ConfigKey.LATENCY,
|
||||||
ConfigKey.IS_THROTTLING_ENABLED,
|
ConfigKey.IS_THROTTLING_ENABLED,
|
||||||
ConfigKey.LOCATIONS,
|
|
||||||
ConfigKey.REVISION,
|
ConfigKey.REVISION,
|
||||||
'secrets',
|
'secrets',
|
||||||
];
|
];
|
||||||
|
|
|
@ -5,10 +5,13 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { SyntheticsService } from './synthetics_service';
|
jest.mock('axios', () => jest.fn());
|
||||||
|
|
||||||
|
import { SyntheticsService, SyntheticsConfig } from './synthetics_service';
|
||||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||||
import { loggerMock } from '@kbn/core/server/logging/logger.mock';
|
import { loggerMock } from '@kbn/core/server/logging/logger.mock';
|
||||||
import { UptimeServerSetup } from '../legacy_uptime/lib/adapters';
|
import { UptimeServerSetup } from '../legacy_uptime/lib/adapters';
|
||||||
|
import axios, { AxiosResponse } from 'axios';
|
||||||
|
|
||||||
describe('SyntheticsService', () => {
|
describe('SyntheticsService', () => {
|
||||||
const mockEsClient = {
|
const mockEsClient = {
|
||||||
|
@ -67,4 +70,71 @@ describe('SyntheticsService', () => {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('addConfig', () => {
|
||||||
|
afterEach(() => jest.restoreAllMocks());
|
||||||
|
|
||||||
|
it('saves configs only to the selected locations', async () => {
|
||||||
|
serverMock.config = { service: { devUrl: 'http://localhost' } };
|
||||||
|
const service = new SyntheticsService(logger, serverMock, {
|
||||||
|
username: 'dev',
|
||||||
|
password: '12345',
|
||||||
|
});
|
||||||
|
|
||||||
|
service.apiClient.locations = [
|
||||||
|
{
|
||||||
|
id: 'selected',
|
||||||
|
label: 'Selected Location',
|
||||||
|
url: 'example.com/1',
|
||||||
|
geo: {
|
||||||
|
lat: 0,
|
||||||
|
lon: 0,
|
||||||
|
},
|
||||||
|
isServiceManaged: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'not selected',
|
||||||
|
label: 'Not Selected Location',
|
||||||
|
url: 'example.com/2',
|
||||||
|
geo: {
|
||||||
|
lat: 0,
|
||||||
|
lon: 0,
|
||||||
|
},
|
||||||
|
isServiceManaged: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
jest.spyOn(service, 'getApiKey').mockResolvedValue({ name: 'example', id: 'i', apiKey: 'k' });
|
||||||
|
jest.spyOn(service, 'getOutput').mockResolvedValue({ hosts: ['es'], api_key: 'i:k' });
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
type: 'http',
|
||||||
|
enabled: true,
|
||||||
|
schedule: {
|
||||||
|
number: '3',
|
||||||
|
unit: 'm',
|
||||||
|
},
|
||||||
|
name: 'my mon',
|
||||||
|
locations: [{ id: 'selected', isServiceManaged: true }],
|
||||||
|
urls: 'http://google.com',
|
||||||
|
max_redirects: '0',
|
||||||
|
password: '',
|
||||||
|
proxy_url: '',
|
||||||
|
id: '7af7e2f0-d5dc-11ec-87ac-bdfdb894c53d',
|
||||||
|
fields: { config_id: '7af7e2f0-d5dc-11ec-87ac-bdfdb894c53d' },
|
||||||
|
fields_under_root: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
(axios as jest.MockedFunction<typeof axios>).mockResolvedValue({} as AxiosResponse);
|
||||||
|
|
||||||
|
await service.addConfig(payload as SyntheticsConfig);
|
||||||
|
|
||||||
|
expect(axios).toHaveBeenCalledTimes(1);
|
||||||
|
expect(axios).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
url: 'example.com/1/monitors',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -48,7 +48,7 @@ const SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_TYPE =
|
||||||
const SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID = 'UPTIME:SyntheticsService:sync-task';
|
const SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_ID = 'UPTIME:SyntheticsService:sync-task';
|
||||||
const SYNTHETICS_SERVICE_SYNC_INTERVAL_DEFAULT = '5m';
|
const SYNTHETICS_SERVICE_SYNC_INTERVAL_DEFAULT = '5m';
|
||||||
|
|
||||||
type SyntheticsConfig = SyntheticsMonitorWithId & {
|
export type SyntheticsConfig = SyntheticsMonitorWithId & {
|
||||||
fields_under_root?: boolean;
|
fields_under_root?: boolean;
|
||||||
fields?: { config_id: string; run_once?: boolean; test_run_id?: string };
|
fields?: { config_id: string; run_once?: boolean; test_run_id?: string };
|
||||||
};
|
};
|
||||||
|
@ -56,7 +56,7 @@ type SyntheticsConfig = SyntheticsMonitorWithId & {
|
||||||
export class SyntheticsService {
|
export class SyntheticsService {
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
private readonly server: UptimeServerSetup;
|
private readonly server: UptimeServerSetup;
|
||||||
private apiClient: ServiceAPIClient;
|
public apiClient: ServiceAPIClient;
|
||||||
|
|
||||||
private readonly config: ServiceConfig;
|
private readonly config: ServiceConfig;
|
||||||
private readonly esHosts: string[];
|
private readonly esHosts: string[];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue