From 2d490800565c410af8564844f52cd9fa34c7b1bf Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 14 Mar 2023 23:21:27 +0100 Subject: [PATCH] pkg/sysinfo: move MemInfo and ReadMemInfo to a separate package Commit 6a516acb2e720b7a01d27c7df9cfe9857c013308 moved the MemInfo type and ReadMemInfo() function into the pkg/sysinfo package. In an attempt to assist consumers of these to migrate to the new location, an alias was added. Unfortunately, the side effect of this alias is that pkg/system now depends on pkg/sysinfo, which means that consumers of this (such as docker/cli) now get all (indirect) dependencies of that package as dependency, which includes many dependencies that should only be needed for the daemon / runtime; - github.com/cilium/ebpf - github.com/containerd/cgroups - github.com/coreos/go-systemd/v22 - github.com/godbus/dbus/v5 - github.com/moby/sys/mountinfo - github.com/opencontainers/runtime-spec This patch moves the MemInfo related code to its own package. As the previous move was not yet part of a release, we're not adding new aliases in pkg/sysinfo. Signed-off-by: Sebastiaan van Stijn --- daemon/info.go | 7 ++++--- daemon/stats_collector.go | 4 ++-- pkg/{sysinfo => meminfo}/meminfo.go | 8 +++++--- pkg/{sysinfo => meminfo}/meminfo_linux.go | 2 +- pkg/{sysinfo => meminfo}/meminfo_unix_test.go | 2 +- pkg/{sysinfo => meminfo}/meminfo_unsupported.go | 2 +- pkg/{sysinfo => meminfo}/meminfo_windows.go | 4 ++-- pkg/system/meminfo_deprecated.go | 12 ++++++------ 8 files changed, 22 insertions(+), 19 deletions(-) rename pkg/{sysinfo => meminfo}/meminfo.go (70%) rename pkg/{sysinfo => meminfo}/meminfo_linux.go (98%) rename pkg/{sysinfo => meminfo}/meminfo_unix_test.go (98%) rename pkg/{sysinfo => meminfo}/meminfo_unsupported.go (94%) rename pkg/{sysinfo => meminfo}/meminfo_windows.go (93%) diff --git a/daemon/info.go b/daemon/info.go index 00b9d9b500..26c5851a50 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -14,6 +14,7 @@ import ( "github.com/docker/docker/daemon/logger" "github.com/docker/docker/dockerversion" "github.com/docker/docker/pkg/fileutils" + "github.com/docker/docker/pkg/meminfo" "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/parsers/operatingsystem" "github.com/docker/docker/pkg/platform" @@ -249,11 +250,11 @@ func kernelVersion() string { return kernelVersion } -func memInfo() *sysinfo.Memory { - memInfo, err := sysinfo.ReadMemInfo() +func memInfo() *meminfo.Memory { + memInfo, err := meminfo.Read() if err != nil { logrus.Errorf("Could not read system memory info: %v", err) - memInfo = &sysinfo.Memory{} + memInfo = &meminfo.Memory{} } return memInfo } diff --git a/daemon/stats_collector.go b/daemon/stats_collector.go index 3516f44b0b..f71992e7d5 100644 --- a/daemon/stats_collector.go +++ b/daemon/stats_collector.go @@ -5,7 +5,7 @@ import ( "time" "github.com/docker/docker/daemon/stats" - "github.com/docker/docker/pkg/sysinfo" + "github.com/docker/docker/pkg/meminfo" ) // newStatsCollector returns a new statsCollector that collections @@ -15,7 +15,7 @@ import ( func (daemon *Daemon) newStatsCollector(interval time.Duration) *stats.Collector { // FIXME(vdemeester) move this elsewhere if runtime.GOOS == "linux" { - meminfo, err := sysinfo.ReadMemInfo() + meminfo, err := meminfo.Read() if err == nil && meminfo.MemTotal > 0 { daemon.machineMemory = uint64(meminfo.MemTotal) } diff --git a/pkg/sysinfo/meminfo.go b/pkg/meminfo/meminfo.go similarity index 70% rename from pkg/sysinfo/meminfo.go rename to pkg/meminfo/meminfo.go index 6b9f8e5505..4f33ad26bf 100644 --- a/pkg/sysinfo/meminfo.go +++ b/pkg/meminfo/meminfo.go @@ -1,9 +1,11 @@ -package sysinfo +// Package meminfo provides utilites to retrieve memory statistics of +// the host system. +package meminfo -// ReadMemInfo retrieves memory statistics of the host system and returns a +// Read retrieves memory statistics of the host system and returns a // Memory type. It is only supported on Linux and Windows, and returns an // error on other platforms. -func ReadMemInfo() (*Memory, error) { +func Read() (*Memory, error) { return readMemInfo() } diff --git a/pkg/sysinfo/meminfo_linux.go b/pkg/meminfo/meminfo_linux.go similarity index 98% rename from pkg/sysinfo/meminfo_linux.go rename to pkg/meminfo/meminfo_linux.go index 993be58450..0c1cd21d49 100644 --- a/pkg/sysinfo/meminfo_linux.go +++ b/pkg/meminfo/meminfo_linux.go @@ -1,4 +1,4 @@ -package sysinfo +package meminfo import ( "bufio" diff --git a/pkg/sysinfo/meminfo_unix_test.go b/pkg/meminfo/meminfo_unix_test.go similarity index 98% rename from pkg/sysinfo/meminfo_unix_test.go rename to pkg/meminfo/meminfo_unix_test.go index bfbb6cdd06..8bb9eb191b 100644 --- a/pkg/sysinfo/meminfo_unix_test.go +++ b/pkg/meminfo/meminfo_unix_test.go @@ -1,7 +1,7 @@ //go:build linux || freebsd // +build linux freebsd -package sysinfo +package meminfo import ( "strings" diff --git a/pkg/sysinfo/meminfo_unsupported.go b/pkg/meminfo/meminfo_unsupported.go similarity index 94% rename from pkg/sysinfo/meminfo_unsupported.go rename to pkg/meminfo/meminfo_unsupported.go index 42472dda71..ebfadd5343 100644 --- a/pkg/sysinfo/meminfo_unsupported.go +++ b/pkg/meminfo/meminfo_unsupported.go @@ -1,7 +1,7 @@ //go:build !linux && !windows // +build !linux,!windows -package sysinfo +package meminfo import "errors" diff --git a/pkg/sysinfo/meminfo_windows.go b/pkg/meminfo/meminfo_windows.go similarity index 93% rename from pkg/sysinfo/meminfo_windows.go rename to pkg/meminfo/meminfo_windows.go index 553c1f3f4c..aa7d9375be 100644 --- a/pkg/sysinfo/meminfo_windows.go +++ b/pkg/meminfo/meminfo_windows.go @@ -1,4 +1,4 @@ -package sysinfo +package meminfo import ( "unsafe" @@ -26,7 +26,7 @@ type memorystatusex struct { ullAvailExtendedVirtual uint64 } -// ReadMemInfo retrieves memory statistics of the host system and returns a +// readMemInfo retrieves memory statistics of the host system and returns a // Memory type. func readMemInfo() (*Memory, error) { msi := &memorystatusex{ diff --git a/pkg/system/meminfo_deprecated.go b/pkg/system/meminfo_deprecated.go index 00e40352a9..216519923e 100644 --- a/pkg/system/meminfo_deprecated.go +++ b/pkg/system/meminfo_deprecated.go @@ -1,16 +1,16 @@ package system -import "github.com/docker/docker/pkg/sysinfo" +import "github.com/docker/docker/pkg/meminfo" // MemInfo contains memory statistics of the host system. // -// Deprecated: use [sysinfo.Memory]. -type MemInfo = sysinfo.Memory +// Deprecated: use [meminfo.Memory]. +type MemInfo = meminfo.Memory // ReadMemInfo retrieves memory statistics of the host system and returns a // MemInfo type. // -// Deprecated: use [sysinfo.ReadMemInfo]. -func ReadMemInfo() (*sysinfo.Memory, error) { - return sysinfo.ReadMemInfo() +// Deprecated: use [meminfo.Read]. +func ReadMemInfo() (*meminfo.Memory, error) { + return meminfo.Read() }