Print the PostgreSQL service log at the end of the CI job (refs #98)
ci / test (postgres) (push) Successful in 8m16s
ci / test (sqlite) (push) Successful in 5m16s
ci / test (postgres) (pull_request) Successful in 11m38s
ci / test (sqlite) (pull_request) Successful in 4m58s
ci / image (push) Successful in 1m42s
ci / image (pull_request) Successful in 47s
ci / test (postgres) (push) Successful in 8m16s
ci / test (sqlite) (push) Successful in 5m16s
ci / test (postgres) (pull_request) Successful in 11m38s
ci / test (sqlite) (pull_request) Successful in 4m58s
ci / image (push) Successful in 1m42s
ci / image (pull_request) Successful in 47s
The job log shows the tests losing every connection but not why the server went into recovery. A new tasks command reads the service container's log, state and memory through the Docker socket the runner mounts in the job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
25e71b679f
commit
0a9a8a38ec
3 files changed
+132
No files matched your search
@@ -45,6 +45,10 @@ jobs:
|
||||
git checkout -q FETCH_HEAD
|
||||
- name: Check
|
||||
run: sh ./tasks.sh check
|
||||
# The log of the PostgreSQL service, read through the Docker socket the runner mounts in the job (issue #98).
|
||||
- name: PostgreSQL log
|
||||
if: always() && matrix.db == 'postgres'
|
||||
run: sh ./tasks.sh ci-service-log postgres
|
||||
|
||||
image:
|
||||
needs: test
|
||||
|
||||
@@ -19,6 +19,7 @@ return command switch
|
||||
"seed-demo" => Run("dotnet", ["run", "--project", "src/Anubis.Server", "-c", "Release", "--", "--demo", .. rest]),
|
||||
"screenshots" => Screenshots(rest),
|
||||
"release-win" => ReleaseWindows(),
|
||||
"ci-service-log" => ServiceLog.Print(rest.Length > 0 ? rest[0] : "postgres"),
|
||||
"desktop-win" => NotYet("desktop-win", 10),
|
||||
_ => Help(),
|
||||
};
|
||||
@@ -237,6 +238,7 @@ int Help()
|
||||
tasks seed-demo avvia la modalità dimostrativa (dati dell'appendice F, database a parte)
|
||||
tasks screenshots fotografa le schermate dimostrative a 1440 e 390 pixel
|
||||
tasks release-win zip di prova per Windows in artifacts/release (ADR 0013)
|
||||
tasks ci-service-log nella CI: registro e memoria del PostgreSQL dei test
|
||||
tasks desktop-win installatore Windows (Fase 10)
|
||||
""");
|
||||
return command == "help" ? 0 : 1;
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
using System.Globalization;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
/// <summary>
|
||||
/// Prints what the CI cannot see from inside the job: the log, state and memory of the service containers next to this
|
||||
/// one (the PostgreSQL of the tests). It talks to the Docker Engine API through the socket the runner mounts in the job
|
||||
/// container, so it needs neither the docker client nor anything else to install (ADR 0004).
|
||||
/// </summary>
|
||||
internal static class ServiceLog
|
||||
{
|
||||
private const string Socket = "/var/run/docker.sock";
|
||||
|
||||
public static int Print(string imagePrefix)
|
||||
{
|
||||
if (!File.Exists(Socket))
|
||||
{
|
||||
Console.WriteLine($"Nessun {Socket}: il registro dei servizi si legge solo nella CI.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
using var http = new HttpClient(new SocketsHttpHandler
|
||||
{
|
||||
ConnectCallback = async (_, token) =>
|
||||
{
|
||||
var socket = new System.Net.Sockets.Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
|
||||
await socket.ConnectAsync(new UnixDomainSocketEndPoint(Socket), token).ConfigureAwait(false);
|
||||
return new NetworkStream(socket, ownsSocket: true);
|
||||
},
|
||||
})
|
||||
{
|
||||
BaseAddress = new Uri("http://docker/"),
|
||||
Timeout = TimeSpan.FromMinutes(2),
|
||||
};
|
||||
|
||||
var info = Json(http, "info");
|
||||
Console.WriteLine($"Host: {info["Name"]}, {info["NCPU"]} CPU, {Mib(info["MemTotal"])} di memoria, kernel {info["KernelVersion"]}");
|
||||
|
||||
var self = Json(http, $"containers/{Uri.EscapeDataString(Environment.MachineName)}/json");
|
||||
var networks = self["NetworkSettings"]?["Networks"]?.AsObject().Select(pair => pair.Key).ToList() ?? [];
|
||||
var found = 0;
|
||||
foreach (var network in networks)
|
||||
{
|
||||
var filter = Uri.EscapeDataString($$"""{"network":["{{network}}"]}""");
|
||||
foreach (var container in Json(http, $"containers/json?all=1&filters={filter}").AsArray())
|
||||
{
|
||||
var image = container?["Image"]?.GetValue<string>() ?? "";
|
||||
if (!image.StartsWith(imagePrefix, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
found++;
|
||||
var id = container!["Id"]!.GetValue<string>();
|
||||
Describe(http, id, image);
|
||||
}
|
||||
}
|
||||
|
||||
if (found == 0)
|
||||
{
|
||||
Console.WriteLine($"Nessun contenitore '{imagePrefix}*' sulle reti {string.Join(", ", networks)}.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void Describe(HttpClient http, string id, string image)
|
||||
{
|
||||
var inspect = Json(http, $"containers/{id}/json");
|
||||
var state = inspect["State"];
|
||||
var host = inspect["HostConfig"];
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"== {image} {id[..12]}");
|
||||
Console.WriteLine($"Stato: {state?["Status"]}, avviato {state?["StartedAt"]}, riavvii {inspect["RestartCount"]}, OOMKilled {state?["OOMKilled"]}, uscita {state?["ExitCode"]}");
|
||||
Console.WriteLine($"Limiti: memoria {Mib(host?["Memory"])}, /dev/shm {Mib(host?["ShmSize"])}");
|
||||
|
||||
if (state?["Running"]?.GetValue<bool>() == true)
|
||||
{
|
||||
var stats = Json(http, $"containers/{id}/stats?stream=false");
|
||||
var memory = stats["memory_stats"];
|
||||
Console.WriteLine($"Memoria ora: {Mib(memory?["usage"])}, limite visto dal contenitore {Mib(memory?["limit"])}, massimo {Mib(memory?["max_usage"])}");
|
||||
}
|
||||
|
||||
Console.WriteLine("-- registro");
|
||||
using var response = http.GetAsync(new Uri($"containers/{id}/logs?stdout=1&stderr=1×tamps=1", UriKind.Relative)).GetAwaiter().GetResult();
|
||||
response.EnsureSuccessStatusCode();
|
||||
var bytes = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();
|
||||
var raw = response.Content.Headers.ContentType?.MediaType == "application/vnd.docker.raw-stream";
|
||||
Console.Write(raw ? Encoding.UTF8.GetString(bytes) : Demultiplex(bytes));
|
||||
Console.WriteLine("-- fine del registro");
|
||||
}
|
||||
|
||||
// Without a terminal the log arrives in frames: one byte for the stream, three zeros, four bytes of length.
|
||||
private static string Demultiplex(byte[] bytes)
|
||||
{
|
||||
var text = new StringBuilder();
|
||||
var at = 0;
|
||||
while (at + 8 <= bytes.Length)
|
||||
{
|
||||
var length = (bytes[at + 4] << 24) | (bytes[at + 5] << 16) | (bytes[at + 6] << 8) | bytes[at + 7];
|
||||
var size = Math.Min(length, bytes.Length - at - 8);
|
||||
text.Append(Encoding.UTF8.GetString(bytes, at + 8, size));
|
||||
at += 8 + length;
|
||||
}
|
||||
|
||||
return text.ToString();
|
||||
}
|
||||
|
||||
private static JsonNode Json(HttpClient http, string path)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(path, UriKind.Relative));
|
||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
using var response = http.Send(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
using var stream = response.Content.ReadAsStream();
|
||||
return JsonNode.Parse(stream) ?? new JsonObject();
|
||||
}
|
||||
|
||||
private static string Mib(JsonNode? bytes)
|
||||
{
|
||||
var value = bytes?.GetValue<long>() ?? 0;
|
||||
return value == 0 ? "nessuno" : (value / 1048576.0).ToString("0", CultureInfo.InvariantCulture) + " MiB";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user