Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export enum SYNTHETICS_API_URLS {
INDEX_SIZE = `/internal/synthetics/index_size`,
AGENT_POLICIES = `/internal/synthetics/agent_policies`,
PRIVATE_LOCATIONS_MONITORS = `/internal/synthetics/private_locations/monitors`,
SYNC_GLOBAL_PARAMS = `/internal/synthetics/sync_global_params`,
ENABLE_DEFAULT_ALERTING = `/internal/synthetics/enable_default_alerting`,
GET_ACTIONS_CONNECTORS = `/internal/synthetics/get_actions_connectors`,
GET_CONNECTOR_TYPES = `/internal/synthetics/get_connector_types`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { SyntheticsService } from './synthetics_service/synthetics_service';
import { syntheticsServiceApiKey } from './saved_objects/service_api_key';
import { SYNTHETICS_RULE_TYPES_ALERT_CONTEXT } from '../common/constants/synthetics_alerts';
import { syntheticsRuleTypeFieldMap } from './alert_rules/common';
import { SyncPrivateLocationMonitorsTask } from './tasks/sync_private_locations_monitors_task';

export class Plugin implements PluginType {
private savedObjectsClient?: SavedObjectsClientContract;
Expand All @@ -38,6 +39,7 @@ export class Plugin implements PluginType {
private syntheticsService?: SyntheticsService;
private syntheticsMonitorClient?: SyntheticsMonitorClient;
private readonly telemetryEventsSender: TelemetryEventsSender;
private syncPrivateLocationMonitorsTask?: SyncPrivateLocationMonitorsTask;

constructor(private readonly initContext: PluginInitializerContext<UptimeConfig>) {
this.logger = initContext.logger.get();
Expand Down Expand Up @@ -89,6 +91,12 @@ export class Plugin implements PluginType {

registerSyntheticsSavedObjects(core.savedObjects, plugins.encryptedSavedObjects);

this.syncPrivateLocationMonitorsTask = new SyncPrivateLocationMonitorsTask(
this.server,
plugins.taskManager,
this.syntheticsMonitorClient
);

return {};
}

Expand All @@ -107,6 +115,9 @@ export class Plugin implements PluginType {
this.server.spaces = pluginsStart.spaces;
this.server.isElasticsearchServerless = coreStart.elasticsearch.getCapabilities().serverless;
}
this.syncPrivateLocationMonitorsTask?.start().catch(() => {
this.logger.error('Failed to start sync private location monitors task');
});

this.syntheticsService?.start(pluginsStart.taskManager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { createJourneyScreenshotBlocksRoute } from './pings/journey_screenshot_b
import { createLastSuccessfulCheckRoute } from './pings/last_successful_check';
import { createJourneyFailedStepsRoute, createJourneyRoute } from './pings/journeys';
import { updateDefaultAlertingRoute } from './default_alerts/update_default_alert';
import { syncParamsSyntheticsParamsRoute } from './settings/sync_global_params';
import { getIndexSizesRoute } from './settings/settings';
import { getAPIKeySyntheticsRoute } from './monitor_cruds/get_api_key';
import { getServiceLocationsRoute } from './synthetics_service/get_service_locations';
Expand Down Expand Up @@ -80,7 +79,6 @@ export const syntheticsAppRestApiRoutes: SyntheticsRestApiRouteFactory[] = [
getHasIntegrationMonitorsRoute,
createGetCurrentStatusRoute,
getIndexSizesRoute,
syncParamsSyntheticsParamsRoute,
enableDefaultAlertingRoute,
getDefaultAlertingRoute,
updateDefaultAlertingRoute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema';
import { ALL_SPACES_ID } from '@kbn/security-plugin/common/constants';
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
import { SavedObject, SavedObjectsBulkCreateObject } from '@kbn/core-saved-objects-api-server';
import { syncSpaceGlobalParams } from '../../../synthetics_service/sync_global_params';
import { runSynPrivateLocationMonitorsTaskSoon } from '../../../tasks/sync_private_locations_monitors_task';
import { SyntheticsRestApiRouteFactory } from '../../types';
import {
SyntheticsParamRequest,
Expand Down Expand Up @@ -42,7 +42,7 @@ export const addSyntheticsParamsRoute: SyntheticsRestApiRouteFactory<
body: schema.oneOf([ParamsObjectSchema, schema.arrayOf(ParamsObjectSchema)]),
},
},
handler: async ({ request, response, server, savedObjectsClient, syntheticsMonitorClient }) => {
handler: async ({ request, response, server, savedObjectsClient }) => {
try {
const { id: spaceId } = (await server.spaces?.spacesService.getActiveSpace(request)) ?? {
id: DEFAULT_SPACE_ID,
Expand All @@ -57,12 +57,8 @@ export const addSyntheticsParamsRoute: SyntheticsRestApiRouteFactory<
savedObjectsData
);

void syncSpaceGlobalParams({
spaceId,
logger: server.logger,
encryptedSavedObjects: server.encryptedSavedObjects,
savedObjects: server.coreStart.savedObjects,
syntheticsMonitorClient,
await runSynPrivateLocationMonitorsTaskSoon({
server,
});

if (savedObjectsData.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { syncSpaceGlobalParams } from '../../../synthetics_service/sync_global_params';
import { runSynPrivateLocationMonitorsTaskSoon } from '../../../tasks/sync_private_locations_monitors_task';
import { SyntheticsRestApiRouteFactory } from '../../types';
import { syntheticsParamType } from '../../../../common/types/saved_objects';
import { SYNTHETICS_API_URLS } from '../../../../common/constants';
Expand Down Expand Up @@ -36,14 +36,7 @@ export const deleteSyntheticsParamsRoute: SyntheticsRestApiRouteFactory<
}),
},
},
handler: async ({
savedObjectsClient,
request,
response,
server,
spaceId,
syntheticsMonitorClient,
}) => {
handler: async ({ savedObjectsClient, request, response, server }) => {
const { ids } = request.body ?? {};
const { id: paramId } = request.params ?? {};

Expand All @@ -69,13 +62,8 @@ export const deleteSyntheticsParamsRoute: SyntheticsRestApiRouteFactory<
idsToDelete.map((id) => ({ type: syntheticsParamType, id })),
{ force: true }
);

void syncSpaceGlobalParams({
spaceId,
logger: server.logger,
encryptedSavedObjects: server.encryptedSavedObjects,
savedObjects: server.coreStart.savedObjects,
syntheticsMonitorClient,
await runSynPrivateLocationMonitorsTaskSoon({
server,
});

return result.statuses.map(({ id, success }) => ({ id, deleted: success }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { syncSpaceGlobalParams } from '../../../synthetics_service/sync_global_params';
import { runSynPrivateLocationMonitorsTaskSoon } from '../../../tasks/sync_private_locations_monitors_task';
import { SyntheticsRestApiRouteFactory } from '../../types';
import { syntheticsParamType } from '../../../../common/types/saved_objects';
import { SYNTHETICS_API_URLS } from '../../../../common/constants';
Expand All @@ -28,20 +28,16 @@ export const deleteSyntheticsParamsBulkRoute: SyntheticsRestApiRouteFactory<
}),
},
},
handler: async ({ savedObjectsClient, request, server, spaceId, syntheticsMonitorClient }) => {
handler: async ({ savedObjectsClient, request, server, spaceId }) => {
const { ids } = request.body;

const result = await savedObjectsClient.bulkDelete(
ids.map((id) => ({ type: syntheticsParamType, id })),
{ force: true }
);

void syncSpaceGlobalParams({
spaceId,
logger: server.logger,
encryptedSavedObjects: server.encryptedSavedObjects,
savedObjects: server.coreStart.savedObjects,
syntheticsMonitorClient,
await runSynPrivateLocationMonitorsTaskSoon({
server,
});

return result.statuses.map(({ id, success }) => ({ id, deleted: success }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { schema, TypeOf } from '@kbn/config-schema';
import { SavedObject, SavedObjectsErrorHelpers } from '@kbn/core/server';
import { isEmpty } from 'lodash';
import { syncSpaceGlobalParams } from '../../../synthetics_service/sync_global_params';
import { runSynPrivateLocationMonitorsTaskSoon } from '../../../tasks/sync_private_locations_monitors_task';
import { validateRouteSpaceName } from '../../common';
import { SyntheticsRestApiRouteFactory } from '../../types';
import { SyntheticsParamRequest, SyntheticsParams } from '../../../../common/runtime_types';
Expand Down Expand Up @@ -48,8 +48,7 @@ export const editSyntheticsParamsRoute: SyntheticsRestApiRouteFactory<
},
},
handler: async (routeContext) => {
const { savedObjectsClient, request, response, spaceId, server, syntheticsMonitorClient } =
routeContext;
const { savedObjectsClient, request, response, spaceId, server } = routeContext;
const { invalidResponse } = await validateRouteSpaceName(routeContext);
if (invalidResponse) return invalidResponse;

Expand Down Expand Up @@ -85,12 +84,8 @@ export const editSyntheticsParamsRoute: SyntheticsRestApiRouteFactory<
newParam
)) as SavedObject<SyntheticsParams>;

void syncSpaceGlobalParams({
spaceId,
logger: server.logger,
encryptedSavedObjects: server.encryptedSavedObjects,
savedObjects: server.coreStart.savedObjects,
syntheticsMonitorClient,
await runSynPrivateLocationMonitorsTaskSoon({
server,
});

return { id: responseId, key, tags, description, namespaces, value };
Expand Down

This file was deleted.

This file was deleted.

Loading