Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dvm-settings-restart-required.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nostream": patch
---

The admin settings API now reports a change to `dvm` settings as restart-required instead of hot-reload. Each DVM orchestrator is started for one entry of `dvm.workers` and keeps the configuration it started with, so a narrowed `kinds` list, a removed worker or a new command was reported as applied while the running orchestrator went on dispatching jobs under the old policy. The default settings file now says the same.
2 changes: 2 additions & 0 deletions resources/default-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ eventStore:
# Only postgres for now. Changing it needs a restart.
backend: postgres
dvm:
# One orchestrator starts for each worker and keeps the configuration it started with, so a change here needs a
# restart.
workers: []
limits:
# Every `period` below is a count of milliseconds, and `rate` is how many hits
Expand Down
20 changes: 18 additions & 2 deletions src/controllers/admin/patch-settings-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,24 @@ export class PatchAdminSettingsController implements IController {
}
}

const getSettingsReloadBehavior = (path: string): 'hot-reload' | 'restart-required' => {
if (path.startsWith('workers.') || path.startsWith('payments') || path.startsWith('network.')) {
const getSettingsReloadBehavior = (rawPath: string): 'hot-reload' | 'restart-required' => {
// The settings writer trims the path and each of its segments (`' dvm '` names `dvm`), so the path is classified in
// that form.
const path = rawPath
.trim()
.split('.')
.map((segment) => segment.trim())
.join('.')

// A DVM orchestrator is started for each of dvm.workers and keeps the configuration it started with, so a change to
// its kinds, command or timeout, or to the list of workers, takes effect at the next start only.
if (
path.startsWith('workers.') ||
path.startsWith('payments') ||
path.startsWith('network.') ||
path === 'dvm' ||
path.startsWith('dvm.')
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
) {
return 'restart-required'
}

Expand Down
37 changes: 37 additions & 0 deletions test/unit/routes/admin-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,43 @@ describe('admin settings API', () => {
expect(settingsRaw).to.include('enabled: true')
})

describe('which settings need a restart', () => {
const patchSetting = async (path: string, value: unknown) => {
const passwordHash = hashAdminPassword('settings-password')
const baseUrl = await startServer({
admin: { enabled: true, passwordHash, sessionTtlSeconds: 3600 },
})
const cookie = await login(baseUrl)

return axios.patch(
`${baseUrl}/settings`,
{ path, value },
{ headers: { cookie, 'content-type': 'application/json' }, validateStatus: () => true },
)
}

it('reports a change to the DVM workers as restart-required, since each keeps the configuration it started with', async () => {
const response = await patchSetting('dvm.workers', [{ command: 'node', kinds: [5300] }])

expect(response.status).to.equal(200)
expect(response.data.reload).to.equal('restart-required')
})

it('classifies a path written with spaces the way the settings writer reads it', async () => {
const response = await patchSetting(' dvm . workers ', [{ command: 'node', kinds: [5300] }])

expect(response.status).to.equal(200)
expect(response.data.reload).to.equal('restart-required')
})

it('still reports a setting read on every use as hot-reload', async () => {
const response = await patchSetting('info.name', 'Another relay')

expect(response.status).to.equal(200)
expect(response.data.reload).to.equal('hot-reload')
})
})

describe('the admin password hash', () => {
const otherHash = () => hashAdminPassword('another-password')

Expand Down
Loading