mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-27 05:57:27 +00:00
3a4a3fd62b
Expose confined, identity-bound filesystem observations through the shared resource pipeline so investigations can distinguish an exhausted container mount from unrelated host capacity. Keep unavailable measurements explicit. Isolate alert-history reads from durable writes and reuse one chronological fold across polling. Catch up through bounded durable event IDs so simultaneous readers do not replay every retained snapshot. Retain expired actions when investigation outcomes move back to needs attention, and keep attached Assistant context focused. Record live storage diagnosis, healthy and dependency controls, approved and rejected Docker outcomes, source-bound browser proof and exact test limits. Missing-access continuity, VM dispatch completion and remaining Assistant orchestration defects stay open in the redesign plan.
69 lines
2.9 KiB
Go
69 lines
2.9 KiB
Go
package monitoring
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/mock"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/models"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
|
|
agentsdocker "github.com/rcourtman/pulse-go-rewrite/pkg/agents/docker"
|
|
"github.com/rcourtman/pulse-go-rewrite/pkg/agents/filesystem"
|
|
)
|
|
|
|
func TestDockerFilesystemEvidenceSurvivesIngestionAndReplacesStaleUsage(t *testing.T) {
|
|
previous := mock.IsMockEnabled()
|
|
mustSetMockEnabled(t, false)
|
|
t.Cleanup(func() { mustSetMockEnabled(t, previous) })
|
|
m := newTestMonitor(t)
|
|
registry := unifiedresources.NewRegistry(nil)
|
|
now := time.Now().UTC()
|
|
report := agentsdocker.Report{Timestamp: now, Agent: agentsdocker.AgentInfo{ID: "fs-agent", IntervalSeconds: 30}, Host: agentsdocker.HostInfo{Hostname: "fs-host"}, Containers: []agentsdocker.Container{{ID: "fs-container", Name: "worker", State: "running", WritableLayerBytes: 999, RootFilesystemBytes: 9999}}}
|
|
observations := [][]filesystem.Observation{
|
|
{{Mountpoint: "/cache", Source: "linux-proc-root-statfs", ObservedAt: now, Type: "tmpfs", Usage: &filesystem.Usage{CapacityBytes: 8 << 20, Inodes: &filesystem.InodeUsage{Capacity: 100, Free: 50}}}},
|
|
{{Mountpoint: "/cache", Source: "linux-proc-root-statfs", ObservedAt: now.Add(time.Second), Error: "namespace unavailable"}},
|
|
nil,
|
|
}
|
|
for i, rows := range observations {
|
|
report.Timestamp = now.Add(time.Duration(i) * time.Second)
|
|
report.Containers[0].Filesystems = rows
|
|
host, err := m.ApplyDockerReport(report, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
registry.IngestSnapshot(models.StateSnapshot{DockerHosts: []models.DockerHost{host}})
|
|
resources := registry.ListByType(unifiedresources.ResourceTypeAppContainer)
|
|
if len(resources) != 1 {
|
|
t.Fatalf("resources: %+v", resources)
|
|
}
|
|
got := resources[0].Docker.Filesystems
|
|
if len(got) != len(rows) {
|
|
t.Fatalf("old evidence retained at step %d: %+v", i, got)
|
|
}
|
|
if resources[0].Metrics != nil && resources[0].Metrics.Disk != nil {
|
|
t.Fatal("mount capacity was promoted into a container-wide disk percentage")
|
|
}
|
|
if i == 0 {
|
|
if got[0].Usage == nil || got[0].Usage.CapacityBytes != 8<<20 || got[0].Usage.AvailableBytes != 0 {
|
|
t.Fatalf("measured full filesystem lost: %+v", got)
|
|
}
|
|
got[0].Usage.CapacityBytes = 1
|
|
got[0].Usage.Inodes.Free = 1
|
|
report.Containers[0].Filesystems[0].Usage.CapacityBytes = 2
|
|
fresh := registry.ListByType(unifiedresources.ResourceTypeAppContainer)[0].Docker.Filesystems[0]
|
|
if fresh.Usage.CapacityBytes != 8<<20 || fresh.Usage.Inodes.Free != 50 {
|
|
t.Fatal("resource snapshot aliases external observation storage")
|
|
}
|
|
}
|
|
if i == 1 && (got[0].Usage != nil || got[0].Error == "") {
|
|
t.Fatalf("failed read kept old numeric usage: %+v", got)
|
|
}
|
|
wire, err := json.Marshal(resources)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Logf("FILESYSTEM_RESOURCE_STEP_%d %s", i, wire)
|
|
}
|
|
}
|