Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(agent): preserve collector interface compatibility

[email protected]4918bca7393c
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 95a6f4abae..e278e89c34 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -1516,7 +1516,11 @@ the intentionally sparse public response.
interface/block field selection, and no server-authored URI, domain, or
command input. Missing clients, inaccessible sockets, unsupported drivers,
partial statistics, or parse failures omit the inventory without failing
- host telemetry. Authenticated ingest derives CPU and I/O rates only after
+ host telemetry. Bounded command output is an optional collector capability
+ rather than a new `SystemCollector` interface requirement, preserving
+ compatibility with existing injected collectors; the production collector
+ enforces the cap during execution and fallback collectors are rejected
+ after the same size limit. Authenticated ingest derives CPU and I/O rates only after
two accepted samples and projects the domains as provider-neutral
`technology=libvirt` VM resources parented to the reporting host. It
preserves the last successful collection timestamp across a failed query so
diff --git a/internal/hostagent/agent_metrics_test.go b/internal/hostagent/agent_metrics_test.go
index 20175dd7c5..6e2cd06cbf 100644
--- a/internal/hostagent/agent_metrics_test.go
+++ b/internal/hostagent/agent_metrics_test.go
@@ -725,3 +725,33 @@ smallfixnumber="3"
t.Fatalf("Host.OSVersion = %q, want %q", report.Host.OSVersion, "7.2.2-72806 Update 3")
}
}
+
+type legacyCommandOutputCollector struct {
+ SystemCollector
+ output string
+ err error
+}
+
+func (c *legacyCommandOutputCollector) CommandCombinedOutput(
+ context.Context,
+ string,
+ ...string,
+) (string, error) {
+ return c.output, c.err
+}
+
+func TestCollectCommandOutputLimitedKeepsLegacyCollectorsCompatible(t *testing.T) {
+ collector := &legacyCommandOutputCollector{output: "123456"}
+ output, err := collectCommandOutputLimited(
+ context.Background(),
+ collector,
+ 4,
+ "example-command",
+ )
+ if err == nil {
+ t.Fatal("expected oversized legacy collector output to fail")
+ }
+ if output != "1234" {
+ t.Fatalf("bounded output = %q, want %q", output, "1234")
+ }
+}
diff --git a/internal/hostagent/libvirt.go b/internal/hostagent/libvirt.go
index 1be97c4551..c961590730 100644
--- a/internal/hostagent/libvirt.go
+++ b/internal/hostagent/libvirt.go
@@ -39,6 +39,32 @@ var libvirtStatsArgs = []string{
"--block",
}
+type limitedCommandOutputCollector interface {
+ CommandCombinedOutputLimited(
+ ctx context.Context,
+ maxBytes int,
+ name string,
+ arg ...string,
+ ) (string, error)
+}
+
+func collectCommandOutputLimited(
+ ctx context.Context,
+ collector SystemCollector,
+ maxBytes int,
+ name string,
+ arg ...string,
+) (string, error) {
+ if limited, ok := collector.(limitedCommandOutputCollector); ok {
+ return limited.CommandCombinedOutputLimited(ctx, maxBytes, name, arg...)
+ }
+ output, err := collector.CommandCombinedOutput(ctx, name, arg...)
+ if len(output) > maxBytes {
+ return output[:maxBytes], fmt.Errorf("command output exceeds %d bytes", maxBytes)
+ }
+ return output, err
+}
+
// collectLibvirtInventory auto-detects a local read-only libvirt connection.
// It is deliberately best-effort: hosts without virsh, socket access, or a
// compatible driver continue reporting normal host telemetry.
@@ -58,8 +84,9 @@ func (a *Agent) collectLibvirtInventory(ctx context.Context) *agentshost.Libvirt
queryCtx, cancel := context.WithTimeout(ctx, libvirtQueryTimeout)
defer cancel()
- listOutput, err := a.collector.CommandCombinedOutputLimited(
+ listOutput, err := collectCommandOutputLimited(
queryCtx,
+ a.collector,
libvirtMaxListOutputBytes,
path,
"--readonly",
@@ -88,8 +115,9 @@ func (a *Agent) collectLibvirtInventory(ctx context.Context) *agentshost.Libvirt
args := make([]string, 0, len(libvirtStatsArgs)+len(names))
args = append(args, libvirtStatsArgs...)
args = append(args, names...)
- statsOutput, err := a.collector.CommandCombinedOutputLimited(
+ statsOutput, err := collectCommandOutputLimited(
queryCtx,
+ a.collector,
libvirtMaxStatsOutputBytes,
path,
args...,
diff --git a/internal/hostagent/sysinfo.go b/internal/hostagent/sysinfo.go
index 80cf4f0b99..b90827a592 100644
--- a/internal/hostagent/sysinfo.go
+++ b/internal/hostagent/sysinfo.go
@@ -41,7 +41,6 @@ type SystemCollector interface {
Chmod(name string, mode os.FileMode) error
WriteFile(filename string, data []byte, perm os.FileMode) error
CommandCombinedOutput(ctx context.Context, name string, arg ...string) (string, error)
- CommandCombinedOutputLimited(ctx context.Context, maxBytes int, name string, arg ...string) (string, error)
LookPath(file string) (string, error)
}