diff --git a/__tests__/push/monitor.test.ts b/__tests__/push/monitor.test.ts index 0d890c96..a9863c02 100644 --- a/__tests__/push/monitor.test.ts +++ b/__tests__/push/monitor.test.ts @@ -82,6 +82,7 @@ describe('Monitors', () => { enabled: true, hash: expect.any(String), locations: ['europe-west2-a', 'australia-southeast1-a'], + 'service.name': 'test-service', privateLocations: ['germany'], fields: { area: 'website' }, }); @@ -99,6 +100,7 @@ describe('Monitors', () => { hash: expect.any(String), // hash is dynamic based on the file path locations: ['europe-west2-a', 'australia-southeast1-a'], privateLocations: ['germany'], + 'service.name': 'test-service', content: expect.any(String), filter: { match: 'test', diff --git a/__tests__/utils/test-config.ts b/__tests__/utils/test-config.ts index 4a0ae448..f13a8f9b 100644 --- a/__tests__/utils/test-config.ts +++ b/__tests__/utils/test-config.ts @@ -40,6 +40,7 @@ export function createTestMonitor(filename: string, type = 'browser') { type, schedule: 10, enabled: true, + serviceName: 'test-service', locations: ['united_kingdom', 'australia_east'], privateLocations: ['germany'], fields: { area: 'website' }, @@ -53,21 +54,31 @@ export function createTestMonitor(filename: string, type = 'browser') { return monitor; } -export function tJourney(status: StatusValue = "succeeded", duration = 0, error?: Error) { - const jj = journey('j1', () => { }); +export function tJourney( + status: StatusValue = 'succeeded', + duration = 0, + error?: Error +) { + const jj = journey('j1', () => {}); jj.status = status; jj.duration = duration; jj.error = error; - return jj + return jj; } -export function tStep(status: StatusValue = "succeeded", duration = 0, error?: Error, url?: string, name?: string) { +export function tStep( + status: StatusValue = 'succeeded', + duration = 0, + error?: Error, + url?: string, + name?: string +) { const ss = step(name ?? 's1', noop); ss.status = status; ss.duration = duration; ss.error = error; ss.url = url; - return ss + return ss; } export class CLIMock { @@ -81,7 +92,7 @@ export class CLIMock { private stderrStr = ''; exitCode: Promise; - constructor(public debug: boolean = false) { } + constructor(public debug: boolean = false) {} args(a: string[]): CLIMock { this.cliArgs.push(...a); diff --git a/src/dsl/monitor.ts b/src/dsl/monitor.ts index 0e2b943c..1286890c 100644 --- a/src/dsl/monitor.ts +++ b/src/dsl/monitor.ts @@ -63,6 +63,7 @@ export type MonitorConfig = { enabled?: boolean; locations?: SyntheticsLocationsType[]; privateLocations?: string[]; + serviceName?: string; /** * @deprecated This option is ignored. * Network throttling via chrome devtools is ignored at the moment. diff --git a/src/push/monitor.ts b/src/push/monitor.ts index 217a87d6..7a29213d 100644 --- a/src/push/monitor.ts +++ b/src/push/monitor.ts @@ -42,11 +42,12 @@ import { isParamOptionSupported, normalizeMonitorName } from './utils'; // Allowed extensions for lightweight monitor files const ALLOWED_LW_EXTENSIONS = ['.yml', '.yaml']; -export type MonitorSchema = Omit & { +export type MonitorSchema = Omit & { locations: string[]; content?: string; filter?: Monitor['filter']; hash?: string; + 'service.name'?: string; }; // Abbreviated monitor info, as often returned by the API, @@ -121,6 +122,10 @@ export function getLocalMonitors(schemas: MonitorSchema[]) { return data; } +type MonitorAPISchema = Omit & { + 'service.name'?: string; +}; + export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) { /** * Set up the bundle artifacts path which can be used to @@ -129,14 +134,19 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) { const bundlePath = join(SYNTHETICS_PATH, 'bundles'); await mkdir(bundlePath, { recursive: true }); const bundler = new Bundler(); - const schemas: MonitorSchema[] = []; + const schemas: MonitorAPISchema[] = []; for (const monitor of monitors) { const { source, config, filter, type } = monitor; - const schema: MonitorSchema = { - ...config, + const configNoServiceName = Object.assign({}, config); + delete configNoServiceName.serviceName; + const schema: MonitorAPISchema = { + ...configNoServiceName, locations: translateLocation(config.locations), }; + if (config.serviceName) { + schema['service.name'] = config.serviceName; + } if (type === 'browser') { const outPath = join(