From 829697d0e70239f3efc199f5adcac6ca3e0016d7 Mon Sep 17 00:00:00 2001 From: Alexey Yarmosh Date: Fri, 31 Jan 2025 19:16:32 +0100 Subject: [PATCH] feat: add 2 types of tags formatting --- src/lib/override/adopted-probes.ts | 10 ++++++++-- test/e2e/cases/adopted-probes.test.ts | 2 +- .../measurement/create-measurement.test.ts | 16 ++++++++-------- test/tests/integration/probes/get-probes.test.ts | 2 +- test/tests/unit/override/adopted-probes.test.ts | 4 ++-- test/tests/unit/probe/router.test.ts | 4 ++-- test/tests/unit/ws/synced-probe-list.test.ts | 2 +- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/lib/override/adopted-probes.ts b/src/lib/override/adopted-probes.ts index 548776d0..469656ba 100644 --- a/src/lib/override/adopted-probes.ts +++ b/src/lib/override/adopted-probes.ts @@ -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), diff --git a/test/e2e/cases/adopted-probes.test.ts b/test/e2e/cases/adopted-probes.test.ts index e9748fd3..5e42beb5 100644 --- a/test/e2e/cases/adopted-probes.test.ts +++ b/test/e2e/cases/adopted-probes.test.ts @@ -62,7 +62,7 @@ describe('adopted probe', () => { target: 'www.jsdelivr.com', type: 'ping', locations: [{ - tags: [ 'u-jimaek-dashboardtag1' ], + tags: [ 'u-jimaek:dashboardtag1' ], }], } }); diff --git a/test/tests/integration/measurement/create-measurement.test.ts b/test/tests/integration/measurement/create-measurement.test.ts index 7ceaf163..3fba319b 100644 --- a/test/tests/integration/measurement/create-measurement.test.ts +++ b/test/tests/integration/measurement/create-measurement.test.ts @@ -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) => { @@ -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) => { @@ -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(); @@ -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) => { @@ -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) => { @@ -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) => { diff --git a/test/tests/integration/probes/get-probes.test.ts b/test/tests/integration/probes/get-probes.test.ts index 47a23b33..060032ac 100644 --- a/test/tests/integration/probes/get-probes.test.ts +++ b/test/tests/integration/probes/get-probes.test.ts @@ -336,7 +336,7 @@ describe('Get Probes', () => { asn: 61004, network: 'InterBS S.R.L. (BAEHOST)', }, - tags: [ 'u-jimaek-dashboardtag1' ], + tags: [ 'u-jimaek:dashboardtag1' ], resolvers: [], }); diff --git a/test/tests/unit/override/adopted-probes.test.ts b/test/tests/unit/override/adopted-probes.test.ts index b01252ea..0dcc7b12 100644 --- a/test/tests/unit/override/adopted-probes.test.ts +++ b/test/tests/unit/override/adopted-probes.test.ts @@ -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, @@ -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' }, ]); }); diff --git a/test/tests/unit/probe/router.test.ts b/test/tests/unit/probe/router.test.ts index a70c4749..0500c715 100644 --- a/test/tests/unit/probe/router.test.ts +++ b/test/tests/unit/probe/router.test.ts @@ -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 ]; const locations: Location[] = [ - { tags: [ 'u-martinkolarik-dashboardtag' ] }, + { tags: [ 'u-martinkolarik:dashboardtag' ] }, ]; fetchProbesMock.resolves(probes as never); diff --git a/test/tests/unit/ws/synced-probe-list.test.ts b/test/tests/unit/ws/synced-probe-list.test.ts index f8635f72..7090d9fb 100644 --- a/test/tests/unit/ws/synced-probe-list.test.ts +++ b/test/tests/unit/ws/synced-probe-list.test.ts @@ -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;