Files
pulse-triage[bot] 0f972f42f2 Isolate host and Docker CPU sampling baselines (#1894)
Near-synchronous host and Docker reports consumed a shared CPU baseline, measuring collection bursts rather than each module's reporting interval. Retain a collector per host collector and a separate Docker module collector while preserving the package-level convenience API and disk filters.

Add an interleaved-counter regression covering both collection entry points. It fails when routed through the shared baseline and passes with isolated state. All hostmetrics, hostagent and dockeragent tests pass, as do the focused CPU regression tests under the race detector.

Change-source: pulse-maintainer
2026-09-04 22:29:32 +01:00

77 lines
2.5 KiB
Go

package dockeragent
import (
"context"
"crypto/rand"
"io"
"os"
"os/exec"
"runtime"
"syscall"
"time"
"github.com/moby/moby/client"
"github.com/rcourtman/pulse-go-rewrite/internal/hostmetrics"
)
// Docker reporting must not consume the host module or package-level CPU baseline.
var dockerHostMetrics hostmetrics.Collector
var (
connectRuntimeFn = connectRuntime
connectCollectorRuntimeFn = connectCollectorOwnedRootlessRuntime
hostmetricsCollect = dockerHostMetrics.Collect
hostmetricsCollectWithDiskFilters = func(ctx context.Context, exclude, include []string) (hostmetrics.Snapshot, error) {
if len(include) == 0 {
return hostmetricsCollect(ctx, exclude)
}
return dockerHostMetrics.CollectWithDiskFilters(ctx, exclude, include)
}
newTickerFn = time.NewTicker
randomDurationFn = randomDuration
nowFn = time.Now
sleepFn = time.Sleep
normalizeTargetsFn = normalizeTargets
buildRuntimeCandidatesFn = buildRuntimeCandidates
tryRuntimeCandidateFn = tryRuntimeCandidate
randIntFn = rand.Int
osExecutableFn = os.Executable
osCreateTempFn = os.CreateTemp
closeFileFn = func(f *os.File) error { return f.Close() }
osRenameFn = os.Rename
osChmodFn = os.Chmod
osRemoveFn = os.Remove
osReadFileFn = os.ReadFile
osWriteFileFn = os.WriteFile
osStatFn = os.Stat
syscallExecFn = syscall.Exec
goArch = runtime.GOARCH
unameMachine = func() (string, error) {
out, err := exec.Command("uname", "-m").Output()
if err != nil {
return "", err
}
return string(out), nil
}
machineIDPaths = []string{
"/etc/machine-id",
"/var/lib/dbus/machine-id",
}
unraidVersionPath = "/etc/unraid-version"
unraidPersistPath = "/boot/config/plugins/pulse-agent/pulse-agent"
unraidStartupScriptPath = "/boot/config/plugins/pulse-agent/start-pulse-agent.sh"
agentLogPath = "/var/log/pulse-agent.log"
openProcUptime = func() (io.ReadCloser, error) {
return os.Open("/proc/uptime")
}
newDockerClientFn = func(opts ...client.Opt) (dockerClient, error) {
return newMobyDockerClient(opts...)
}
selfUpdateFunc = func(a *Agent, ctx context.Context) error {
return a.selfUpdate(ctx)
}
execCommandContextFn = func(ctx context.Context, name string, arg ...string) *exec.Cmd {
return exec.CommandContext(ctx, name, arg...)
}
)