-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Uptime] Route to get service locations and a handler #119964
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
]); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we go ahead and display an fatal error message when this happens? Can't use the service without a location right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if it's empty, it makes sense to just disable the UI, and display an error. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the status for, for my information?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think if the location is in GA or beta etc.