fix: unify diagnostics history access
Resolve diagnostic history through the injected loadHistory dependency whenever it is available, retaining config history only for legacy collectors without a dedicated reader. Build server_health error and batch summaries from one validated snapshot so migrated installations cannot combine current batches with stale errors or parse the external history twice. Add focused regressions for migrated history consistency and fail-closed handling of invalid dedicated history results.
This commit is contained in:
@@ -19,6 +19,15 @@ function createCollectors(deps) {
|
||||
try { return support.collectSecretValues(loadConfig()); } catch { return []; }
|
||||
}
|
||||
|
||||
function _currentHistory() {
|
||||
if (typeof loadHistory === 'function') {
|
||||
const history = loadHistory();
|
||||
return Array.isArray(history) ? history : [];
|
||||
}
|
||||
const cfg = loadConfig();
|
||||
return Array.isArray(cfg && cfg.history) ? cfg.history : [];
|
||||
}
|
||||
|
||||
function _deepRedact(value, secrets) {
|
||||
return support.valueScrub(value, secrets || _secrets());
|
||||
}
|
||||
@@ -162,15 +171,18 @@ function createCollectors(deps) {
|
||||
return { errors, byCategory };
|
||||
}
|
||||
|
||||
function listErrors(args) {
|
||||
function _listErrors(args, history) {
|
||||
const a = args || {};
|
||||
const cfg = loadConfig();
|
||||
const { errors, byCategory } = _historyErrors(cfg.history, a);
|
||||
const { errors, byCategory } = _historyErrors(history, a);
|
||||
const limit = Math.min(Math.max(Number(a.limit) || 100, 1), 1000);
|
||||
const window = Number.isFinite(a.sinceMs) ? `since ${new Date(a.sinceMs).toISOString()}` : 'all history';
|
||||
return { window, total: errors.length, byCategory, errors: errors.slice(-limit) };
|
||||
}
|
||||
|
||||
function listErrors(args) {
|
||||
return _listErrors(args, _currentHistory());
|
||||
}
|
||||
|
||||
function getQueueState(args) {
|
||||
const a = args || {};
|
||||
const cfg = loadConfig();
|
||||
@@ -200,11 +212,8 @@ function createCollectors(deps) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function getHistory(args) {
|
||||
function _getHistory(args, history) {
|
||||
const a = args || {};
|
||||
const history = typeof loadHistory === 'function'
|
||||
? (loadHistory() || [])
|
||||
: (Array.isArray(loadConfig().history) ? loadConfig().history : []);
|
||||
const limit = Math.min(Math.max(Number(a.limit) || 20, 1), 200);
|
||||
const perHoster = stats.summarizePerHoster(history);
|
||||
const recent = [...history].slice(-limit).reverse();
|
||||
@@ -227,6 +236,10 @@ function createCollectors(deps) {
|
||||
return { totalBatches: history.length, returned: batches.length, perHoster, batches };
|
||||
}
|
||||
|
||||
function getHistory(args) {
|
||||
return _getHistory(args, _currentHistory());
|
||||
}
|
||||
|
||||
function getRotationState() {
|
||||
const cfg = loadConfig();
|
||||
return { rotationCursors: _deepRedact(cfg.rotationCursors || {}) };
|
||||
@@ -246,9 +259,10 @@ function createCollectors(deps) {
|
||||
const a = args || {};
|
||||
const errorLimit = Math.min(Math.max(Number(a.errorLimit) || 20, 1), 200);
|
||||
const errArgs = Number.isFinite(a.errorSinceMs) ? { sinceMs: a.errorSinceMs, limit: errorLimit } : { limit: errorLimit };
|
||||
const errors = listErrors(errArgs);
|
||||
const currentHistory = _currentHistory();
|
||||
const errors = _listErrors(errArgs, currentHistory);
|
||||
const queue = getQueueState({ includeJobs: false });
|
||||
const history = getHistory({ limit: 5 });
|
||||
const history = _getHistory({ limit: 5 }, currentHistory);
|
||||
const warnings = [];
|
||||
if (queue.source === 'persisted' && queue.stale) warnings.push('queue state is from the persisted snapshot (may lag live state; UploadManager not introspected in this build).');
|
||||
if (errors.total > 0) warnings.push(`${errors.total} non-success result(s) in the error window.`);
|
||||
|
||||
Reference in New Issue
Block a user