Use authoritative Docker OOM evidence

This commit is contained in:
rcourtman 2026-07-15 17:55:26 +01:00
parent e499f92360
commit e3382c8bcb
32 changed files with 234 additions and 81 deletions

View file

@ -605,6 +605,7 @@ func (c DockerContainer) ToFrontend() DockerContainerFrontend {
UptimeSeconds: c.UptimeSeconds,
RestartCount: c.RestartCount,
ExitCode: c.ExitCode,
OOMKilled: cloneBoolPtr(c.OOMKilled),
CreatedAt: c.CreatedAt.Unix() * 1000,
Labels: nil,
WritableLayerBytes: c.WritableLayerBytes,

View file

@ -413,6 +413,7 @@ func TestContainerToFrontend(t *testing.T) {
func TestDockerContainerToFrontend(t *testing.T) {
now := time.Now()
startedAt := now.Add(-1 * time.Hour)
oomKilled := false
container := DockerContainer{
ID: "abc123def456",
@ -427,6 +428,7 @@ func TestDockerContainerToFrontend(t *testing.T) {
MemoryPercent: 50.0,
UptimeSeconds: 3600,
RestartCount: 0,
OOMKilled: &oomKilled,
CreatedAt: now.Add(-2 * time.Hour),
StartedAt: &startedAt,
Ports: []DockerContainerPort{
@ -479,6 +481,13 @@ func TestDockerContainerToFrontend(t *testing.T) {
if frontend.StartedAt == nil {
t.Error("StartedAt should not be nil")
}
if frontend.OOMKilled == nil || *frontend.OOMKilled {
t.Fatalf("OOMKilled = %v, want explicit false", frontend.OOMKilled)
}
oomKilled = true
if *frontend.OOMKilled {
t.Fatal("frontend OOMKilled must not alias the internal model")
}
}
func TestDockerServiceToFrontend(t *testing.T) {

View file

@ -422,6 +422,7 @@ func cloneDockerContainerUpdateStatus(src *DockerContainerUpdateStatus) *DockerC
func cloneDockerContainer(src DockerContainer) DockerContainer {
dest := src
dest.OOMKilled = cloneBoolPtr(src.OOMKilled)
dest.StartedAt = cloneTimePtr(src.StartedAt)
dest.FinishedAt = cloneTimePtr(src.FinishedAt)
dest.Ports = append([]DockerContainerPort(nil), src.Ports...)

View file

@ -24,6 +24,20 @@ func TestCloneBoolPtr_Value(t *testing.T) {
}
}
func TestCloneDockerContainer_PreservesIndependentOOMEvidence(t *testing.T) {
oomKilled := false
src := DockerContainer{ID: "container-1", OOMKilled: &oomKilled}
got := cloneDockerContainer(src)
if got.OOMKilled == nil || *got.OOMKilled {
t.Fatalf("OOMKilled = %v, want explicit false", got.OOMKilled)
}
oomKilled = true
if *got.OOMKilled {
t.Fatal("cloned Docker container must own its OOM evidence value")
}
}
func TestCloneFloat64Ptr_Nil(t *testing.T) {
if cloneFloat64Ptr(nil) != nil {
t.Error("nil should clone to nil")

View file

@ -908,6 +908,7 @@ type DockerContainer struct {
UptimeSeconds int64 `json:"uptimeSeconds"`
RestartCount int `json:"restartCount"`
ExitCode int `json:"exitCode"`
OOMKilled *bool `json:"oomKilled,omitempty"`
CreatedAt time.Time `json:"createdAt"`
StartedAt *time.Time `json:"startedAt,omitempty"`
FinishedAt *time.Time `json:"finishedAt,omitempty"`

View file

@ -454,6 +454,7 @@ type DockerContainerFrontend struct {
UptimeSeconds int64 `json:"uptimeSeconds"`
RestartCount int `json:"restartCount"`
ExitCode int `json:"exitCode"`
OOMKilled *bool `json:"oomKilled,omitempty"`
CreatedAt int64 `json:"createdAt"`
StartedAt *int64 `json:"startedAt,omitempty"`
FinishedAt *int64 `json:"finishedAt,omitempty"`