mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [[Synthetics] Format locations for public API's (#195295)](https://github.com/elastic/kibana/pull/195295) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2024-10-08T15:52:33Z","message":"[Synthetics] Format locations for public API's (#195295)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/194901 !!\r\n\r\nFormat locations for public API's !!\r\n\r\nPublic API has been refactored to return list of location ids just like\r\nthey are provided in request !!","sha":"d21495bbce07ed39fdcf077c9170d012adab74a4","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-management"],"title":"[Synthetics] Format locations for public API's","number":195295,"url":"https://github.com/elastic/kibana/pull/195295","mergeCommit":{"message":"[Synthetics] Format locations for public API's (#195295)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/194901 !!\r\n\r\nFormat locations for public API's !!\r\n\r\nPublic API has been refactored to return list of location ids just like\r\nthey are provided in request !!","sha":"d21495bbce07ed39fdcf077c9170d012adab74a4"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195295","number":195295,"mergeCommit":{"message":"[Synthetics] Format locations for public API's (#195295)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/194901 !!\r\n\r\nFormat locations for public API's !!\r\n\r\nPublic API has been refactored to return list of location ids just like\r\nthey are provided in request !!","sha":"d21495bbce07ed39fdcf077c9170d012adab74a4"}}]}] BACKPORT--> Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
parent
0b6359b726
commit
f215bde49e
8 changed files with 76 additions and 17 deletions
|
@ -20,6 +20,7 @@ export const FetchMonitorManagementListQueryArgsCodec = t.partial({
|
|||
projects: t.array(t.string),
|
||||
schedules: t.array(t.string),
|
||||
monitorQueryIds: t.array(t.string),
|
||||
internal: t.boolean,
|
||||
});
|
||||
|
||||
export type FetchMonitorManagementListQueryArgs = t.TypeOf<
|
||||
|
|
|
@ -35,6 +35,7 @@ function toMonitorManagementListQueryArgs(
|
|||
schedules: pageState.schedules,
|
||||
monitorQueryIds: pageState.monitorQueryIds,
|
||||
searchFields: [],
|
||||
internal: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,11 @@ export const QuerySchema = schema.object({
|
|||
status: StringOrArraySchema,
|
||||
searchAfter: schema.maybe(schema.arrayOf(schema.string())),
|
||||
monitorQueryIds: StringOrArraySchema,
|
||||
internal: schema.maybe(
|
||||
schema.boolean({
|
||||
defaultValue: false,
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
export type MonitorsQuery = TypeOf<typeof QuerySchema>;
|
||||
|
|
|
@ -84,17 +84,8 @@ describe('mergeSourceMonitor', () => {
|
|||
id: 'todos-lightweight-test-projects-default',
|
||||
ipv4: true,
|
||||
ipv6: true,
|
||||
locations: [
|
||||
{
|
||||
geo: {
|
||||
lat: 41.25,
|
||||
lon: -95.86,
|
||||
},
|
||||
id: 'us_central',
|
||||
isServiceManaged: true,
|
||||
label: 'North America - US Central',
|
||||
},
|
||||
],
|
||||
locations: ['us_central', 'us_east'],
|
||||
private_locations: ['pvt_us_east'],
|
||||
max_redirects: 0,
|
||||
mode: 'any',
|
||||
name: 'Todos Lightweight',
|
||||
|
@ -166,13 +157,31 @@ describe('mergeSourceMonitor', () => {
|
|||
locations: [
|
||||
{
|
||||
geo: {
|
||||
lat: 41.25,
|
||||
lon: -95.86,
|
||||
lat: 41.25,
|
||||
},
|
||||
id: 'us_central',
|
||||
isServiceManaged: true,
|
||||
id: 'us_central',
|
||||
label: 'North America - US Central',
|
||||
},
|
||||
{
|
||||
geo: {
|
||||
lon: -95.86,
|
||||
lat: 41.25,
|
||||
},
|
||||
isServiceManaged: true,
|
||||
id: 'us-east4-a',
|
||||
label: 'US East',
|
||||
},
|
||||
{
|
||||
geo: {
|
||||
lon: -95.86,
|
||||
lat: 41.25,
|
||||
},
|
||||
isServiceManaged: false,
|
||||
id: 'pvt_us_east',
|
||||
label: 'US East (Private)',
|
||||
},
|
||||
],
|
||||
max_redirects: '0',
|
||||
mode: 'any',
|
||||
|
@ -240,6 +249,24 @@ const testMonitor = {
|
|||
id: 'us_central',
|
||||
label: 'North America - US Central',
|
||||
},
|
||||
{
|
||||
geo: {
|
||||
lon: -95.86,
|
||||
lat: 41.25,
|
||||
},
|
||||
isServiceManaged: true,
|
||||
id: 'us-east4-a',
|
||||
label: 'US East',
|
||||
},
|
||||
{
|
||||
geo: {
|
||||
lon: -95.86,
|
||||
lat: 41.25,
|
||||
},
|
||||
isServiceManaged: false,
|
||||
id: 'pvt_us_east',
|
||||
label: 'US East (Private)',
|
||||
},
|
||||
],
|
||||
namespace: 'default',
|
||||
origin: 'project',
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import { SavedObject } from '@kbn/core/server';
|
||||
import { mergeWith, omit, omitBy } from 'lodash';
|
||||
import { LocationsMap } from '../../../synthetics_service/project_monitor/normalizers/common_fields';
|
||||
import {
|
||||
ConfigKey,
|
||||
EncryptedSyntheticsMonitor,
|
||||
|
@ -38,11 +39,14 @@ type Result = MonitorFieldsResult & {
|
|||
ssl: Record<string, any>;
|
||||
response: Record<string, any>;
|
||||
check: Record<string, any>;
|
||||
locations: string[];
|
||||
private_locations: string[];
|
||||
};
|
||||
|
||||
export const transformPublicKeys = (result: Result) => {
|
||||
let formattedResult = {
|
||||
...result,
|
||||
...formatLocations(result),
|
||||
[ConfigKey.PARAMS]: formatParams(result),
|
||||
retest_on_failure: (result[ConfigKey.MAX_ATTEMPTS] ?? 1) > 1,
|
||||
...(result[ConfigKey.HOSTS] && { host: result[ConfigKey.HOSTS] }),
|
||||
|
@ -66,8 +70,7 @@ export const transformPublicKeys = (result: Result) => {
|
|||
|
||||
return omitBy(
|
||||
res,
|
||||
(value, key) =>
|
||||
key.startsWith('response.') || key.startsWith('ssl.') || key.startsWith('check.')
|
||||
(_, key) => key.startsWith('response.') || key.startsWith('ssl.') || key.startsWith('check.')
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -105,6 +108,24 @@ const customizer = (destVal: any, srcValue: any, key: string) => {
|
|||
}
|
||||
};
|
||||
|
||||
const formatLocations = (config: MonitorFields) => {
|
||||
const locMap = Object.entries(LocationsMap);
|
||||
const locations = config[ConfigKey.LOCATIONS]
|
||||
?.filter((location) => location.isServiceManaged)
|
||||
.map((location) => {
|
||||
return locMap.find(([_key, value]) => value === location.id)?.[0] ?? location.id;
|
||||
});
|
||||
|
||||
const privateLocations = config[ConfigKey.LOCATIONS]
|
||||
?.filter((location) => !location.isServiceManaged)
|
||||
.map((location) => location.id);
|
||||
|
||||
return {
|
||||
...(locations && { locations }),
|
||||
...(privateLocations && { private_locations: privateLocations }),
|
||||
};
|
||||
};
|
||||
|
||||
const formatParams = (config: MonitorFields) => {
|
||||
if (config[ConfigKey.PARAMS]) {
|
||||
try {
|
||||
|
|
|
@ -45,6 +45,7 @@ export const getAllSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () =>
|
|||
monitors: savedObjects.map((monitor) =>
|
||||
mapSavedObjectToMonitor({
|
||||
monitor,
|
||||
internal: request.query?.internal,
|
||||
})
|
||||
),
|
||||
absoluteTotal,
|
||||
|
|
|
@ -143,7 +143,7 @@ export class SyntheticsRuleHelper {
|
|||
schedule: 1,
|
||||
};
|
||||
const res = await this.supertest
|
||||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '?internal=true')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(testData);
|
||||
|
||||
|
|
|
@ -1814,7 +1814,10 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
projectMonitors.monitors.map((monitor) => {
|
||||
return supertest
|
||||
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
|
||||
.query({ filter: `${syntheticsMonitorType}.attributes.journey_id: ${monitor.id}` })
|
||||
.query({
|
||||
filter: `${syntheticsMonitorType}.attributes.journey_id: ${monitor.id}`,
|
||||
internal: true,
|
||||
})
|
||||
.set('kbn-xsrf', 'true')
|
||||
.expect(200);
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue