[Synthetics] Fixes monitors search by location/hosts (#146529)

Fixes https://github.com/elastic/kibana/issues/146077
Fixes https://github.com/elastic/kibana/issues/146078
This commit is contained in:
Shahzad 2022-12-01 16:26:53 +01:00 committed by GitHub
parent 5e65ebb846
commit 6f7c6ad947
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 51 additions and 93 deletions

View file

@ -136,7 +136,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"siem-ui-timeline-pinned-event": "e2697b38751506c7fce6e8b7207a830483dc4283",
"space": "c4a0acce1bd4b9cce85154f2a350624a53111c59",
"spaces-usage-stats": "922d3235bbf519e3fb3b260e27248b1df8249b79",
"synthetics-monitor": "d784b64a3def47d3f3d1f367df71ae41ef33cb3c",
"synthetics-monitor": "7c1e5a78fb3b88cc03b441d3bf3714d9967ab214",
"synthetics-privates-locations": "dd00385f4a27ef062c3e57312eeb3799872fa4af",
"tag": "39413f4578cc2128c9a0fda97d0acd1c8862c47a",
"task": "ef53d0f070bd54957b8fe22fae3b1ff208913f76",

View file

@ -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 { PrivateLocation, ServiceLocation } from '../runtime_types';
export const formatLocation = (location: ServiceLocation | PrivateLocation) => {
return {
id: location.id,
label: location.label,
geo: location.geo,
isServiceManaged: location.isServiceManaged,
};
};

View file

@ -29,6 +29,7 @@ import {
EuiLink,
EuiTextArea,
} from '@elastic/eui';
import { formatLocation } from '../../../../../../common/utils/location_formatter';
import { getDocLinks } from '../../../../../kibana_services';
import { useMonitorName } from '../hooks/use_monitor_name';
import { MonitorTypeRadioGroup } from '../fields/monitor_type_radio_group';
@ -407,10 +408,7 @@ export const FIELD: Record<string, FieldMeta> = {
onChange: (updatedValues: ServiceLocations) => {
setValue(
ConfigKey.LOCATIONS,
updatedValues.map((location) => ({
id: location.id,
isServiceManaged: location.isServiceManaged,
})) as MonitorServiceLocations,
updatedValues.map((location) => formatLocation(location)) as MonitorServiceLocations,
{ shouldValidate: Boolean(formState.submitCount > 0) }
);
},

View file

@ -11,6 +11,7 @@ import { i18n } from '@kbn/i18n';
import { EuiCheckboxGroup, EuiFormRow, EuiText, EuiBadge, EuiIconTip } from '@elastic/eui';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { useRouteMatch } from 'react-router-dom';
import { formatLocation } from '../../../../../common/utils/location_formatter';
import { monitorManagementListSelector } from '../../../state/selectors';
import { MonitorServiceLocations, LocationStatus } from '../../../../../common/runtime_types';
import { ClientPluginsStart } from '../../../../plugin';
@ -44,9 +45,7 @@ export const ServiceLocations = ({
const location = locations.find((loc) => loc.id === optionId);
if (isSelected) {
setLocations((prevLocations) =>
location
? [...prevLocations, { id: location.id, isServiceManaged: location.isServiceManaged }]
: prevLocations
location ? [...prevLocations, formatLocation(location)] : prevLocations
);
} else {
setLocations((prevLocations) => [...prevLocations].filter((loc) => loc.id !== optionId));

View file

@ -104,6 +104,9 @@ export const getSyntheticsMonitorSavedObjectType = (
},
},
},
label: {
type: 'text',
},
},
},
custom_heartbeat_id: {

View file

@ -33,6 +33,7 @@ export const SEARCH_FIELDS = [
'name',
'tags.text',
'locations.id.text',
'locations.label',
'urls',
'hosts',
'project_id.text',
@ -74,7 +75,7 @@ export const getMonitors = (
page,
sortField: sortField === 'schedule.keyword' ? 'schedule.number' : sortField,
sortOrder,
searchFields: ['name', 'tags.text', 'locations.id.text', 'urls', 'project_id.text'],
searchFields: SEARCH_FIELDS,
search: query ? `${query}*` : undefined,
filter: filterStr,
fields,

View file

@ -53,27 +53,30 @@ export const getAllSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () =>
query: QuerySchema,
},
handler: async ({ request, savedObjectsClient, syntheticsMonitorClient }): Promise<any> => {
const queryResult = await getMonitors(
request.query,
syntheticsMonitorClient.syntheticsService,
savedObjectsClient
);
const countResult = isMonitorsQueryFiltered(request.query)
? await savedObjectsClient.find({
const totalCountQuery = async () => {
if (isMonitorsQueryFiltered(request.query)) {
return savedObjectsClient.find({
type: syntheticsMonitorType,
perPage: 0,
page: 1,
})
: queryResult;
});
}
};
const [queryResult, totalCount] = await Promise.all([
getMonitors(request.query, syntheticsMonitorClient.syntheticsService, savedObjectsClient),
totalCountQuery(),
]);
const absoluteTotal = totalCount?.total ?? queryResult.total;
const { saved_objects: monitors, per_page: perPageT, ...rest } = queryResult;
return {
...rest,
monitors,
absoluteTotal,
perPage: perPageT,
absoluteTotal: countResult.total,
syncErrors: syntheticsMonitorClient.syntheticsService.syncErrors,
};
},

View file

@ -136,8 +136,6 @@ describe('browser normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
url: 'test-url',
status: 'ga',
},
],
name: 'test-name-1',
@ -182,8 +180,6 @@ describe('browser normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
url: 'test-url',
status: 'ga',
},
{
geo: {
@ -193,8 +189,6 @@ describe('browser normalizers', () => {
id: 'us_east',
isServiceManaged: true,
label: 'Test Location',
url: 'test-url',
status: 'ga',
},
],
name: 'test-name-2',
@ -240,8 +234,6 @@ describe('browser normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
url: 'test-url',
status: 'ga',
},
{
geo: {
@ -251,15 +243,11 @@ describe('browser normalizers', () => {
id: 'us_east',
isServiceManaged: true,
label: 'Test Location',
url: 'test-url',
status: 'ga',
},
{
id: 'germany',
isServiceManaged: false,
label: 'Germany',
agentPolicyId: 'germany',
concurrentMonitors: 1,
},
],
name: 'test-name-3',

View file

@ -6,6 +6,7 @@
*/
import { omit } from 'lodash';
import { formatLocation } from '../../../../common/utils/location_formatter';
import { formatKibanaNamespace } from '../../../../common/formatters';
import {
BrowserFields,
@ -108,9 +109,9 @@ export const getMonitorLocations = ({
);
}) || [];
return [...publicLocs, ...privateLocs].filter(
(location) => location !== undefined
) as BrowserFields[ConfigKey.LOCATIONS];
return [...publicLocs, ...privateLocs]
.filter((location) => location !== undefined)
.map((loc) => formatLocation(loc!)) as BrowserFields[ConfigKey.LOCATIONS];
};
export const getUnsupportedKeysError = (

View file

@ -120,8 +120,6 @@ describe('icmp normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
status: 'ga',
url: 'test-url',
},
],
name: 'Cloudflare DNS',
@ -162,8 +160,6 @@ describe('icmp normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
status: 'ga',
url: 'test-url',
},
],
name: 'Cloudflare DNS 2',
@ -217,8 +213,6 @@ describe('icmp normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
status: 'ga',
url: 'test-url',
},
],
name: 'Cloudflare DNS 3',

View file

@ -128,8 +128,6 @@ describe('tcp normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
status: 'ga',
url: 'test-url',
},
],
name: 'GMail SMTP',
@ -184,8 +182,6 @@ describe('tcp normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
status: 'ga',
url: 'test-url',
},
],
name: 'Always Down',
@ -253,8 +249,6 @@ describe('tcp normalizers', () => {
id: 'us_central',
isServiceManaged: true,
label: 'Test Location',
status: 'ga',
url: 'test-url',
},
],
name: 'Always Down',

View file

@ -21,6 +21,7 @@ import { httpServerMock } from '@kbn/core-http-server-mocks';
import { formatSecrets } from '../utils';
import * as telemetryHooks from '../../routes/telemetry/monitor_upgrade_sender';
import { formatLocation } from '../../../common/utils/location_formatter';
const testMonitors = [
{
@ -453,7 +454,7 @@ const payloadData = [
form_monitor_type: 'multistep',
ignore_https_errors: false,
journey_id: 'check if title is present 10 0',
locations: privateLocations,
locations: privateLocations.map((l) => formatLocation(l)),
name: 'check if title is present 10 0',
namespace: 'default_space',
origin: 'project',
@ -515,7 +516,7 @@ const payloadData = [
form_monitor_type: 'multistep',
ignore_https_errors: false,
journey_id: 'check if title is present 10 1',
locations: privateLocations,
locations: privateLocations.map((l) => formatLocation(l)),
name: 'check if title is present 10 1',
namespace: 'default_space',
origin: 'project',

View file

@ -22,6 +22,7 @@ import { Subject } from 'rxjs';
import { formatSecrets } from '../utils';
import * as telemetryHooks from '../../routes/telemetry/monitor_upgrade_sender';
import { formatLocation } from '../../../common/utils/location_formatter';
const testMonitors = [
{
@ -525,7 +526,7 @@ const payloadData = [
form_monitor_type: 'multistep',
ignore_https_errors: false,
journey_id: 'check if title is present 10 0',
locations: privateLocations,
locations: privateLocations.map((l) => formatLocation(l)),
name: 'check if title is present 10 0',
namespace: 'default_space',
origin: 'project',
@ -587,7 +588,7 @@ const payloadData = [
form_monitor_type: 'multistep',
ignore_https_errors: false,
journey_id: 'check if title is present 10 1',
locations: privateLocations,
locations: privateLocations.map((l) => formatLocation(l)),
name: 'check if title is present 10 1',
namespace: 'default_space',
origin: 'project',

View file

@ -152,11 +152,8 @@ export default function ({ getService }: FtrProviderContext) {
lon: 0,
},
id: 'localhost',
isInvalid: false,
isServiceManaged: true,
label: 'Local Synthetics Service',
status: 'experimental',
url: 'mockDevUrl',
},
],
name: 'check if title is present',
@ -282,11 +279,8 @@ export default function ({ getService }: FtrProviderContext) {
lon: 0,
},
id: 'localhost',
isInvalid: false,
isServiceManaged: true,
label: 'Local Synthetics Service',
status: 'experimental',
url: 'mockDevUrl',
},
],
max_redirects: '0',
@ -390,11 +384,8 @@ export default function ({ getService }: FtrProviderContext) {
lon: 0,
},
id: 'localhost',
isInvalid: false,
isServiceManaged: true,
label: 'Local Synthetics Service',
status: 'experimental',
url: 'mockDevUrl',
},
],
name: monitor.name,
@ -489,21 +480,15 @@ export default function ({ getService }: FtrProviderContext) {
lon: 0,
},
id: 'localhost',
isInvalid: false,
isServiceManaged: true,
label: 'Local Synthetics Service',
status: 'experimental',
url: 'mockDevUrl',
},
{
agentPolicyId: testPolicyId,
concurrentMonitors: 1,
geo: {
lat: '',
lon: '',
},
id: testPolicyId,
isInvalid: false,
isServiceManaged: false,
label: 'Test private location 0',
},
@ -1317,22 +1302,16 @@ export default function ({ getService }: FtrProviderContext) {
id: 'localhost',
label: 'Local Synthetics Service',
geo: { lat: 0, lon: 0 },
url: 'mockDevUrl',
isServiceManaged: true,
status: 'experimental',
isInvalid: false,
},
{
label: 'Test private location 0',
isServiceManaged: false,
isInvalid: false,
agentPolicyId: testPolicyId,
id: testPolicyId,
geo: {
lat: '',
lon: '',
},
concurrentMonitors: 1,
},
]);
});

