From 70d246deee4461fad593e2a3cd8032d1a581b02e Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Tue, 4 Feb 2025 09:48:24 -0500 Subject: [PATCH] chore(ur): remove unused deprecated code paths --- servers/ur/src/config.js | 43 ++-------------------------- servers/ur/src/domain.js | 18 ++---------- servers/ur/src/domain.test.js | 54 ++--------------------------------- servers/ur/src/proxy.js | 4 +-- servers/ur/src/redirect.js | 4 +-- 5 files changed, 13 insertions(+), 110 deletions(-) diff --git a/servers/ur/src/config.js b/servers/ur/src/config.js index d654bc9a3..2ba81fdd8 100644 --- a/servers/ur/src/config.js +++ b/servers/ur/src/config.js @@ -40,20 +40,7 @@ const serverConfigSchema = z.object({ ), aoUnit: z.enum(['cu', 'mu']), strategy: z.enum(['proxy', 'redirect']), - surUrl: z.string().url(), - /** - * @deprecated - use ownerToHost or processToHost to - * achieve subrouting - */ - subrouterUrl: z.string().nullable().optional(), - /** - * @deprecated - use ownerToHost or processToHost to - * achieve subrouting - */ - owners: z.preprocess( - (arg) => (typeof arg === 'string' ? arg.split(',').map(str => str.trim()) : arg), - z.array(z.string()) - ).nullable().optional() + surUrl: z.string().url() }) /** @@ -70,7 +57,6 @@ const CONFIG_ENVS = { processToHost: process.env.PROCESS_TO_HOST || JSON.stringify({}), ownerToHost: process.env.OWNER_TO_HOST || JSON.stringify({}), fromModuleToHost: process.env.FROM_MODULE_TO_HOST || JSON.stringify({}), - /** * default to the CU for no hassle startup in development mode, * @@ -78,18 +64,7 @@ const CONFIG_ENVS = { */ aoUnit: process.env.AO_UNIT || 'cu', strategy: process.env.STRATEGY || 'proxy', - - surUrl: process.env.SUR_URL, - /** - * @deprecated - use ownerToHost or processToHost to - * achieve subrouting - */ - subrouterUrl: process.env.SUBROUTER_URL, - /** - * @deprecated - use ownerToHost or processToHost to - * achieve subrouting - */ - owners: process.env.OWNERS + surUrl: process.env.SUR_URL }, production: { MODE, @@ -98,21 +73,9 @@ const CONFIG_ENVS = { processToHost: process.env.PROCESS_TO_HOST || JSON.stringify({}), ownerToHost: process.env.OWNER_TO_HOST || JSON.stringify({}), fromModuleToHost: process.env.FROM_MODULE_TO_HOST || JSON.stringify({}), - aoUnit: process.env.AO_UNIT, strategy: process.env.STRATEGY || 'proxy', - - surUrl: process.env.SUR_URL, - /** - * @deprecated - use ownerToHost or processToHost to - * achieve subrouting - */ - subrouterUrl: process.env.SUBROUTER_URL, - /** - * @deprecated - use ownerToHost or processToHost to - * achieve subrouting - */ - owners: process.env.OWNERS + surUrl: process.env.SUR_URL } } diff --git a/servers/ur/src/domain.js b/servers/ur/src/domain.js index 3e3ccff86..c7251b3ab 100644 --- a/servers/ur/src/domain.js +++ b/servers/ur/src/domain.js @@ -3,7 +3,7 @@ import { LRUCache } from 'lru-cache' const isNotEmpty = complement(isEmpty) -export function bailoutWith ({ fetch, subrouterUrl, surUrl, owners, processToHost, ownerToHost, fromModuleToHost }) { +export function bailoutWith ({ fetch, surUrl, processToHost, ownerToHost, fromModuleToHost }) { const processToOwnerCache = new LRUCache({ /** * 10MB @@ -23,7 +23,7 @@ export function bailoutWith ({ fetch, subrouterUrl, surUrl, owners, processToHos /** * A number is 8 bytes */ - sizeCalculation: () => 8 + sizeCalculation: () => 8 }) async function findProcessOwner (processId) { @@ -78,25 +78,13 @@ export function bailoutWith ({ fetch, subrouterUrl, surUrl, owners, processToHos } /** - * If there are fromModule -> host configured, then we lookup the + * If there are fromModule -> host configured, then we lookup the * from-module and return the specific host if found */ if (fromModuleToHost && isNotEmpty(fromModuleToHost)) { const module = await findFromModule(processId) if (fromModuleToHost[module]) return fromModuleToHost[module] } - - /** - * @deprecated - this functionality is subsumed by ownerToHost - * and will eventually be removed - * - * All three of these must be set for the - * subrouter logic to work so if any are - * not set just return. - */ - if (!subrouterUrl || !surUrl || !owners) return - const owner = await findProcessOwner(processId) - if (owners.includes(owner)) return subrouterUrl } } diff --git a/servers/ur/src/domain.test.js b/servers/ur/src/domain.test.js index b614effa9..a1cdacb1d 100644 --- a/servers/ur/src/domain.test.js +++ b/servers/ur/src/domain.test.js @@ -42,7 +42,7 @@ describe('domain', () => { test('should bailout if the process fromModule is mapped to a specific host', async () => { const fetchMock = async (url) => { assert.equal(url, 'surUrl1/processes/process-123') - return new Response(JSON.stringify({ owner: { address: 'owner2' }, tags: [{name:'From-Module', value: 'fromModule1'}] })) + return new Response(JSON.stringify({ owner: { address: 'owner2' }, tags: [{ name: 'From-Module', value: 'fromModule1' }] })) } const bailout = bailoutWith({ @@ -60,7 +60,7 @@ describe('domain', () => { test('should NOT bailout if the process owner is not mapped to a specific host', async () => { const fetchMock = async (url) => { assert.equal(url, 'surUrl1/processes/process-123') - return new Response(JSON.stringify({ owner: { address: 'owner2' }, tags: [{name:'From-Module', value: 'fromModule1'}] })) + return new Response(JSON.stringify({ owner: { address: 'owner2' }, tags: [{ name: 'From-Module', value: 'fromModule1' }] })) } const bailout = bailoutWith({ @@ -79,7 +79,7 @@ describe('domain', () => { test('should NOT bailout if no fromModuleToHost is provided', async () => { const fetchMock = async (url) => { assert.equal(url, 'surUrl1/processes/process-123') - return new Response(JSON.stringify({ owner: { address: 'owner2' }, tags: [{name:'From-Module', value: 'fromModule1'}] })) + return new Response(JSON.stringify({ owner: { address: 'owner2' }, tags: [{ name: 'From-Module', value: 'fromModule1' }] })) } const determineHostEmptyMapping = determineHostWith({ @@ -173,54 +173,6 @@ describe('domain', () => { assert.ok(HOSTS.includes(host1)) }) }) - - /** - * @deprecated - this functionality is subsumed by ownerToHost - * and will eventually be removed, along with the tests - */ - describe('subRouter - DEPRECATED', () => { - test('should redirect to the subrouterUrl', async () => { - const fetchMock = async (url) => { - assert.equal(url, 'surUrl1/processes/process-123') - return new Response(JSON.stringify({ owner: { address: 'owner2' } })) - } - - const bailout = bailoutWith({ - fetch: fetchMock, - surUrl: 'surUrl1', - subrouterUrl: 'subrouterUrl1', - owners: ['owner1', 'owner2'] - }) - - const determineHost = determineHostWith({ hosts: HOSTS, bailout }) - - assert(await determineHost({ processId: 'process-123', failoverAttempt: 0 })) - assert.equal(await determineHost({ processId: 'process-123', failoverAttempt: 0 }), 'subrouterUrl1') - }) - - test('should not redirect to the subrouterUrl', async () => { - const fetchMock = async (url) => { - assert.equal(url, 'surUrl1/processes/process-123') - /** - * Here the owner does not match any in the list - * this will cause it to not redirect to the subrouter - */ - return new Response(JSON.stringify({ owner: { address: 'owner3' } })) - } - - const bailout = bailoutWith({ - fetch: fetchMock, - surUrl: 'surUrl1', - subrouterUrl: 'subrouterUrl1', - owners: ['owner1', 'owner2'] - }) - - const determineHost = determineHostWith({ hosts: HOSTS, bailout }) - - assert(await determineHost({ processId: 'process-123', failoverAttempt: 0 })) - assert.equal(await determineHost({ processId: 'process-123', failoverAttempt: 0 }), 'http://fizz.buzz') - }) - }) }) describe('computeHashSumFromProcessId', () => { diff --git a/servers/ur/src/proxy.js b/servers/ur/src/proxy.js index 1afb7b000..414c41d8d 100644 --- a/servers/ur/src/proxy.js +++ b/servers/ur/src/proxy.js @@ -14,13 +14,13 @@ import { logger } from './logger.js' import { mountRoutesWithByAoUnit } from './routes/byAoUnit.js' -export function proxyWith ({ aoUnit, hosts, subrouterUrl, surUrl, owners, processToHost, ownerToHost }) { +export function proxyWith ({ aoUnit, hosts, surUrl, processToHost, ownerToHost }) { const _logger = logger.child('proxy') _logger('Configuring to reverse proxy ao %s units...', aoUnit) const proxy = httpProxy.createProxyServer({}) - const bailout = aoUnit === 'cu' ? bailoutWith({ fetch, subrouterUrl, surUrl, owners, processToHost, ownerToHost }) : undefined + const bailout = aoUnit === 'cu' ? bailoutWith({ fetch, surUrl, processToHost, ownerToHost }) : undefined const determineHost = determineHostWith({ hosts, bailout }) async function trampoline (init) { diff --git a/servers/ur/src/redirect.js b/servers/ur/src/redirect.js index 90c877c51..dfba65500 100644 --- a/servers/ur/src/redirect.js +++ b/servers/ur/src/redirect.js @@ -6,11 +6,11 @@ import { logger } from './logger.js' import { mountRoutesWithByAoUnit } from './routes/byAoUnit.js' -export function redirectWith ({ aoUnit, hosts, subrouterUrl, surUrl, owners, processToHost, ownerToHost }) { +export function redirectWith ({ aoUnit, hosts, surUrl, processToHost, ownerToHost }) { const _logger = logger.child('redirect') _logger('Configuring to redirect ao %s units...', aoUnit) - const bailout = aoUnit === 'cu' ? bailoutWith({ fetch, subrouterUrl, surUrl, owners, processToHost, ownerToHost }) : undefined + const bailout = aoUnit === 'cu' ? bailoutWith({ fetch, surUrl, processToHost, ownerToHost }) : undefined const determineHost = determineHostWith({ hosts, bailout }) /**