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 1 commit
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
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
Loading