pkg/sysinfo: move MemInfo and ReadMemInfo to a separate package
Commit 6a516acb2e
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 <github@gone.nl>
This commit is contained in:
parent
6a8964b75b
commit
2d49080056
8 changed files with 22 additions and 19 deletions
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/docker/docker/daemon/logger"
|
"github.com/docker/docker/daemon/logger"
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
"github.com/docker/docker/pkg/fileutils"
|
"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/kernel"
|
||||||
"github.com/docker/docker/pkg/parsers/operatingsystem"
|
"github.com/docker/docker/pkg/parsers/operatingsystem"
|
||||||
"github.com/docker/docker/pkg/platform"
|
"github.com/docker/docker/pkg/platform"
|
||||||
|
@ -249,11 +250,11 @@ func kernelVersion() string {
|
||||||
return kernelVersion
|
return kernelVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func memInfo() *sysinfo.Memory {
|
func memInfo() *meminfo.Memory {
|
||||||
memInfo, err := sysinfo.ReadMemInfo()
|
memInfo, err := meminfo.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Could not read system memory info: %v", err)
|
logrus.Errorf("Could not read system memory info: %v", err)
|
||||||
memInfo = &sysinfo.Memory{}
|
memInfo = &meminfo.Memory{}
|
||||||
}
|
}
|
||||||
return memInfo
|
return memInfo
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/stats"
|
"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
|
// newStatsCollector returns a new statsCollector that collections
|
||||||
|
@ -15,7 +15,7 @@ import (
|
||||||
func (daemon *Daemon) newStatsCollector(interval time.Duration) *stats.Collector {
|
func (daemon *Daemon) newStatsCollector(interval time.Duration) *stats.Collector {
|
||||||
// FIXME(vdemeester) move this elsewhere
|
// FIXME(vdemeester) move this elsewhere
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
meminfo, err := sysinfo.ReadMemInfo()
|
meminfo, err := meminfo.Read()
|
||||||
if err == nil && meminfo.MemTotal > 0 {
|
if err == nil && meminfo.MemTotal > 0 {
|
||||||
daemon.machineMemory = uint64(meminfo.MemTotal)
|
daemon.machineMemory = uint64(meminfo.MemTotal)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// Memory type. It is only supported on Linux and Windows, and returns an
|
||||||
// error on other platforms.
|
// error on other platforms.
|
||||||
func ReadMemInfo() (*Memory, error) {
|
func Read() (*Memory, error) {
|
||||||
return readMemInfo()
|
return readMemInfo()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package sysinfo
|
package meminfo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build linux || freebsd
|
//go:build linux || freebsd
|
||||||
// +build linux freebsd
|
// +build linux freebsd
|
||||||
|
|
||||||
package sysinfo
|
package meminfo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
|
@ -1,7 +1,7 @@
|
||||||
//go:build !linux && !windows
|
//go:build !linux && !windows
|
||||||
// +build !linux,!windows
|
// +build !linux,!windows
|
||||||
|
|
||||||
package sysinfo
|
package meminfo
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package sysinfo
|
package meminfo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -26,7 +26,7 @@ type memorystatusex struct {
|
||||||
ullAvailExtendedVirtual uint64
|
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.
|
// Memory type.
|
||||||
func readMemInfo() (*Memory, error) {
|
func readMemInfo() (*Memory, error) {
|
||||||
msi := &memorystatusex{
|
msi := &memorystatusex{
|
|
@ -1,16 +1,16 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import "github.com/docker/docker/pkg/sysinfo"
|
import "github.com/docker/docker/pkg/meminfo"
|
||||||
|
|
||||||
// MemInfo contains memory statistics of the host system.
|
// MemInfo contains memory statistics of the host system.
|
||||||
//
|
//
|
||||||
// Deprecated: use [sysinfo.Memory].
|
// Deprecated: use [meminfo.Memory].
|
||||||
type MemInfo = sysinfo.Memory
|
type MemInfo = meminfo.Memory
|
||||||
|
|
||||||
// ReadMemInfo retrieves memory statistics of the host system and returns a
|
// ReadMemInfo retrieves memory statistics of the host system and returns a
|
||||||
// MemInfo type.
|
// MemInfo type.
|
||||||
//
|
//
|
||||||
// Deprecated: use [sysinfo.ReadMemInfo].
|
// Deprecated: use [meminfo.Read].
|
||||||
func ReadMemInfo() (*sysinfo.Memory, error) {
|
func ReadMemInfo() (*meminfo.Memory, error) {
|
||||||
return sysinfo.ReadMemInfo()
|
return meminfo.Read()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue