Skip to content

Commit

Permalink
chore(ur): remove unused deprecated code paths
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Feb 4, 2025
1 parent 398d483 commit 70d246d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 110 deletions.
43 changes: 3 additions & 40 deletions servers/ur/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

/**
Expand All @@ -70,26 +57,14 @@ 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,
*
* but should consider setting explicitly in your .env
*/
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,
Expand All @@ -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
}
}

Expand Down
18 changes: 3 additions & 15 deletions servers/ur/src/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
}

Expand Down
54 changes: 3 additions & 51 deletions servers/ur/src/domain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand Down Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions servers/ur/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions servers/ur/src/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

/**
Expand Down

0 comments on commit 70d246d

Please sign in to comment.