Files
Chronos/src/Chronos.Protocol/Admin.cs
T
Alby96 422f33d5f3 fix(server): show the audit clean-up's real age limit and lock it before the first pass
Settings › Logs › Keep audit showed ServerOptions.AuditRetentionDays, a second
copy of the audit clean-up schedule's age limit. Edits made on Jobs › Scheduled
never reached it, so the panel could say "kept forever" while entries were
being deleted every night. Saving 0 there then changed nothing, because the
endpoint only compared against the stale option value.

- GET and PUT /server/settings now report the schedule's limit in force (0
  while the schedule is off). Saving compares against that value. A value sent
  back unchanged leaves the server.json reset default and the env lock alone. A
  new value sets the schedule and becomes the reset default.
- ApplyAgeAsync also turns the schedule on when it already holds the days but
  is off.
- CHRONOS_AUDIT_RETENTION_DAYS is now applied before the scheduler's first
  pass, through a new Scheduler.StartAsync overload with a beforeFirstPass hook.
  Before, a missed 04:30 run was caught up at start with the stale days, which
  could delete entries the variable says to keep. While the variable fixes a
  limit above 0, turning the schedule off is a 409 setting_locked.
- Corrected the comments in SchedulerHost, ServerOptions, ServerSettingsStore,
  LogSettingsDto, the header of settings.js and ARCHITECTURE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 490ed286e9f32745174b13b1963d6ec91955196b)
2026-10-27 09:56:46 +01:00

93 lines
4.2 KiB
C#

namespace Chronos.Protocol;
/// <summary>
/// <c>GET/PUT /api/v1/server/settings</c> (admin): the editable part of the server configuration. Settings named in
/// <see cref="Locked"/> come from environment variables and cannot be changed here; <see cref="LockedBy"/> names the
/// variable that fixes each of them (ignored when saving); <see cref="RestartRequired"/> says
/// that saved values (ports, TLS, chunk size) wait for a restart; <see cref="JobHistoryDays"/> is what the housekeeping
/// schedule is reset to (owner review 2, R10). <see cref="ProxyWarning"/> is set in responses when TLS mode is proxy and
/// the request did not come through a trusted proxy over HTTPS (ignored when saving).
/// <see cref="Parallelism"/> is how many photos the running job processes at once (jobs run one at a time), and
/// <see cref="PriorityQueue"/> with <see cref="JobPriorities"/> the priority queue (owner review 1); both apply at once, as
/// do <see cref="Logs"/> (owner review 2, R11; a request without them keeps them as they are).
/// </summary>
public sealed record ServerSettingsDto(
string ServerName,
int HttpPort,
int HttpsPort,
string TlsMode,
string? TlsCert,
string? TlsKey,
string Language,
int Parallelism,
bool PriorityQueue,
IReadOnlyList<JobPriorityDto> JobPriorities,
bool Discovery,
long MaxUploadBytes,
int ChunkSizeBytes,
int JobHistoryDays,
int TokenLifetimeDays,
int UploadRetentionHours,
LogSettingsDto Logs,
IReadOnlyList<string> Locked,
IReadOnlyDictionary<string, string> LockedBy,
bool RestartRequired,
bool ProxyWarning);
/// <summary>
/// The log settings of <see cref="ServerSettingsDto"/> (owner review 2, R11): the least severe level of the files and of the
/// console (<c>trace</c>, <c>debug</c>, <c>information</c>, <c>warning</c>, <c>error</c>, <c>critical</c>, <c>none</c>), the
/// days log files are kept, the size at which a file continues in a numbered one and the size of all of them (MB of 2²⁰
/// bytes, 0 = no limit), the rotation (<c>daily</c> or <c>hourly</c>, UTC), the days audit entries are kept (the audit
/// clean-up schedule's age limit; 0 = forever, as while that schedule is off) and the MB of the end of each log file in
/// the diagnostics zip. Their locks use the server.json names (<c>LogLevel</c>, <c>ConsoleLogLevel</c>,
/// <c>LogRetentionDays</c>, <c>LogMaxFileMb</c>, <c>LogMaxTotalMb</c>, <c>LogRotation</c>, <c>AuditRetentionDays</c>,
/// <c>DiagnosticsLogMb</c>).
/// </summary>
public sealed record LogSettingsDto(
string FileLevel,
string ConsoleLevel,
int RetentionDays,
int MaxFileMb,
int MaxTotalMb,
string Rotation,
int AuditRetentionDays,
int DiagnosticsLogMb);
/// <summary>A kind of job (<c>render</c>) and its level in the server's priority queue: <c>high</c>, <c>normal</c> or <c>low</c>.</summary>
public sealed record JobPriorityDto(string Kind, string Level);
/// <summary>A server log file (<c>GET /api/v1/logs/files</c>).</summary>
public sealed record LogFileDto(string Name, long Size, DateTimeOffset Modified);
/// <summary>The last lines of the current server log (<c>GET /api/v1/logs</c>).</summary>
public sealed record LogTailDto(string File, IReadOnlyList<string> Lines);
/// <summary>Jobs per state; done and failed count today's (UTC) jobs.</summary>
public sealed record JobCountsDto(int Queued, int Running, int Paused, int DoneToday, int FailedToday);
/// <summary>Frames committed by uploads on one UTC day.</summary>
public sealed record UploadDayDto(DateOnly Day, long Frames, long Bytes);
/// <summary>
/// <c>GET /api/v1/server/dashboard</c> (admin): everything the dashboard page shows in one call (BRIEF §14.8).
/// <see cref="ProxyWarning"/>: TLS mode is proxy and this request did not come through a trusted proxy over HTTPS.
/// </summary>
public sealed record DashboardDto(
string ServerName,
string Version,
long UptimeSeconds,
string Database,
string TlsMode,
bool Discovery,
int Users,
ArchiveStatsDto Archive,
JobCountsDto Jobs,
int Parallelism,
bool PriorityQueue,
IReadOnlyList<RenderNodeDto> Nodes,
IReadOnlyList<UploadDayDto> Uploads,
IReadOnlyList<AuditEntryDto> Activity,
IReadOnlyList<JobDto> ActiveJobs,
bool ProxyWarning);