View file

@ -152,11 +152,8 @@ export default function ({ getService }: FtrProviderContext) {
lon: 0,
},
id: 'localhost',
isInvalid: false,
isServiceManaged: true,
label: 'Local Synthetics Service',
status: 'experimental',
url: 'mockDevUrl',
},
],
name: 'check if title is present',
@ -279,11 +276,8 @@ export default function ({ getService }: FtrProviderContext) {
lon: 0,
},
id: 'localhost',
isInvalid: false,
isServiceManaged: true,
label: 'Local Synthetics Service',
status: 'experimental',
url: 'mockDevUrl',
},
],
max_redirects: '0',
@ -384,11 +378,8 @@ export default function ({ getService }: FtrProviderContext) {
lon: 0,
},
id: 'localhost',
isInvalid: false,
isServiceManaged: true,
label: 'Local Synthetics Service',
status: 'experimental',
url: 'mockDevUrl',
},
],
name: monitor.name,
@ -481,21 +472,15 @@ export default function ({ getService }: FtrProviderContext) {
lon: 0,
},
id: 'localhost',
isInvalid: false,
isServiceManaged: true,
label: 'Local Synthetics Service',
status: 'experimental',
url: 'mockDevUrl',
},
{
agentPolicyId: testPolicyId,
concurrentMonitors: 1,
geo: {
lat: '',
lon: '',
},
id: testPolicyId,
isInvalid: false,
isServiceManaged: false,
label: 'Test private location 0',
},
@ -2012,22 +1997,16 @@ export default function ({ getService }: FtrProviderContext) {
id: 'localhost',
label: 'Local Synthetics Service',
geo: { lat: 0, lon: 0 },
url: 'mockDevUrl',
isServiceManaged: true,
status: 'experimental',
isInvalid: false,
},
{
label: 'Test private location 0',
isServiceManaged: false,
isInvalid: false,
agentPolicyId: testPolicyId,
id: testPolicyId,
geo: {
lat: '',
lon: '',
},
concurrentMonitors: 1,
},
]);
});