Skip to content

Commit

Permalink
feat: add 2 types of tags formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Feb 2, 2025
1 parent bee1440 commit f5de01d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
10 changes: 8 additions & 2 deletions src/lib/override/adopted-probes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,14 @@ export class AdoptedProbes {
const adoptions: Adoption[] = rows.map(row => ({
...row,
altIps: JSON.parse(row.altIps) as string[],
tags: (JSON.parse(row.tags) as { prefix: string; value: string; }[])
.map(({ prefix, value }) => ({ type: 'user' as const, value: `u-${prefix}-${value}` })),
tags: (JSON.parse(row.tags) as { prefix: string; value: string; format?: string; }[])
.map(({ prefix, value, format }) => {
if (format === 'v1') {
return { type: 'user' as const, value: `u-${prefix}-${value}` };
}

return { type: 'user' as const, value: `u-${prefix}:${value}` };
}),
systemTags: JSON.parse(row.systemTags) as string[],
isCustomCity: Boolean(row.isCustomCity),
isIPv4Supported: Boolean(row.isIPv4Supported),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cases/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('adopted probe', () => {
target: 'www.jsdelivr.com',
type: 'ping',
locations: [{
tags: [ 'u-jimaek-dashboardtag1' ],
tags: [ 'u-jimaek:dashboardtag1' ],
}],
} });

Expand Down
16 changes: 8 additions & 8 deletions test/tests/integration/measurement/create-measurement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,12 @@ describe('Create measurement', () => {
});
});

it('should create measurement with adopted "tags: ["u-jsdelivr-dashboard-tag"]" location', async () => {
it('should create measurement with adopted "tags: ["u-jsdelivr:dashboard-tag"]" location', async () => {
await requestAgent.post('/v1/measurements')
.send({
type: 'ping',
target: 'example.com',
locations: [{ tags: [ 'u-jsdelivr-dashboard-tag' ], limit: 2 }],
locations: [{ tags: [ 'u-jsdelivr:dashboard-tag' ], limit: 2 }],
})
.expect(202)
.expect((response) => {
Expand All @@ -736,12 +736,12 @@ describe('Create measurement', () => {
});
});

it('should create measurement with adopted "tags: ["u-jsdelivr-Dashboard-Tag"]" in any letter case', async () => {
it('should create measurement with adopted "tags: ["u-jsdelivr:Dashboard-Tag"]" in any letter case', async () => {
await requestAgent.post('/v1/measurements')
.send({
type: 'ping',
target: 'example.com',
locations: [{ tags: [ 'u-jsdelivr-Dashboard-Tag' ], limit: 2 }],
locations: [{ tags: [ 'u-jsdelivr:Dashboard-Tag' ], limit: 2 }],
})
.expect(202)
.expect((response) => {
Expand All @@ -763,7 +763,7 @@ describe('Create measurement', () => {
// Creating an AR probe which has a tag value inside of the content (network name).
nock('https://ipinfo.io').get(/.*/).reply(200, {
...geoIpMocks.ipinfo.argentina,
org: 'AS61004 InterBS u-jsdelivr-dashboard-tag S.R.L.',
org: 'AS61004 InterBS u-jsdelivr:dashboard-tag S.R.L.',
});

probe2 = await addFakeProbe();
Expand All @@ -783,7 +783,7 @@ describe('Create measurement', () => {
.send({
type: 'ping',
target: 'example.com',
locations: [{ magic: 'u-jsdelivr-dashboard-tag', limit: 2 }],
locations: [{ magic: 'u-jsdelivr:dashboard-tag', limit: 2 }],
})
.expect(202)
.expect((response) => {
Expand All @@ -808,7 +808,7 @@ describe('Create measurement', () => {
.send({
type: 'ping',
target: 'example.com',
locations: [{ magic: 'u-jsdelivr-dashboard-tag', limit: 2 }],
locations: [{ magic: 'u-jsdelivr:dashboard-tag', limit: 2 }],
})
.expect(202)
.expect((response) => {
Expand All @@ -831,7 +831,7 @@ describe('Create measurement', () => {
.send({
type: 'ping',
target: 'example.com',
locations: [{ magic: 'U-JSdelivr-Dashboard-TAG', limit: 2 }],
locations: [{ magic: 'U-JSdelivr:Dashboard-TAG', limit: 2 }],
})
.expect(202)
.expect((response) => {
Expand Down
2 changes: 1 addition & 1 deletion test/tests/integration/probes/get-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('Get Probes', () => {
asn: 61004,
network: 'InterBS S.R.L. (BAEHOST)',
},
tags: [ 'u-jimaek-dashboardtag1' ],
tags: [ 'u-jimaek:dashboardtag1' ],
resolvers: [],
});

Expand Down
4 changes: 2 additions & 2 deletions test/tests/unit/override/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ describe('AdoptedProbes', () => {
...defaultAdoptedProbe,
altIps: [],
systemTags: [ 'datacenter-network' ],
tags: [{ type: 'user', value: 'u-jimaek-dashboardtag' }],
tags: [{ type: 'user', value: 'u-jimaek:dashboardtag' }],
isCustomCity: false,
isIPv4Supported: true,
isIPv6Supported: true,
Expand Down Expand Up @@ -854,7 +854,7 @@ describe('AdoptedProbes', () => {
const updatedTags = adoptedProbes.getUpdatedTags(defaultConnectedProbe);
expect(updatedTags).to.deep.equal([
{ type: 'system', value: 'datacenter-network' },
{ type: 'user', value: 'u-jimaek-dashboardtag' },
{ type: 'user', value: 'u-jimaek:dashboardtag' },
]);
});

Expand Down
4 changes: 2 additions & 2 deletions test/tests/unit/probe/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,13 +1038,13 @@ describe('probe router', () => {
const probe = await buildProbe(String(Date.now()), location);
probe.tags = [
...probe.tags,
{ type: 'user', value: 'u-MartinKolarik-DashboardTag' },
{ type: 'user', value: 'u-MartinKolarik:DashboardTag' },
];

const probes: DeepPartial<Probe[]> = [ probe ];

const locations: Location[] = [
{ tags: [ 'u-martinkolarik-dashboardtag' ] },
{ tags: [ 'u-martinkolarik:dashboardtag' ] },
];

fetchProbesMock.resolves(probes as never);
Expand Down
2 changes: 1 addition & 1 deletion test/tests/unit/ws/synced-probe-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ describe('SyncedProbeList', () => {
const probe2 = getProbe('B');
const sockets = [{ data: { probe: probe1 } }, { data: { probe: probe2 } }];

const tags = [{ type: 'user', value: 'u-name-tag1' }] as Probe['tags'];
const tags = [{ type: 'user', value: 'u-name:tag1' }] as Probe['tags'];

const adoptedData = { tags } as Probe;

Expand Down

0 comments on commit f5de01d

Please sign in to comment.