diff --git a/.changeset/dvm-settings-restart-required.md b/.changeset/dvm-settings-restart-required.md new file mode 100644 index 000000000..703303223 --- /dev/null +++ b/.changeset/dvm-settings-restart-required.md @@ -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. diff --git a/resources/default-settings.yaml b/resources/default-settings.yaml index a54965632..20484cf51 100755 --- a/resources/default-settings.yaml +++ b/resources/default-settings.yaml @@ -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 diff --git a/src/controllers/admin/patch-settings-controller.ts b/src/controllers/admin/patch-settings-controller.ts index d01dc9c99..6b7a9a87b 100644 --- a/src/controllers/admin/patch-settings-controller.ts +++ b/src/controllers/admin/patch-settings-controller.ts @@ -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.') + ) { return 'restart-required' } diff --git a/test/unit/routes/admin-settings.spec.ts b/test/unit/routes/admin-settings.spec.ts index c2e61d7e0..3e26088a5 100644 --- a/test/unit/routes/admin-settings.spec.ts +++ b/test/unit/routes/admin-settings.spec.ts @@ -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')