Fix task load.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
72a3a019ae
commit
28ca8f05d3
@ -5,6 +5,7 @@ package linux
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"github.com/containerd/cgroups"
|
"github.com/containerd/cgroups"
|
||||||
@ -32,7 +33,8 @@ func newTask(id, namespace string, pid int, shim *client.Client, monitor runtime
|
|||||||
cg cgroups.Cgroup
|
cg cgroups.Cgroup
|
||||||
)
|
)
|
||||||
if pid > 0 {
|
if pid > 0 {
|
||||||
if cg, err = cgroups.Load(cgroups.V1, cgroups.PidPath(pid)); err != nil {
|
cg, err = cgroups.Load(cgroups.V1, cgroups.PidPath(pid))
|
||||||
|
if err != nil && err != cgroups.ErrCgroupDeleted {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,6 +255,9 @@ func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error)
|
|||||||
|
|
||||||
// Metrics returns runtime specific system level metric information for the task
|
// Metrics returns runtime specific system level metric information for the task
|
||||||
func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
||||||
|
if t.cg == nil {
|
||||||
|
return nil, errors.Wrap(errdefs.ErrNotFound, "cgroup does not exist")
|
||||||
|
}
|
||||||
stats, err := t.cg.Stat(cgroups.IgnoreNotExist)
|
stats, err := t.cg.Stat(cgroups.IgnoreNotExist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -261,8 +266,11 @@ func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cgroup returns the underlying cgroup for a linux task
|
// Cgroup returns the underlying cgroup for a linux task
|
||||||
func (t *Task) Cgroup() cgroups.Cgroup {
|
func (t *Task) Cgroup() (cgroups.Cgroup, error) {
|
||||||
return t.cg
|
if t.cg == nil {
|
||||||
|
return nil, errors.Wrap(errdefs.ErrNotFound, "cgroup does not exist")
|
||||||
|
}
|
||||||
|
return t.cg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the task to exit returning the status and timestamp
|
// Wait for the task to exit returning the status and timestamp
|
||||||
|
@ -62,10 +62,14 @@ type cgroupsMonitor struct {
|
|||||||
func (m *cgroupsMonitor) Monitor(c runtime.Task) error {
|
func (m *cgroupsMonitor) Monitor(c runtime.Task) error {
|
||||||
info := c.Info()
|
info := c.Info()
|
||||||
t := c.(*linux.Task)
|
t := c.(*linux.Task)
|
||||||
if err := m.collector.Add(info.ID, info.Namespace, t.Cgroup()); err != nil {
|
cg, err := t.Cgroup()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return m.oom.Add(info.ID, info.Namespace, t.Cgroup(), m.trigger)
|
if err := m.collector.Add(info.ID, info.Namespace, cg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return m.oom.Add(info.ID, info.Namespace, cg, m.trigger)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *cgroupsMonitor) Stop(c runtime.Task) error {
|
func (m *cgroupsMonitor) Stop(c runtime.Task) error {
|
||||||
|
@ -519,7 +519,9 @@ func getTasksMetrics(ctx context.Context, filter filters.Filter, tasks []runtime
|
|||||||
collected := time.Now()
|
collected := time.Now()
|
||||||
metrics, err := tk.Metrics(ctx)
|
metrics, err := tk.Metrics(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if !errdefs.IsNotFound(err) {
|
||||||
log.G(ctx).WithError(err).Errorf("collecting metrics for %s", tk.ID())
|
log.G(ctx).WithError(err).Errorf("collecting metrics for %s", tk.ID())
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data, err := typeurl.MarshalAny(metrics)
|
data, err := typeurl.MarshalAny(metrics)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6
|
github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6
|
||||||
github.com/containerd/go-runc b3c048c028ddd789c6f9510c597f8b9c62f25359
|
github.com/containerd/go-runc b3c048c028ddd789c6f9510c597f8b9c62f25359
|
||||||
github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e
|
github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e
|
||||||
github.com/containerd/cgroups 5933ab4dc4f7caa3a73a1dc141bd11f42b5c9163
|
github.com/containerd/cgroups 9c238e632e80d94f71a067c3deb9b34b1886ef18
|
||||||
github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788
|
github.com/containerd/typeurl f6943554a7e7e88b3c14aad190bf05932da84788
|
||||||
github.com/docker/go-metrics 8fd5772bf1584597834c6f7961a530f06cbfbb87
|
github.com/docker/go-metrics 8fd5772bf1584597834c6f7961a530f06cbfbb87
|
||||||
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
|
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
|
||||||
|
4
vendor/github.com/containerd/cgroups/cgroup.go
generated
vendored
4
vendor/github.com/containerd/cgroups/cgroup.go
generated
vendored
@ -10,6 +10,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New returns a new control via the cgroup cgroups interface
|
// New returns a new control via the cgroup cgroups interface
|
||||||
@ -39,6 +40,9 @@ func Load(hierarchy Hierarchy, path Path) (Cgroup, error) {
|
|||||||
for _, s := range pathers(subsystems) {
|
for _, s := range pathers(subsystems) {
|
||||||
p, err := path(s.Name())
|
p, err := path(s.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(errors.Cause(err)) {
|
||||||
|
return nil, ErrCgroupDeleted
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := os.Lstat(s.Path(p)); err != nil {
|
if _, err := os.Lstat(s.Path(p)); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user