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 @@ -111,6 +111,7 @@ const STANDARD_LIST_TYPES = [
'uptime-dynamic-settings',
'synthetics-privates-locations',
'synthetics-private-location',
'synthetics-param',

'osquery-saved-query',
'osquery-pack',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import {
} from '../runtime_types/private_locations';

export const getPrivateLocations = async (
client: SavedObjectsClientContract
client: SavedObjectsClientContract,
spaceId?: string
): Promise<SyntheticsPrivateLocationsAttributes['locations']> => {
try {
const [results, legacyLocations] = await Promise.all([
getNewPrivateLocations(client),
getNewPrivateLocations(client, spaceId),
getLegacyPrivateLocations(client),
]);

Expand All @@ -39,10 +40,11 @@ export const getPrivateLocations = async (
}
};

const getNewPrivateLocations = async (client: SavedObjectsClientContract) => {
const getNewPrivateLocations = async (client: SavedObjectsClientContract, spaceId?: string) => {
const finder = client.createPointInTimeFinder<PrivateLocationAttributes>({
type: privateLocationSavedObjectName,
perPage: 1000,
...(spaceId ? { namespaces: [spaceId] } : {}),
});

const results: Array<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ describe('runSynPrivateLocationMonitorsTaskSoon', () => {
const error = new Error('Failed to run soon');
mockTaskManagerStart.runSoon.mockRejectedValue(error);

await runSynPrivateLocationMonitorsTaskSoon({ server: mockServerSetup as any });
await runSynPrivateLocationMonitorsTaskSoon({ server: mockServerSetup as any, retries: 0 });

expect(mockLogger.error).toHaveBeenCalledWith(
`Error scheduling Synthetics sync private location monitors task: ${error.message}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ALL_SPACES_ID } from '@kbn/spaces-plugin/common/constants';
import { ConcreteTaskInstance } from '@kbn/task-manager-plugin/server';
import moment from 'moment';
import { MAINTENANCE_WINDOW_SAVED_OBJECT_TYPE } from '@kbn/alerting-plugin/common';
import pRetry from 'p-retry';
import { syntheticsParamType } from '../../common/types/saved_objects';
import { normalizeSecrets } from '../synthetics_service/utils';
import type { PrivateLocationAttributes } from '../runtime_types/private_locations';
Expand Down Expand Up @@ -92,7 +93,7 @@ export class SyncPrivateLocationMonitorsTask {
const soClient = savedObjects.createInternalRepository([
MAINTENANCE_WINDOW_SAVED_OBJECT_TYPE,
]);
const allPrivateLocations = await getPrivateLocations(soClient);
const allPrivateLocations = await getPrivateLocations(soClient, ALL_SPACES_ID);
const { totalMWs, totalParams, hasDataChanged } = await this.hasAnyDataChanged({
soClient,
taskInstance,
Expand Down Expand Up @@ -384,19 +385,28 @@ export class SyncPrivateLocationMonitorsTask {

export const runSynPrivateLocationMonitorsTaskSoon = async ({
server,
retries = 5,
}: {
server: SyntheticsServerSetup;
retries?: number;
}) => {
const {
logger,
pluginsStart: { taskManager },
} = server;
try {
logger.debug(`Scheduling Synthetics sync private location monitors task soon`);
await taskManager.runSoon(TASK_ID);
logger.debug(`Synthetics sync private location task scheduled successfully`);
await pRetry(
async () => {
const {
logger,
pluginsStart: { taskManager },
} = server;
logger.debug(`Scheduling Synthetics sync private location monitors task soon`);
await taskManager.runSoon(TASK_ID);
logger.debug(`Synthetics sync private location task scheduled successfully`);
},
{
retries,
}
);
} catch (error) {
logger.error(
server.logger.error(
`Error scheduling Synthetics sync private location monitors task: ${error.message}`,
{ error }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/
import expect from '@kbn/expect';
import moment from 'moment/moment';
import { v4 as uuidv4 } from 'uuid';
import { omit, omitBy } from 'lodash';
import { format as formatUrl } from 'url';
Expand All @@ -22,29 +21,6 @@ import {
import { FtrProviderContext } from '../../ftr_provider_context';
import { getFixtureJson } from './helper/get_fixture_json';

export const addMonitorAPIHelper = async (supertestAPI: any, monitor: any, statusCode = 200) => {
const result = await supertestAPI
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
.set('kbn-xsrf', 'true')
.send(monitor);

expect(result.status).eql(statusCode, JSON.stringify(result.body));

if (statusCode === 200) {
const { created_at: createdAt, updated_at: updatedAt, id, config_id: configId } = result.body;
expect(id).not.empty();
expect(configId).not.empty();
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
return {
rawBody: result.body,
body: {
...omit(result.body, ['created_at', 'updated_at', 'id', 'config_id', 'form_monitor_type']),
},
};
}
return result.body;
};

export const keyToOmitList = [
'created_at',
'updated_at',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function ({ getService }: FtrProviderContext) {
});

it('add a test private location', async () => {
pvtLoc = await testPrivateLocations.addPrivateLocation();
pvtLoc = await testPrivateLocations.createPrivateLocation();
testFleetPolicyID = pvtLoc.agentPolicyId;

const apiResponse = await supertestAPI.get(SYNTHETICS_API_URLS.SERVICE_LOCATIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200);
await testPrivateLocations.installSyntheticsPackage();
await testPrivateLocations.addPrivateLocation();
await testPrivateLocations.createPrivateLocation();

await supertest
.post(SYNTHETICS_API_URLS.PARAMS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200);

const loc = await testPrivateLocations.addPrivateLocation();
const loc = await testPrivateLocations.createPrivateLocation();
testPolicyId = loc.id;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./add_monitor_private_location'));
loadTestFile(require.resolve('./edit_monitor'));
loadTestFile(require.resolve('./sync_global_params'));
loadTestFile(require.resolve('./sync_global_params_spaces'));
loadTestFile(require.resolve('./add_edit_params'));
loadTestFile(require.resolve('./private_location_apis'));
loadTestFile(require.resolve('./list_monitors'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function ({ getService }: FtrProviderContext) {
});

it('adds a test private location', async () => {
await testPrivateLocations.addPrivateLocation();
await testPrivateLocations.createPrivateLocation();
});

it('list all locations', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
legacyPrivateLocationsSavedObjectId,
legacyPrivateLocationsSavedObjectName,
} from '@kbn/synthetics-plugin/common/saved_objects/private_locations';
import { PackagePolicy } from '@kbn/fleet-plugin/common';
import { omit } from 'lodash';
import { FtrProviderContext } from '../../../ftr_provider_context';

export const INSTALLED_VERSION = '1.4.2';
Expand Down Expand Up @@ -54,7 +56,11 @@ export class PrivateLocationTestService {
return apiRes;
}

async addPrivateLocation({ policyId, label }: { policyId?: string; label?: string } = {}) {
async createPrivateLocation({
policyId,
label,
spaceId,
}: { policyId?: string; label?: string; spaceId?: string } = {}) {
let agentPolicyId = policyId;

if (!agentPolicyId) {
Expand All @@ -69,6 +75,7 @@ export class PrivateLocationTestService {
lat: 0,
lon: 0,
},
...(spaceId ? { spaces: [spaceId] } : {}),
};

const response = await this.supertest
Expand All @@ -80,6 +87,10 @@ export class PrivateLocationTestService {

const { isInvalid, ...loc } = response.body;

if (spaceId) {
return omit(loc, ['spaces']);
}

return loc;
}

Expand Down Expand Up @@ -122,4 +133,22 @@ export class PrivateLocationTestService {
.set('kbn-xsrf', 'true')
.expect(200);
}

async getPackagePolicy({
monitorId,
locId,
spaceId = 'default',
}: {
monitorId: string;
locId: string;
spaceId?: string;
}) {
const apiResponse = await this.supertest.get(
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
);

return apiResponse.body.items.find(
(pkgPolicy: PackagePolicy) => pkgPolicy.id === `${monitorId}-${locId}-${spaceId}`
);
}
}
Loading