Committed by Hermes autonomous QA sprint 2026-08-13. These files were modified during the Aug 12 sprint but never committed.
65 lines
2.8 KiB
JavaScript
65 lines
2.8 KiB
JavaScript
const express = require('express');
|
|
const { success, error: errorResponse } = require('../src/utils/responses');
|
|
|
|
/**
|
|
* Disk space management routes
|
|
*
|
|
* GET /disk — current usage snapshot (budget, breakdown, status)
|
|
* GET /disk/breakdown — detailed breakdown incl. per-container log sizes
|
|
* GET /disk/config — get disk budget settings
|
|
* POST /disk/config — update disk budget settings
|
|
* POST /disk/cleanup — trigger manual cleanup (standard|aggressive|logs-only)
|
|
*/
|
|
module.exports = function({ diskSpaceMonitor, asyncHandler, log }) {
|
|
const router = express.Router();
|
|
|
|
// Current disk usage snapshot
|
|
router.get('/', asyncHandler(async (req, res) => {
|
|
const snapshot = await diskSpaceMonitor.getSnapshot();
|
|
success(res, snapshot);
|
|
}, 'disk-get'));
|
|
|
|
// Detailed breakdown (includes per-container log sizes)
|
|
router.get('/breakdown', asyncHandler(async (req, res) => {
|
|
const breakdown = await diskSpaceMonitor.getDetailedBreakdown();
|
|
success(res, breakdown);
|
|
}, 'disk-breakdown'));
|
|
|
|
// Get disk budget config
|
|
router.get('/config', asyncHandler(async (req, res) => {
|
|
success(res, diskSpaceMonitor.getConfig());
|
|
}, 'disk-config-get'));
|
|
|
|
// Update disk budget config
|
|
router.post('/config', asyncHandler(async (req, res) => {
|
|
const { diskBudgetGB, warningThresholdPct, criticalThresholdPct, autoCleanup, enabled, cleanupAggressivePct } = req.body;
|
|
|
|
const updates = {};
|
|
if (typeof diskBudgetGB === 'number' && diskBudgetGB > 0) updates.diskBudgetGB = Math.min(diskBudgetGB, 1000);
|
|
if (typeof warningThresholdPct === 'number') updates.warningThresholdPct = Math.min(Math.max(warningThresholdPct, 50), 99);
|
|
if (typeof criticalThresholdPct === 'number') updates.criticalThresholdPct = Math.min(Math.max(criticalThresholdPct, 60), 99);
|
|
if (typeof cleanupAggressivePct === 'number') updates.cleanupAggressivePct = Math.min(Math.max(cleanupAggressivePct, 70), 99);
|
|
if (typeof autoCleanup === 'boolean') updates.autoCleanup = autoCleanup;
|
|
if (typeof enabled === 'boolean') updates.enabled = enabled;
|
|
|
|
const config = diskSpaceMonitor.configure(updates);
|
|
log.info('disk', 'Disk budget updated', updates);
|
|
|
|
success(res, { message: 'Disk budget updated', config });
|
|
}, 'disk-config-set'));
|
|
|
|
// Manual cleanup trigger
|
|
router.post('/cleanup', asyncHandler(async (req, res) => {
|
|
const level = req.body?.level || 'standard';
|
|
if (!['standard', 'aggressive', 'logs-only'].includes(level)) {
|
|
return errorResponse(res, 'Invalid cleanup level. Use: standard, aggressive, or logs-only', 400);
|
|
}
|
|
|
|
log.info('disk', 'Manual cleanup triggered', { level, by: req.auth?.user || 'api' });
|
|
const result = await diskSpaceMonitor.performCleanup(level);
|
|
success(res, result);
|
|
}, 'disk-cleanup'));
|
|
|
|
return router;
|
|
};
|