diff --git a/migrations/create-tables.js.sql b/migrations/create-tables.js.sql index cddb344f..18f130d1 100644 --- a/migrations/create-tables.js.sql +++ b/migrations/create-tables.js.sql @@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS gp_adopted_probes ( version VARCHAR(255) NOT NULL, nodeVersion VARCHAR(255) NOT NULL, hardwareDevice VARCHAR(255) NULL, + hardwareDeviceFirmware VARCHAR(255) NULL, country VARCHAR(255) NOT NULL, city VARCHAR(255), state VARCHAR(255), diff --git a/src/adoption-code/route/adoption-code.ts b/src/adoption-code/route/adoption-code.ts index 74eab76e..26bcd791 100644 --- a/src/adoption-code/route/adoption-code.ts +++ b/src/adoption-code/route/adoption-code.ts @@ -20,6 +20,7 @@ const handle = async (ctx: Context): Promise => { version: probe.version, nodeVersion: probe.nodeVersion, hardwareDevice: probe.hardwareDevice, + hardwareDeviceFirmware: probe.hardwareDeviceFirmware, status: probe.status, systemTags: probe.tags.filter(({ type }) => type === 'system').map(({ value }) => value), city: probe.location.city, diff --git a/src/lib/override/adopted-probes.ts b/src/lib/override/adopted-probes.ts index d38ea390..093e9b20 100644 --- a/src/lib/override/adopted-probes.ts +++ b/src/lib/override/adopted-probes.ts @@ -34,6 +34,7 @@ export type Adoption = { version: string | null; nodeVersion: string | null; hardwareDevice: string | null; + hardwareDeviceFirmware: string | null; country: string | null; countryOfCustomCity: string | null; city: string | null; @@ -100,6 +101,10 @@ export class AdoptedProbes { probeField: 'hardwareDevice', shouldUpdateIfCustomCity: true, }, + hardwareDeviceFirmware: { + probeField: 'hardwareDeviceFirmware', + shouldUpdateIfCustomCity: true, + }, systemTags: { probeField: 'tags', shouldUpdateIfCustomCity: true, diff --git a/src/probe/builder.ts b/src/probe/builder.ts index c619fe3c..a73fa8be 100644 --- a/src/probe/builder.ts +++ b/src/probe/builder.ts @@ -21,7 +21,9 @@ export const buildProbe = async (socket: Socket): Promise => { const uuid = String(socket.handshake.query['uuid']); const isHardware = socket.handshake.query['isHardware'] === 'true' || socket.handshake.query['isHardware'] === '1'; const hardwareDeviceValue = socket.handshake.query['hardwareDevice']; + const hardwareDeviceFirmwareValue = socket.handshake.query['hardwareDeviceFirmware']; const hardwareDevice = (!hardwareDeviceValue || hardwareDeviceValue === 'undefined') ? null : String(hardwareDeviceValue); + const hardwareDeviceFirmware = (!hardwareDeviceFirmwareValue || hardwareDeviceFirmwareValue === 'undefined') ? null : String(hardwareDeviceFirmwareValue); const host = process.env['HOSTNAME'] ?? ''; const ip = getProbeIp(socket); @@ -63,6 +65,7 @@ export const buildProbe = async (socket: Socket): Promise => { uuid, isHardware, hardwareDevice, + hardwareDeviceFirmware, ipAddress: ip, altIpAddresses: [], host, diff --git a/src/probe/route/get-probes.ts b/src/probe/route/get-probes.ts index d36db0a9..48c1c3fd 100644 --- a/src/probe/route/get-probes.ts +++ b/src/probe/route/get-probes.ts @@ -5,39 +5,40 @@ import { fetchProbes } from '../../lib/ws/server.js'; const handle = async (ctx: ParameterizedContext): Promise => { const { isAdmin, isSystem } = ctx; - let sockets = await fetchProbes(); + let probes = await fetchProbes(); if (!isAdmin && !isSystem) { - sockets = sockets.filter(socket => socket.status === 'ready'); + probes = probes.filter(probe => probe.status === 'ready'); } - ctx.body = sockets.map((socket: Probe) => ({ - status: (isAdmin || isSystem) ? socket.status : undefined, - version: socket.version, - isIPv4Supported: (isAdmin || isSystem) ? socket.isIPv4Supported : undefined, - isIPv6Supported: (isAdmin || isSystem) ? socket.isIPv6Supported : undefined, - nodeVersion: isAdmin ? socket.nodeVersion : undefined, - uuid: isAdmin ? socket.uuid : undefined, - ipAddress: (isAdmin || isSystem) ? socket.ipAddress : undefined, - altIpAddresses: (isAdmin || isSystem) ? socket.altIpAddresses : undefined, + ctx.body = probes.map((probe: Probe) => ({ + status: (isAdmin || isSystem) ? probe.status : undefined, + version: probe.version, + isIPv4Supported: (isAdmin || isSystem) ? probe.isIPv4Supported : undefined, + isIPv6Supported: (isAdmin || isSystem) ? probe.isIPv6Supported : undefined, + nodeVersion: isAdmin ? probe.nodeVersion : undefined, + uuid: isAdmin ? probe.uuid : undefined, + ipAddress: (isAdmin || isSystem) ? probe.ipAddress : undefined, + altIpAddresses: (isAdmin || isSystem) ? probe.altIpAddresses : undefined, location: { - continent: socket.location.continent, - region: socket.location.region, - country: socket.location.country, - state: socket.location.state, - city: socket.location.city, - asn: socket.location.asn, - latitude: socket.location.latitude, - longitude: socket.location.longitude, - network: socket.location.network, + continent: probe.location.continent, + region: probe.location.region, + country: probe.location.country, + state: probe.location.state, + city: probe.location.city, + asn: probe.location.asn, + latitude: probe.location.latitude, + longitude: probe.location.longitude, + network: probe.location.network, }, - tags: socket.tags.map(({ value }) => value), - ...(isAdmin && socket.isHardware ? { isHardware: socket.isHardware } : null), - ...(isAdmin && socket.hardwareDevice ? { hardwareDevice: socket.hardwareDevice } : null), - resolvers: socket.resolvers, - host: isAdmin ? socket.host : undefined, - stats: isAdmin ? socket.stats : undefined, - hostInfo: isAdmin ? socket.hostInfo : undefined, + tags: probe.tags.map(({ value }) => value), + ...(isAdmin && probe.isHardware ? { isHardware: probe.isHardware } : null), + ...(isAdmin && probe.hardwareDevice ? { hardwareDevice: probe.hardwareDevice } : null), + ...(isAdmin && probe.hardwareDeviceFirmware ? { hardwareDeviceFirmware: probe.hardwareDeviceFirmware } : null), + resolvers: probe.resolvers, + host: isAdmin ? probe.host : undefined, + stats: isAdmin ? probe.stats : undefined, + hostInfo: isAdmin ? probe.hostInfo : undefined, })); }; diff --git a/src/probe/router.ts b/src/probe/router.ts index 95315d5c..0f23fef6 100644 --- a/src/probe/router.ts +++ b/src/probe/router.ts @@ -150,6 +150,7 @@ export class ProbeRouter { uuid: null, isHardware: false, hardwareDevice: null, + hardwareDeviceFirmware: null, ipAddress: ip, altIpAddresses: [], host: null, diff --git a/src/probe/types.ts b/src/probe/types.ts index fe77f721..964665f1 100644 --- a/src/probe/types.ts +++ b/src/probe/types.ts @@ -44,6 +44,7 @@ export type Probe = { uuid: string; isHardware: boolean; hardwareDevice: string | null; + hardwareDeviceFirmware: string | null; ipAddress: string; altIpAddresses: string[]; host: string; @@ -66,6 +67,7 @@ export type OfflineProbe = Modify { isIPv6Supported: true, version: '0.28.0', nodeVersion: 'v18.14.2', - hardwareDevice: null, country: 'FR', countryOfCustomCity: 'FR', city: 'Marseille', diff --git a/test/e2e/cases/adoption-code.test.ts b/test/e2e/cases/adoption-code.test.ts index 8c2bdf49..dde744a2 100644 --- a/test/e2e/cases/adoption-code.test.ts +++ b/test/e2e/cases/adoption-code.test.ts @@ -17,6 +17,7 @@ describe('/adoption-code endpoint', () => { city: 'Paris', country: 'FR', hardwareDevice: null, + hardwareDeviceFirmware: null, state: null, status: 'ready', }); diff --git a/test/tests/integration/adoption-code.test.ts b/test/tests/integration/adoption-code.test.ts index b0b74681..8cb3521b 100644 --- a/test/tests/integration/adoption-code.test.ts +++ b/test/tests/integration/adoption-code.test.ts @@ -45,6 +45,7 @@ describe('Adoption code', () => { version: '0.14.0', nodeVersion: 'v18.17.0', hardwareDevice: null, + hardwareDeviceFirmware: null, status: 'initializing', systemTags: [ 'datacenter-network' ], city: 'Dallas', diff --git a/test/tests/integration/measurement/create-measurement.test.ts b/test/tests/integration/measurement/create-measurement.test.ts index 7ac6e3f8..a3addcc9 100644 --- a/test/tests/integration/measurement/create-measurement.test.ts +++ b/test/tests/integration/measurement/create-measurement.test.ts @@ -689,7 +689,6 @@ describe('Create measurement', () => { isIPv6Supported: true, version: '0.26.0', nodeVersion: 'v18.14.2', - hardwareDevice: null, country: 'US', countryOfCustomCity: 'US', city: 'Oklahoma City', @@ -860,7 +859,6 @@ describe('Create measurement', () => { isIPv6Supported: true, version: '0.26.0', nodeVersion: 'v18.14.2', - hardwareDevice: null, country: 'US', countryOfCustomCity: 'US', city: 'Oklahoma City', diff --git a/test/tests/integration/probes/get-probes.test.ts b/test/tests/integration/probes/get-probes.test.ts index 72d5795a..ac48db00 100644 --- a/test/tests/integration/probes/get-probes.test.ts +++ b/test/tests/integration/probes/get-probes.test.ts @@ -294,7 +294,6 @@ describe('Get Probes', () => { isIPv6Supported: false, version: '0.26.0', nodeVersion: 'v18.14.2', - hardwareDevice: null, country: 'AR', countryOfCustomCity: 'AR', city: 'Cordoba', diff --git a/test/tests/unit/override/adopted-probes.test.ts b/test/tests/unit/override/adopted-probes.test.ts index 5fb63cf0..ef94d290 100644 --- a/test/tests/unit/override/adopted-probes.test.ts +++ b/test/tests/unit/override/adopted-probes.test.ts @@ -22,6 +22,7 @@ describe('AdoptedProbes', () => { version: '0.26.0', nodeVersion: 'v18.17.0', hardwareDevice: null, + hardwareDeviceFirmware: null, country: 'IE', state: null, countryOfCustomCity: '', @@ -56,6 +57,7 @@ describe('AdoptedProbes', () => { }, isHardware: false, hardwareDevice: null, + hardwareDeviceFirmware: null, tags: [{ type: 'system', value: 'datacenter-network', @@ -299,6 +301,7 @@ describe('AdoptedProbes', () => { nodeVersion: 'v18.17.1', isHardware: true, hardwareDevice: 'v1', + hardwareDeviceFirmware: 'v2.2', tags: [ { type: 'system', value: 'eyeball-network' }, ], @@ -329,6 +332,7 @@ describe('AdoptedProbes', () => { version: '0.27.0', nodeVersion: 'v18.17.1', hardwareDevice: 'v1', + hardwareDeviceFirmware: 'v2.2', systemTags: '["eyeball-network"]', asn: 20473, network: 'The Constant Company, LLC', @@ -365,6 +369,7 @@ describe('AdoptedProbes', () => { nodeVersion: 'v18.17.0', isHardware: false, hardwareDevice: null, + hardwareDeviceFirmware: null, tags: [ { type: 'system', value: 'datacenter-network' }, ], @@ -391,6 +396,7 @@ describe('AdoptedProbes', () => { nodeVersion: 'v18.17.0', isHardware: false, hardwareDevice: null, + hardwareDeviceFirmware: null, tags: [ { type: 'system', value: 'datacenter-network' }, ], @@ -467,6 +473,7 @@ describe('AdoptedProbes', () => { nodeVersion: 'v18.17.0', isHardware: false, hardwareDevice: null, + hardwareDeviceFirmware: null, tags: [ { type: 'system', value: 'datacenter-network' }, ], @@ -493,6 +500,7 @@ describe('AdoptedProbes', () => { nodeVersion: 'v18.17.0', isHardware: false, hardwareDevice: null, + hardwareDeviceFirmware: null, tags: [ { type: 'system', value: 'datacenter-network' }, ], @@ -572,6 +580,7 @@ describe('AdoptedProbes', () => { nodeVersion: 'v18.17.0', isHardware: false, hardwareDevice: null, + hardwareDeviceFirmware: null, tags: [ { type: 'system', value: 'datacenter-network' }, ], diff --git a/test/utils/server.ts b/test/utils/server.ts index 737838b8..3691e2aa 100644 --- a/test/utils/server.ts +++ b/test/utils/server.ts @@ -55,6 +55,7 @@ export const addFakeProbes = async (count: number, events: object = {}, options: uuid: '1-1-1-1-1', isHardware: 'undefined', hardwareDevice: 'undefined', + hardwareDeviceFirmware: 'undefined', totalMemory: 1e9, totalDiskSize: 2e3, availableDiskSpace: 1e3,