Skip to content

Commit

Permalink
Support service.name property for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvc committed Oct 25, 2024
1 parent 22fb009 commit a1891ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
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
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
16 changes: 13 additions & 3 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 @@ -133,10 +138,15 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) {

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

0 comments on commit a1891ff

Please sign in to comment.