Skip to content

Commit 2f74d8e

Browse files
committed
feat(API): report non-default task intervals in diagnostics
Add cadt.nonDefaultTaskIntervals to /diagnostics, listing each APP.TASKS interval that differs from defaultConfig with default and actual values in seconds.
1 parent 87588db commit 2f74d8e

3 files changed

Lines changed: 102 additions & 0 deletions

File tree

src/routes/diagnostics.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import _ from 'lodash';
1515

1616
import { getConfig, getConfigV2 } from '../utils/config-loader.js';
17+
import { defaultConfig } from '../utils/defaultConfig.js';
1718
import { getChiaRoot } from '../utils/chia-root.js';
1819
import { getWalletHealthResponse } from './wallet-health.js';
1920
import { getSystemInfo } from '../utils/system-info.js';
@@ -340,6 +341,32 @@ const normalizeNodeId = (id) => {
340341
return s.startsWith('0x') ? s.slice(2) : s;
341342
};
342343

344+
/** Task interval keys shipped in defaultConfig.APP.TASKS. */
345+
const TASK_INTERVAL_KEYS = Object.freeze([
346+
'GOVERNANCE_SYNC_TASK_INTERVAL',
347+
'ORGANIZATION_META_SYNC_TASK_INTERVAL',
348+
'PICKLIST_SYNC_TASK_INTERVAL',
349+
'MIRROR_CHECK_TASK_INTERVAL',
350+
'VALIDATE_ORGANIZATION_TABLE_TASK_INTERVAL',
351+
'COIN_MANAGEMENT_TASK_INTERVAL',
352+
]);
353+
354+
/**
355+
* Compare effective APP.TASKS intervals against defaultConfig. Returns only
356+
* entries whose actual value differs from the shipped default, each with
357+
* { key, default, actual } in seconds.
358+
*/
359+
const collectNonDefaultTaskIntervals = (actualTasks, defaultTasks = defaultConfig.APP.TASKS) => {
360+
const nonDefault = [];
361+
for (const key of TASK_INTERVAL_KEYS) {
362+
const defaultValue = defaultTasks?.[key];
363+
const actualValue = actualTasks?.[key];
364+
if (actualValue === undefined || actualValue === defaultValue) continue;
365+
nonDefault.push({ key, default: defaultValue, actual: actualValue });
366+
}
367+
return nonDefault;
368+
};
369+
343370
/**
344371
* Cross-reference connected wallet peers against the trusted_peers map in
345372
* the chia config.yaml. Returns a small object suitable for embedding in
@@ -573,6 +600,7 @@ export const getDiagnosticsResponse = async () => {
573600
governanceBodyId: configV2.GOVERNANCE?.GOVERNANCE_BODY_ID || null,
574601
homeOrgId: homeOrgUid(v2HomeOrg),
575602
},
603+
nonDefaultTaskIntervals: collectNonDefaultTaskIntervals(appConfig.TASKS),
576604
};
577605

578606
// ---- Chia: network match ------------------------------------------------
@@ -881,6 +909,8 @@ export const __test = {
881909
buildTrustedPeerView,
882910
normalizeNodeId,
883911
collectOwnedStoreExpectations,
912+
collectNonDefaultTaskIntervals,
884913
escalateLostOwnedStores,
885914
StatusAccumulator,
915+
TASK_INTERVAL_KEYS,
886916
};

tests/v2/integration/diagnostics-helpers.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,51 @@ describe('collectOwnedStoreExpectations', function () {
578578
expect(result.expectedOwnedStores.map((e) => e.label)).to.deep.equal(['v1 registry']);
579579
});
580580
});
581+
582+
describe('diagnostics collectNonDefaultTaskIntervals', function () {
583+
const { collectNonDefaultTaskIntervals } = diagnosticsTest;
584+
585+
const defaultTasks = {
586+
GOVERNANCE_SYNC_TASK_INTERVAL: 120,
587+
ORGANIZATION_META_SYNC_TASK_INTERVAL: 120,
588+
PICKLIST_SYNC_TASK_INTERVAL: 120,
589+
MIRROR_CHECK_TASK_INTERVAL: 900,
590+
VALIDATE_ORGANIZATION_TABLE_TASK_INTERVAL: 1800,
591+
COIN_MANAGEMENT_TASK_INTERVAL: 21600,
592+
};
593+
594+
it('returns an empty array when all intervals match defaults', function () {
595+
expect(collectNonDefaultTaskIntervals(defaultTasks, defaultTasks)).to.deep.equal([]);
596+
});
597+
598+
it('reports only intervals that differ from defaults', function () {
599+
const actual = {
600+
...defaultTasks,
601+
GOVERNANCE_SYNC_TASK_INTERVAL: 30,
602+
MIRROR_CHECK_TASK_INTERVAL: 900,
603+
};
604+
expect(collectNonDefaultTaskIntervals(actual, defaultTasks)).to.deep.equal([
605+
{ key: 'GOVERNANCE_SYNC_TASK_INTERVAL', default: 120, actual: 30 },
606+
]);
607+
});
608+
609+
it('reports multiple non-default intervals', function () {
610+
const actual = {
611+
...defaultTasks,
612+
PICKLIST_SYNC_TASK_INTERVAL: 60,
613+
COIN_MANAGEMENT_TASK_INTERVAL: 3600,
614+
};
615+
expect(collectNonDefaultTaskIntervals(actual, defaultTasks)).to.deep.equal([
616+
{ key: 'PICKLIST_SYNC_TASK_INTERVAL', default: 120, actual: 60 },
617+
{ key: 'COIN_MANAGEMENT_TASK_INTERVAL', default: 21600, actual: 3600 },
618+
]);
619+
});
620+
621+
it('ignores unknown task keys and missing actual values', function () {
622+
const actual = {
623+
GOVERNANCE_SYNC_TASK_INTERVAL: 120,
624+
DEFAULT_ORGANIZATIONS_SYNC_TASK_INTERVAL: 30,
625+
};
626+
expect(collectNonDefaultTaskIntervals(actual, defaultTasks)).to.deep.equal([]);
627+
});
628+
});

tests/v2/integration/diagnostics.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,30 @@ describe('/diagnostics endpoint', function () {
3434
expect(cadt).to.have.property('v2').that.is.an('object');
3535
expect(cadt.v1).to.have.property('governanceBodyId');
3636
expect(cadt.v2).to.have.property('governanceBodyId');
37+
expect(cadt).to.have.property('nonDefaultTaskIntervals').that.is.an('array');
38+
});
39+
40+
it('reports non-default task intervals with default and actual values', async function () {
41+
await withConfigOverride(async () => {
42+
const response = await supertest(app).get('/diagnostics').expect(200);
43+
expect(response.body.cadt.nonDefaultTaskIntervals).to.deep.include({
44+
key: 'GOVERNANCE_SYNC_TASK_INTERVAL',
45+
default: 120,
46+
actual: 30,
47+
});
48+
expect(response.body.cadt.nonDefaultTaskIntervals).to.deep.include({
49+
key: 'MIRROR_CHECK_TASK_INTERVAL',
50+
default: 900,
51+
actual: 86460,
52+
});
53+
}, {
54+
APP: {
55+
TASKS: {
56+
GOVERNANCE_SYNC_TASK_INTERVAL: 30,
57+
MIRROR_CHECK_TASK_INTERVAL: 86460,
58+
},
59+
},
60+
});
3761
});
3862

3963
it('reports CPU, memory, and disk in the system section', async function () {

0 commit comments

Comments
 (0)