Skip to content

Commit

Permalink
feat: sync hw firmware with dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Jan 14, 2025
1 parent 26e2cd6 commit de8d0ef
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 31 deletions.
1 change: 1 addition & 0 deletions migrations/create-tables.js.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/adoption-code/route/adoption-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const handle = async (ctx: Context): Promise<void> => {
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,
Expand Down
5 changes: 5 additions & 0 deletions src/lib/override/adopted-probes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,6 +101,10 @@ export class AdoptedProbes {
probeField: 'hardwareDevice',
shouldUpdateIfCustomCity: true,
},
hardwareDeviceFirmware: {
probeField: 'hardwareDeviceFirmware',
shouldUpdateIfCustomCity: true,
},
systemTags: {
probeField: 'tags',
shouldUpdateIfCustomCity: true,
Expand Down
3 changes: 3 additions & 0 deletions src/probe/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export const buildProbe = async (socket: Socket): Promise<Probe> => {
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);
Expand Down Expand Up @@ -63,6 +65,7 @@ export const buildProbe = async (socket: Socket): Promise<Probe> => {
uuid,
isHardware,
hardwareDevice,
hardwareDeviceFirmware,
ipAddress: ip,
altIpAddresses: [],
host,
Expand Down
55 changes: 28 additions & 27 deletions src/probe/route/get-probes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,40 @@ import { fetchProbes } from '../../lib/ws/server.js';

const handle = async (ctx: ParameterizedContext<DefaultState, DefaultContext & Router.RouterParamContext>): Promise<void> => {
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,
}));
};

Expand Down
1 change: 1 addition & 0 deletions src/probe/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class ProbeRouter {
uuid: null,
isHardware: false,
hardwareDevice: null,
hardwareDeviceFirmware: null,
ipAddress: ip,
altIpAddresses: [],
host: null,
Expand Down
2 changes: 2 additions & 0 deletions src/probe/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type Probe = {
uuid: string;
isHardware: boolean;
hardwareDevice: string | null;
hardwareDeviceFirmware: string | null;
ipAddress: string;
altIpAddresses: string[];
host: string;
Expand All @@ -66,6 +67,7 @@ export type OfflineProbe = Modify<Probe, {
uuid: null;
isHardware: false;
hardwareDevice: null;
hardwareDeviceFirmware: null;
host: null;
hostInfo: {
totalMemory: null;
Expand Down
1 change: 0 additions & 1 deletion test/e2e/cases/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('adopted probe', () => {
isIPv6Supported: true,
version: '0.28.0',
nodeVersion: 'v18.14.2',
hardwareDevice: null,
country: 'FR',
countryOfCustomCity: 'FR',
city: 'Marseille',
Expand Down
1 change: 1 addition & 0 deletions test/e2e/cases/adoption-code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('/adoption-code endpoint', () => {
city: 'Paris',
country: 'FR',
hardwareDevice: null,
hardwareDeviceFirmware: null,
state: null,
status: 'ready',
});
Expand Down
1 change: 1 addition & 0 deletions test/tests/integration/adoption-code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions test/tests/integration/measurement/create-measurement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion test/tests/integration/probes/get-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions test/tests/unit/override/adopted-probes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('AdoptedProbes', () => {
version: '0.26.0',
nodeVersion: 'v18.17.0',
hardwareDevice: null,
hardwareDeviceFirmware: null,
country: 'IE',
state: null,
countryOfCustomCity: '',
Expand Down Expand Up @@ -56,6 +57,7 @@ describe('AdoptedProbes', () => {
},
isHardware: false,
hardwareDevice: null,
hardwareDeviceFirmware: null,
tags: [{
type: 'system',
value: 'datacenter-network',
Expand Down Expand Up @@ -299,6 +301,7 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.1',
isHardware: true,
hardwareDevice: 'v1',
hardwareDeviceFirmware: 'v2.2',
tags: [
{ type: 'system', value: 'eyeball-network' },
],
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -365,6 +369,7 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.0',
isHardware: false,
hardwareDevice: null,
hardwareDeviceFirmware: null,
tags: [
{ type: 'system', value: 'datacenter-network' },
],
Expand All @@ -391,6 +396,7 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.0',
isHardware: false,
hardwareDevice: null,
hardwareDeviceFirmware: null,
tags: [
{ type: 'system', value: 'datacenter-network' },
],
Expand Down Expand Up @@ -467,6 +473,7 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.0',
isHardware: false,
hardwareDevice: null,
hardwareDeviceFirmware: null,
tags: [
{ type: 'system', value: 'datacenter-network' },
],
Expand All @@ -493,6 +500,7 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.0',
isHardware: false,
hardwareDevice: null,
hardwareDeviceFirmware: null,
tags: [
{ type: 'system', value: 'datacenter-network' },
],
Expand Down Expand Up @@ -572,6 +580,7 @@ describe('AdoptedProbes', () => {
nodeVersion: 'v18.17.0',
isHardware: false,
hardwareDevice: null,
hardwareDeviceFirmware: null,
tags: [
{ type: 'system', value: 'datacenter-network' },
],
Expand Down
1 change: 1 addition & 0 deletions test/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit de8d0ef

Please sign in to comment.