From 9cf386d08b28bc45e5f48e3b16ab105149cbb485 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Sat, 14 Nov 2026 18:05:57 +0100 Subject: [PATCH] Count WebSocket upgrades as successful calls and tidy the report (refs #95) Trying the packaged release showed three things to fix: a 101 answer that opens a WebSocket was counted as a failure, the duration buckets were too coarse around the usual 200-500 ms of the brokers, and the report mixed CRLF and LF lines and named SQLite only by its version. Co-Authored-By: Claude Opus 5.5 --- src/Anubis.Server/DiagnosticsCommand.cs | 2 +- src/Anubis/Diagnostics/DiagnosticsReport.cs | 4 ++-- src/Anubis/Diagnostics/HttpCallMeter.cs | 5 +++-- tests/Anubis.Tests/DiagnosticsTests.cs | 6 ++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Anubis.Server/DiagnosticsCommand.cs b/src/Anubis.Server/DiagnosticsCommand.cs index 463b2a4..bcc93a2 100644 --- a/src/Anubis.Server/DiagnosticsCommand.cs +++ b/src/Anubis.Server/DiagnosticsCommand.cs @@ -49,7 +49,7 @@ internal static class DiagnosticsExport new("Piattaforma", config.Platform.ToString().ToLowerInvariant()), new("Database", config.Db?.Describe() ?? "non configurato"), new("Cartella dei dati", config.Data.Root), - new("Rete consentita", config.AllowNetwork ? "sì" : "no"), + new("Raggiungibile da altri computer", config.AllowNetwork ? "sì" : "no"), new("Ordini reali consentiti", config.AllowLive ? "sì" : "no"), }; var variables = environment diff --git a/src/Anubis/Diagnostics/DiagnosticsReport.cs b/src/Anubis/Diagnostics/DiagnosticsReport.cs index 8013abd..7dfedb0 100644 --- a/src/Anubis/Diagnostics/DiagnosticsReport.cs +++ b/src/Anubis/Diagnostics/DiagnosticsReport.cs @@ -55,7 +55,7 @@ public static partial class DiagnosticsReporter var data = await db.ReadAsync(async s => { (string Name, object? Value)[] window = [("from", request.From), ("to", request.To)]; - var engine = await s.FirstOrDefaultAsync(s.Engine == DbEngine.Sqlite ? "SELECT sqlite_version() AS v" : "SELECT version() AS v", r => r.Text("v")).ConfigureAwait(false); + var engine = await s.FirstOrDefaultAsync(s.Engine == DbEngine.Sqlite ? "SELECT 'SQLite ' || sqlite_version() AS v" : "SELECT version() AS v", r => r.Text("v")).ConfigureAwait(false); var samples = await s.QueryAsync("SELECT * FROM diagnostic_samples WHERE taken_at >= @from AND taken_at <= @to ORDER BY taken_at", ReadSample, window).ConfigureAwait(false); var runs = await s.QueryAsync("SELECT job, due_at, started_at, finished_at, outcome, missed, error FROM job_runs WHERE started_at >= @from AND started_at <= @to", r => new Run(r.Text("job"), r.Moment("due_at"), r.Moment("started_at"), r.Moment("finished_at"), r.Text("outcome"), r.Bool("missed"), r.TextOrNull("error")), window) @@ -96,7 +96,7 @@ public static partial class DiagnosticsReporter text.AppendLine().Append(section); } - return Fit(Mask(text.ToString())); + return Fit(Mask(text.ToString().ReplaceLineEndings("\n"))); } /// The user's folders and name out, the secrets out, and no more than . diff --git a/src/Anubis/Diagnostics/HttpCallMeter.cs b/src/Anubis/Diagnostics/HttpCallMeter.cs index e1df85a..0e2ac6a 100644 --- a/src/Anubis/Diagnostics/HttpCallMeter.cs +++ b/src/Anubis/Diagnostics/HttpCallMeter.cs @@ -10,7 +10,7 @@ namespace Anubis.Diagnostics; public sealed record HttpCallStats(string Host, long Calls, long Failures, IReadOnlyDictionary Outcomes, long[] Buckets, double MaxMs, double TotalMs) { /// Upper bounds in milliseconds of the duration buckets; one more bucket holds everything slower. - public static IReadOnlyList Bounds { get; } = [5, 10, 20, 50, 100, 200, 300, 500, 750, 1000, 1500, 2000, 3000, 5000, 10000, 20000, 30000, 60000]; + public static IReadOnlyList Bounds { get; } = [5, 10, 20, 30, 50, 75, 100, 150, 200, 250, 300, 400, 500, 750, 1000, 1500, 2000, 3000, 5000, 10000, 20000, 30000, 60000]; public double AverageMs => Calls == 0 ? 0 : TotalMs / Calls; @@ -152,7 +152,8 @@ public sealed class HttpCallMeter : IDisposable var key = (host ?? "?") + (port is { } p and not (80 or 443) ? ":" + p.ToString(CultureInfo.InvariantCulture) : ""); var outcome = status?.ToString(CultureInfo.InvariantCulture) ?? error ?? "?"; - var failed = status is not (>= 200 and < 400); + // 101 is the answer that opens a WebSocket: a success like 2xx and 3xx. + var failed = status is not (>= 100 and < 400); var milliseconds = Math.Max(0, seconds * 1000); lock (_gate) { diff --git a/tests/Anubis.Tests/DiagnosticsTests.cs b/tests/Anubis.Tests/DiagnosticsTests.cs index 9966787..56848ba 100644 --- a/tests/Anubis.Tests/DiagnosticsTests.cs +++ b/tests/Anubis.Tests/DiagnosticsTests.cs @@ -24,7 +24,7 @@ public sealed class DiagnosticsTests using var source = new Meter(HttpCallMeter.MeterName); var duration = source.CreateHistogram(HttpCallMeter.InstrumentName, "s"); const string host = "misura.invalid"; - foreach (var (seconds, status) in new[] { (0.04, 200), (0.08, 200), (0.4, 200), (2.5, 503) }) + foreach (var (seconds, status) in new[] { (0.04, 200), (0.08, 101), (0.4, 200), (2.5, 503) }) { duration.Record(seconds, new("server.address", host), new("server.port", 443), new("http.response.status_code", status)); } @@ -35,10 +35,12 @@ public sealed class DiagnosticsTests var main = calls[host]; Assert.AreEqual(4, main.Calls); Assert.AreEqual(1, main.Failures); - Assert.AreEqual(3, main.Outcomes["200"]); + Assert.AreEqual(2, main.Outcomes["200"]); + Assert.AreEqual(1, main.Outcomes["101"], "A WebSocket that opens is not a failure."); Assert.AreEqual(1, main.Outcomes["503"]); Assert.AreEqual(2500, main.MaxMs); Assert.AreEqual(100, main.Percentile(0.5), "The second fastest call is under the 100 ms bound."); + Assert.AreEqual(400, main.Percentile(0.75)); Assert.AreEqual(2500, main.Percentile(0.95), "Never more than the slowest call."); Assert.AreEqual(1, calls[host + ":8443"].Failures); Assert.AreEqual(1, calls[host + ":8443"].Outcomes["timeout"]);