Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove docker-isms from manager package #2968

Merged
merged 3 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/internal/pages/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ func serveDockerPage(m manager.Manager, w http.ResponseWriter, u *url.URL) {
}

// Get Docker status
status, err := m.DockerInfo()
status, err := docker.Status()
if err != nil {
http.Error(w, fmt.Sprintf("failed to get docker info: %v", err), http.StatusInternalServerError)
return
}

dockerStatus, driverStatus := toStatusKV(status)
// Get Docker Images
images, err := m.DockerImages()
images, err := docker.Images()
if err != nil {
http.Error(w, fmt.Sprintf("failed to get docker images: %v", err), http.StatusInternalServerError)
return
Expand Down
4 changes: 2 additions & 2 deletions integration/tests/api/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ func TestAttributeInformationIsReturned(t *testing.T) {
}

vp := `\d+\.\d+\.\d+`
assert.True(t, assert.Regexp(t, vp, attributes.DockerVersion),
"Expected %s to match %s", attributes.DockerVersion, vp)
assert.True(t, assert.Regexp(t, vp, attributes.KernelVersion),
"Expected %s to match %s", attributes.KernelVersion, vp)
}
34 changes: 6 additions & 28 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/google/cadvisor/cache/memory"
"github.com/google/cadvisor/collector"
"github.com/google/cadvisor/container"
"github.com/google/cadvisor/container/docker"
"github.com/google/cadvisor/container/raw"
"github.com/google/cadvisor/events"
"github.com/google/cadvisor/fs"
Expand Down Expand Up @@ -61,6 +60,9 @@ var eventStorageAgeLimit = flag.String("event_storage_age_limit", "default=24h",
var eventStorageEventLimit = flag.String("event_storage_event_limit", "default=100000", "Max number of events to store (per type). Value is a comma separated list of key values, where the keys are event types (e.g.: creation, oom) or \"default\" and the value is an integer. Default is applied to all non-specified event types")
var applicationMetricsCountLimit = flag.Int("application_metrics_count_limit", 100, "Max number of application metrics to store (per container)")

// The namespace under which Docker aliases are unique.
const DockerNamespace = "docker"

var HousekeepingConfigFlags = HouskeepingConfig{
flag.Duration("max_housekeeping_interval", 60*time.Second, "Largest interval to allow between container housekeepings"),
flag.Bool("allow_dynamic_housekeeping", true, "Whether to allow the housekeeping interval to be dynamic"),
Expand Down Expand Up @@ -134,12 +136,6 @@ type Manager interface {

CloseEventChannel(watchID int)

// Get status information about docker.
DockerInfo() (info.DockerStatus, error)

// Get details about interesting docker images.
DockerImages() ([]info.DockerImage, error)

// Returns debugging information. Map of lines per category.
DebugInfo() map[string][]string
}
Expand Down Expand Up @@ -599,7 +595,7 @@ func (m *manager) getAllDockerContainers() map[string]*containerData {

// Get containers in the Docker namespace.
for name, cont := range m.containers {
if name.Namespace == docker.DockerNamespace {
if name.Namespace == DockerNamespace {
containers[cont.info.Name] = cont
}
}
Expand Down Expand Up @@ -631,14 +627,14 @@ func (m *manager) getDockerContainer(containerName string) (*containerData, erro

// Check for the container in the Docker container namespace.
cont, ok := m.containers[namespacedContainerName{
Namespace: docker.DockerNamespace,
Namespace: DockerNamespace,
Name: containerName,
}]

// Look for container by short prefix name if no exact match found.
if !ok {
for contName, c := range m.containers {
if contName.Namespace == docker.DockerNamespace && strings.HasPrefix(contName.Name, containerName) {
if contName.Namespace == DockerNamespace && strings.HasPrefix(contName.Name, containerName) {
if cont == nil {
cont = c
} else {
Expand Down Expand Up @@ -1335,14 +1331,6 @@ func parseEventsStoragePolicy() events.StoragePolicy {
return policy
}

func (m *manager) DockerImages() ([]info.DockerImage, error) {
return docker.Images()
}

func (m *manager) DockerInfo() (info.DockerStatus, error) {
return docker.Status()
}

func (m *manager) DebugInfo() map[string][]string {
debugInfo := container.DebugInfo()

Expand Down Expand Up @@ -1399,20 +1387,10 @@ func getVersionInfo() (*info.VersionInfo, error) {

kernelVersion := machine.KernelVersion()
osVersion := machine.ContainerOsVersion()
dockerVersion, err := docker.VersionString()
if err != nil {
return nil, err
}
dockerAPIVersion, err := docker.APIVersionString()
if err != nil {
return nil, err
}

return &info.VersionInfo{
KernelVersion: kernelVersion,
ContainerOsVersion: osVersion,
DockerVersion: dockerVersion,
DockerAPIVersion: dockerAPIVersion,
CadvisorVersion: version.Info["version"],
CadvisorRevision: version.Info["revision"],
}, nil
Expand Down
5 changes: 2 additions & 3 deletions manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/google/cadvisor/cache/memory"
"github.com/google/cadvisor/collector"
"github.com/google/cadvisor/container"
"github.com/google/cadvisor/container/docker"
containertest "github.com/google/cadvisor/container/testing"
info "github.com/google/cadvisor/info/v1"
itest "github.com/google/cadvisor/info/v1/test"
Expand Down Expand Up @@ -76,7 +75,7 @@ func createManagerAndAddContainers(
// Add Docker containers under their namespace.
if strings.HasPrefix(name, "/docker") {
mif.containers[namespacedContainerName{
Namespace: docker.DockerNamespace,
Namespace: DockerNamespace,
Name: strings.TrimPrefix(name, "/docker/"),
}] = cont
}
Expand Down Expand Up @@ -139,7 +138,7 @@ func createManagerAndAddSubContainers(
// Add Docker containers under their namespace.
if strings.HasPrefix(name, "/docker") {
mif.containers[namespacedContainerName{
Namespace: docker.DockerNamespace,
Namespace: DockerNamespace,
Name: strings.TrimPrefix(name, "/docker/"),
}] = cont
}
Expand Down