Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support service.name property for tests #974

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions __tests__/push/monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
});
Expand All @@ -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',
Expand Down
23 changes: 17 additions & 6 deletions __tests__/utils/test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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 {
Expand All @@ -81,7 +92,7 @@ export class CLIMock {
private stderrStr = '';
exitCode: Promise<number>;

constructor(public debug: boolean = false) { }
constructor(public debug: boolean = false) {}

args(a: string[]): CLIMock {
this.cliArgs.push(...a);
Expand Down
1 change: 1 addition & 0 deletions src/dsl/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 14 additions & 4 deletions src/push/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MonitorConfig, 'locations'> & {
export type MonitorSchema = Omit<MonitorConfig, 'locations' | 'serviceName'> & {
locations: string[];
content?: string;
filter?: Monitor['filter'];
hash?: string;
'service.name'?: string;
};

// Abbreviated monitor info, as often returned by the API,
Expand Down Expand Up @@ -121,6 +122,10 @@ export function getLocalMonitors(schemas: MonitorSchema[]) {
return data;
}

type MonitorAPISchema = Omit<MonitorSchema, 'serviceName'> & {
'service.name'?: string;
};

export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) {
/**
* Set up the bundle artifacts path which can be used to
Expand All @@ -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(
Expand Down
Loading