Commit eabffb6e authored by Lantao Liu's avatar Lantao Liu

Update cadvisor to 6116f265302357cbb10f84737af30b1f13ce2d6c

parent c15ae2ff
...@@ -273,7 +273,6 @@ filegroup( ...@@ -273,7 +273,6 @@ filegroup(
"//vendor/github.com/jonboulle/clockwork:all-srcs", "//vendor/github.com/jonboulle/clockwork:all-srcs",
"//vendor/github.com/json-iterator/go:all-srcs", "//vendor/github.com/json-iterator/go:all-srcs",
"//vendor/github.com/jteeuwen/go-bindata:all-srcs", "//vendor/github.com/jteeuwen/go-bindata:all-srcs",
"//vendor/github.com/juju/ratelimit:all-srcs",
"//vendor/github.com/kardianos/osext:all-srcs", "//vendor/github.com/kardianos/osext:all-srcs",
"//vendor/github.com/kr/fs:all-srcs", "//vendor/github.com/kr/fs:all-srcs",
"//vendor/github.com/kr/pretty:all-srcs", "//vendor/github.com/kr/pretty:all-srcs",
......
...@@ -16,6 +16,7 @@ package containerd ...@@ -16,6 +16,7 @@ package containerd
import ( import (
"context" "context"
"sync"
"time" "time"
containersapi "github.com/containerd/containerd/api/services/containers/v1" containersapi "github.com/containerd/containerd/api/services/containers/v1"
...@@ -45,32 +46,38 @@ type containerdClient interface { ...@@ -45,32 +46,38 @@ type containerdClient interface {
Version(ctx context.Context) (string, error) Version(ctx context.Context) (string, error)
} }
var once sync.Once
var ctrdClient containerdClient = nil
// Client creates a containerd client // Client creates a containerd client
func Client() (containerdClient, error) { func Client() (containerdClient, error) {
gopts := []grpc.DialOption{ var retErr error
grpc.WithInsecure(), once.Do(func() {
grpc.FailOnNonTempDialError(true), gopts := []grpc.DialOption{
grpc.WithDialer(dialer.Dialer), grpc.WithInsecure(),
grpc.WithBlock(), grpc.WithDialer(dialer.Dialer),
grpc.WithTimeout(2 * time.Second), grpc.WithBlock(),
grpc.WithBackoffMaxDelay(3 * time.Second), grpc.WithTimeout(2 * time.Second),
} grpc.WithBackoffMaxDelay(3 * time.Second),
unary, stream := newNSInterceptors(k8sNamespace) }
gopts = append(gopts, unary, stream := newNSInterceptors(k8sNamespace)
grpc.WithUnaryInterceptor(unary), gopts = append(gopts,
grpc.WithStreamInterceptor(stream), grpc.WithUnaryInterceptor(unary),
) grpc.WithStreamInterceptor(stream),
)
conn, err := grpc.Dial(dialer.DialAddress("/var/run/containerd/containerd.sock"), gopts...) conn, err := grpc.Dial(dialer.DialAddress("/var/run/containerd/containerd.sock"), gopts...)
if err != nil { if err != nil {
return nil, err retErr = err
} return
c := &client{ }
containerService: containersapi.NewContainersClient(conn), ctrdClient = &client{
taskService: tasksapi.NewTasksClient(conn), containerService: containersapi.NewContainersClient(conn),
versionService: versionapi.NewVersionClient(conn), taskService: tasksapi.NewTasksClient(conn),
} versionService: versionapi.NewVersionClient(conn),
return c, err }
})
return ctrdClient, retErr
} }
func (c *client) LoadContainer(ctx context.Context, id string) (*containers.Container, error) { func (c *client) LoadContainer(ctx context.Context, id string) (*containers.Container, error) {
......
...@@ -29,19 +29,27 @@ import ( ...@@ -29,19 +29,27 @@ import (
"github.com/google/cadvisor/machine" "github.com/google/cadvisor/machine"
) )
const defaultTimeout = time.Second * 5 var dockerTimeout = 10 * time.Second
func defaultContext() context.Context { func defaultContext() context.Context {
ctx, _ := context.WithTimeout(context.Background(), defaultTimeout) ctx, _ := context.WithTimeout(context.Background(), dockerTimeout)
return ctx return ctx
} }
func SetTimeout(timeout time.Duration) {
dockerTimeout = timeout
}
func Status() (v1.DockerStatus, error) { func Status() (v1.DockerStatus, error) {
return StatusWithContext(defaultContext())
}
func StatusWithContext(ctx context.Context) (v1.DockerStatus, error) {
client, err := Client() client, err := Client()
if err != nil { if err != nil {
return v1.DockerStatus{}, fmt.Errorf("unable to communicate with docker daemon: %v", err) return v1.DockerStatus{}, fmt.Errorf("unable to communicate with docker daemon: %v", err)
} }
dockerInfo, err := client.Info(defaultContext()) dockerInfo, err := client.Info(ctx)
if err != nil { if err != nil {
return v1.DockerStatus{}, err return v1.DockerStatus{}, err
} }
......
...@@ -44,6 +44,7 @@ import ( ...@@ -44,6 +44,7 @@ import (
const ( const (
// The read write layers exist here. // The read write layers exist here.
aufsRWLayer = "diff" aufsRWLayer = "diff"
overlayRWLayer = "upper"
overlay2RWLayer = "diff" overlay2RWLayer = "diff"
// Path to the directory where docker stores log files if the json logging driver is enabled. // Path to the directory where docker stores log files if the json logging driver is enabled.
...@@ -197,7 +198,7 @@ func newDockerContainerHandler( ...@@ -197,7 +198,7 @@ func newDockerContainerHandler(
case aufsStorageDriver: case aufsStorageDriver:
rootfsStorageDir = path.Join(storageDir, string(aufsStorageDriver), aufsRWLayer, rwLayerID) rootfsStorageDir = path.Join(storageDir, string(aufsStorageDriver), aufsRWLayer, rwLayerID)
case overlayStorageDriver: case overlayStorageDriver:
rootfsStorageDir = path.Join(storageDir, string(storageDriver), rwLayerID) rootfsStorageDir = path.Join(storageDir, string(storageDriver), rwLayerID, overlayRWLayer)
case overlay2StorageDriver: case overlay2StorageDriver:
rootfsStorageDir = path.Join(storageDir, string(storageDriver), rwLayerID, overlay2RWLayer) rootfsStorageDir = path.Join(storageDir, string(storageDriver), rwLayerID, overlay2RWLayer)
case zfsStorageDriver: case zfsStorageDriver:
......
...@@ -114,7 +114,9 @@ func NewFsInfo(context Context) (FsInfo, error) { ...@@ -114,7 +114,9 @@ func NewFsInfo(context Context) (FsInfo, error) {
fsUUIDToDeviceName, err := getFsUUIDToDeviceNameMap() fsUUIDToDeviceName, err := getFsUUIDToDeviceNameMap()
if err != nil { if err != nil {
return nil, err // UUID is not always avaiable across different OS distributions.
// Do not fail if there is an error.
glog.Warningf("Failed to get disk UUID mapping, getting disk info by uuid will not work: %v", err)
} }
// Avoid devicemapper container mounts - these are tracked by the ThinPoolWatcher // Avoid devicemapper container mounts - these are tracked by the ThinPoolWatcher
......
...@@ -35,6 +35,7 @@ go_library( ...@@ -35,6 +35,7 @@ go_library(
"//vendor/github.com/google/cadvisor/utils/sysfs:go_default_library", "//vendor/github.com/google/cadvisor/utils/sysfs:go_default_library",
"//vendor/github.com/google/cadvisor/version:go_default_library", "//vendor/github.com/google/cadvisor/version:go_default_library",
"//vendor/github.com/opencontainers/runc/libcontainer/cgroups:go_default_library", "//vendor/github.com/opencontainers/runc/libcontainer/cgroups:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/k8s.io/utils/clock:go_default_library", "//vendor/k8s.io/utils/clock:go_default_library",
], ],
) )
......
...@@ -504,7 +504,7 @@ func (c *containerData) housekeepingTick(timer <-chan time.Time, longHousekeepin ...@@ -504,7 +504,7 @@ func (c *containerData) housekeepingTick(timer <-chan time.Time, longHousekeepin
err := c.updateStats() err := c.updateStats()
if err != nil { if err != nil {
if c.allowErrorLogging() { if c.allowErrorLogging() {
glog.Warning("Failed to update stats for container \"%s\": %s", c.info.Name, err) glog.Warningf("Failed to update stats for container \"%s\": %s", c.info.Name, err)
} }
} }
// Log if housekeeping took too long. // Log if housekeeping took too long.
......
...@@ -50,6 +50,7 @@ import ( ...@@ -50,6 +50,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/cgroups"
"golang.org/x/net/context"
"k8s.io/utils/clock" "k8s.io/utils/clock"
) )
...@@ -59,6 +60,8 @@ var eventStorageAgeLimit = flag.String("event_storage_age_limit", "default=24h", ...@@ -59,6 +60,8 @@ 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 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)") var applicationMetricsCountLimit = flag.Int("application_metrics_count_limit", 100, "Max number of application metrics to store (per container)")
const dockerClientTimeout = 10 * time.Second
// The Manager interface defines operations for starting a manager and getting // The Manager interface defines operations for starting a manager and getting
// container and machine information. // container and machine information.
type Manager interface { type Manager interface {
...@@ -154,11 +157,10 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn ...@@ -154,11 +157,10 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn
dockerStatus info.DockerStatus dockerStatus info.DockerStatus
rktPath string rktPath string
) )
if tempDockerStatus, err := docker.Status(); err != nil { docker.SetTimeout(dockerClientTimeout)
glog.V(5).Infof("Docker not connected: %v", err) // Try to connect to docker indefinitely on startup.
} else { dockerStatus = retryDockerStatus()
dockerStatus = tempDockerStatus
}
if tmpRktPath, err := rkt.RktPath(); err != nil { if tmpRktPath, err := rkt.RktPath(); err != nil {
glog.V(5).Infof("Rkt not connected: %v", err) glog.V(5).Infof("Rkt not connected: %v", err)
} else { } else {
...@@ -234,6 +236,31 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn ...@@ -234,6 +236,31 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn
return newManager, nil return newManager, nil
} }
func retryDockerStatus() info.DockerStatus {
startupTimeout := dockerClientTimeout
maxTimeout := 4 * startupTimeout
for {
ctx, _ := context.WithTimeout(context.Background(), startupTimeout)
dockerStatus, err := docker.StatusWithContext(ctx)
if err != nil {
return dockerStatus
}
switch err {
case context.DeadlineExceeded:
glog.Warningf("Timeout trying to communicate with docker during initialization, will retry")
default:
glog.V(5).Infof("Docker not connected: %v", err)
return info.DockerStatus{}
}
startupTimeout = 2 * startupTimeout
if startupTimeout > maxTimeout {
startupTimeout = maxTimeout
}
}
}
// A namespaced container name. // A namespaced container name.
type namespacedContainerName struct { type namespacedContainerName struct {
// The namespace of the container. Can be empty for the root namespace. // The namespace of the container. Can be empty for the root namespace.
......
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"ratelimit.go",
"reader.go",
],
importpath = "github.com/juju/ratelimit",
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment