mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Co-authored-by: Shahzad <shahzad.muhammad@elastic.co>
This commit is contained in:
parent
5ee887bf5d
commit
8324c851e9
6 changed files with 116 additions and 0 deletions
|
@ -38,5 +38,6 @@ export enum API_URLS {
|
|||
|
||||
// Service end points
|
||||
INDEX_TEMPLATES = '/internal/uptime/service/index_templates',
|
||||
SERVICE_LOCATIONS = '/internal/uptime/service/locations',
|
||||
SYNTHETICS_MONITORS = '/internal/uptime/service/monitors',
|
||||
}
|
||||
|
|
|
@ -44,3 +44,19 @@ export type SyntheticsMonitorSavedObject = SimpleSavedObject<{
|
|||
};
|
||||
};
|
||||
}>;
|
||||
|
||||
interface LocationGeo {
|
||||
lat: number;
|
||||
lon: number;
|
||||
}
|
||||
|
||||
export interface ManifestLocation {
|
||||
url: string;
|
||||
geo: {
|
||||
name: string;
|
||||
location: LocationGeo;
|
||||
};
|
||||
status: string;
|
||||
}
|
||||
|
||||
export type ServiceLocations = Array<{ id: string; label: string; geo: LocationGeo }>;
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
import axios from 'axios';
|
||||
import { getServiceLocations } from './get_service_locations';
|
||||
jest.mock('axios');
|
||||
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
||||
|
||||
describe('getServiceLocations', function () {
|
||||
mockedAxios.get.mockRejectedValue('Network error: Something went wrong');
|
||||
mockedAxios.get.mockResolvedValue({
|
||||
data: {
|
||||
locations: {
|
||||
us_central: {
|
||||
url: 'https://local.dev',
|
||||
geo: {
|
||||
name: 'US Central',
|
||||
location: { lat: 41.25, lon: -95.86 },
|
||||
},
|
||||
status: 'beta',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
it('should return parsed locations', async () => {
|
||||
const locations = await getServiceLocations({
|
||||
config: {
|
||||
unsafe: {
|
||||
service: {
|
||||
manifestUrl: 'http://local.dev',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(locations).toEqual([
|
||||
{
|
||||
geo: {
|
||||
lat: 41.25,
|
||||
lon: -95.86,
|
||||
},
|
||||
id: 'us_central',
|
||||
label: 'US Central',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import axios from 'axios';
|
||||
import { UptimeConfig } from '../../../common/config';
|
||||
import { ManifestLocation, ServiceLocations } from '../../../common/types';
|
||||
|
||||
export async function getServiceLocations({ config }: { config: UptimeConfig }) {
|
||||
const manifestURL = config.unsafe.service.manifestUrl;
|
||||
const locations: ServiceLocations = [];
|
||||
try {
|
||||
const { data } = await axios.get<Record<string, ManifestLocation>>(manifestURL);
|
||||
|
||||
Object.entries(data.locations).forEach(([locationId, location]) => {
|
||||
locations.push({
|
||||
id: locationId,
|
||||
label: location.geo.name,
|
||||
geo: location.geo.location,
|
||||
});
|
||||
});
|
||||
|
||||
return locations;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ import { createNetworkEventsRoute } from './network_events';
|
|||
import { createJourneyFailedStepsRoute } from './pings/journeys';
|
||||
import { createLastSuccessfulStepRoute } from './synthetics/last_successful_step';
|
||||
import { installIndexTemplatesRoute } from './synthetics_service/install_index_templates';
|
||||
import { getServiceLocationsRoute } from './synthetics_service/get_service_locations';
|
||||
import {
|
||||
getAllSyntheticsMonitorRoute,
|
||||
getSyntheticsMonitorRoute,
|
||||
|
@ -60,6 +61,7 @@ export const restApiRoutes: UMRestApiRouteFactory[] = [
|
|||
createLastSuccessfulStepRoute,
|
||||
createJourneyScreenshotBlocksRoute,
|
||||
installIndexTemplatesRoute,
|
||||
getServiceLocationsRoute,
|
||||
getSyntheticsMonitorRoute,
|
||||
getAllSyntheticsMonitorRoute,
|
||||
addSyntheticsMonitorRoute,
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { UMRestApiRouteFactory } from '../types';
|
||||
import { API_URLS } from '../../../common/constants';
|
||||
import { getServiceLocations } from '../../lib/synthetics_service/get_service_locations';
|
||||
|
||||
export const getServiceLocationsRoute: UMRestApiRouteFactory = () => ({
|
||||
method: 'GET',
|
||||
path: API_URLS.SERVICE_LOCATIONS,
|
||||
validate: {},
|
||||
handler: async ({ server }): Promise<any> => getServiceLocations({ config: server.config }),
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue