Skip to content

Commit 663b7b1

Browse files
authored
Revert "Integrate CRI and containerd file system stats "
1 parent 0ab27c2 commit 663b7b1

28 files changed

+79
-73931
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ docker-build:
9191
presubmit: vet
9292
@echo ">> checking go formatting"
9393
@./build/check_gofmt.sh
94-
@echo ">> checking CRI definitions"
95-
@./build/check_cri_defs.sh
9694
@echo ">> checking go mod tidy"
9795
@./build/check_gotidy.sh
9896
@echo ">> checking file boilerplate"

build/boilerplate/boilerplate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def file_passes(filename, refs, regexs):
9595
def file_extension(filename):
9696
return os.path.splitext(filename)[1].split(".")[-1].lower()
9797

98-
skipped_dirs = ['Godeps', 'vendor', 'third_party', '_gopath', '_output', '.git', 'cri-api']
98+
skipped_dirs = ['Godeps', 'vendor', 'third_party', '_gopath', '_output', '.git']
9999
def normalize_files(files):
100100
newfiles = []
101101
for pathname in files:

build/check_cri_defs.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.

build/update_cri_defs.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

cmd/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/mesos/mesos-go v0.0.7-0.20180413204204-29de6ff97b48
2222
github.com/pquerna/ffjson v0.0.0-20171002144729-d49c2bc1aa13 // indirect
2323
github.com/prometheus/client_golang v1.8.0
24-
github.com/stretchr/testify v1.7.0
24+
github.com/stretchr/testify v1.6.1
2525
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
2626
google.golang.org/api v0.34.0
2727
gopkg.in/olivere/elastic.v2 v2.0.12

cmd/go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,8 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
454454
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
455455
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
456456
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
457+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
457458
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
458-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
459-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
460459
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
461460
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
462461
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=

container/common/fsHandler.go

Lines changed: 46 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,15 @@ type FsUsage struct {
3737
InodeUsage uint64
3838
}
3939

40-
type FsUsageProvider interface {
41-
// Usage returns the fs usage
42-
Usage() (*FsUsage, error)
43-
// Targets returns where the fs usage metric is collected,it maybe a directory, a file or some
44-
// information about the snapshotter(for containerd)
45-
Targets() []string
46-
}
47-
4840
type realFsHandler struct {
4941
sync.RWMutex
50-
lastUpdate time.Time
51-
usage FsUsage
52-
period time.Duration
53-
minPeriod time.Duration
54-
usageProvider FsUsageProvider
42+
lastUpdate time.Time
43+
usage FsUsage
44+
period time.Duration
45+
minPeriod time.Duration
46+
rootfs string
47+
extraDir string
48+
fsInfo fs.FsInfo
5549
// Tells the container to stop.
5650
stopChan chan struct{}
5751
}
@@ -64,33 +58,56 @@ const DefaultPeriod = time.Minute
6458

6559
var _ FsHandler = &realFsHandler{}
6660

67-
func NewFsHandler(period time.Duration, provider FsUsageProvider) FsHandler {
61+
func NewFsHandler(period time.Duration, rootfs, extraDir string, fsInfo fs.FsInfo) FsHandler {
6862
return &realFsHandler{
69-
lastUpdate: time.Time{},
70-
usage: FsUsage{},
71-
period: period,
72-
minPeriod: period,
73-
usageProvider: provider,
74-
stopChan: make(chan struct{}, 1),
63+
lastUpdate: time.Time{},
64+
usage: FsUsage{},
65+
period: period,
66+
minPeriod: period,
67+
rootfs: rootfs,
68+
extraDir: extraDir,
69+
fsInfo: fsInfo,
70+
stopChan: make(chan struct{}, 1),
7571
}
7672
}
7773

7874
func (fh *realFsHandler) update() error {
75+
var (
76+
rootUsage, extraUsage fs.UsageInfo
77+
rootErr, extraErr error
78+
)
79+
// TODO(vishh): Add support for external mounts.
80+
if fh.rootfs != "" {
81+
rootUsage, rootErr = fh.fsInfo.GetDirUsage(fh.rootfs)
82+
}
7983

80-
usage, err := fh.usageProvider.Usage()
81-
82-
if err != nil {
83-
return err
84+
if fh.extraDir != "" {
85+
extraUsage, extraErr = fh.fsInfo.GetDirUsage(fh.extraDir)
8486
}
8587

88+
// Wait to handle errors until after all operartions are run.
89+
// An error in one will not cause an early return, skipping others
8690
fh.Lock()
8791
defer fh.Unlock()
8892
fh.lastUpdate = time.Now()
93+
if fh.rootfs != "" && rootErr == nil {
94+
fh.usage.InodeUsage = rootUsage.Inodes
95+
fh.usage.BaseUsageBytes = rootUsage.Bytes
96+
fh.usage.TotalUsageBytes = rootUsage.Bytes
97+
}
98+
if fh.extraDir != "" && extraErr == nil {
99+
if fh.rootfs != "" {
100+
fh.usage.TotalUsageBytes += extraUsage.Bytes
101+
} else {
102+
// rootfs is empty, totalUsageBytes use extra usage bytes
103+
fh.usage.TotalUsageBytes = extraUsage.Bytes
104+
}
105+
}
89106

90-
fh.usage.InodeUsage = usage.InodeUsage
91-
fh.usage.BaseUsageBytes = usage.BaseUsageBytes
92-
fh.usage.TotalUsageBytes = usage.TotalUsageBytes
93-
107+
// Combine errors into a single error to return
108+
if rootErr != nil || extraErr != nil {
109+
return fmt.Errorf("rootDiskErr: %v, extraDiskErr: %v", rootErr, extraErr)
110+
}
94111
return nil
95112
}
96113

@@ -113,8 +130,7 @@ func (fh *realFsHandler) trackUsage() {
113130
// if the long duration is persistent either because of slow
114131
// disk or lots of containers.
115132
longOp = longOp + time.Second
116-
klog.V(2).Infof(`fs: disk usage and inodes count on targets took %v: %v; `+
117-
`will not log again for this container unless duration exceeds %v`, duration, fh.usageProvider.Targets(), longOp)
133+
klog.V(2).Infof("fs: disk usage and inodes count on following dirs took %v: %v; will not log again for this container unless duration exceeds %v", duration, []string{fh.rootfs, fh.extraDir}, longOp)
118134
}
119135
select {
120136
case <-fh.stopChan:
@@ -137,56 +153,3 @@ func (fh *realFsHandler) Usage() FsUsage {
137153
defer fh.RUnlock()
138154
return fh.usage
139155
}
140-
141-
type fsUsageProvider struct {
142-
fsInfo fs.FsInfo
143-
rootFs string
144-
// The directory consumed by the container but outside rootFs, e.g. directory of saving logs
145-
extraDir string
146-
}
147-
148-
func NewGeneralFsUsageProvider(fsInfo fs.FsInfo, rootFs, extraDir string) FsUsageProvider {
149-
return &fsUsageProvider{
150-
fsInfo: fsInfo,
151-
rootFs: rootFs,
152-
extraDir: extraDir,
153-
}
154-
}
155-
156-
func (f *fsUsageProvider) Targets() []string {
157-
return []string{f.rootFs, f.extraDir}
158-
}
159-
160-
func (f *fsUsageProvider) Usage() (*FsUsage, error) {
161-
var (
162-
rootUsage, extraUsage fs.UsageInfo
163-
rootErr, extraErr error
164-
)
165-
166-
if f.rootFs != "" {
167-
rootUsage, rootErr = f.fsInfo.GetDirUsage(f.rootFs)
168-
}
169-
170-
if f.extraDir != "" {
171-
extraUsage, extraErr = f.fsInfo.GetDirUsage(f.extraDir)
172-
}
173-
174-
usage := &FsUsage{}
175-
176-
if f.rootFs != "" && rootErr == nil {
177-
usage.InodeUsage = rootUsage.Inodes
178-
usage.BaseUsageBytes = rootUsage.Bytes
179-
usage.TotalUsageBytes = rootUsage.Bytes
180-
}
181-
182-
if f.extraDir != "" && extraErr == nil {
183-
usage.TotalUsageBytes += extraUsage.Bytes
184-
}
185-
186-
// Combine errors into a single error to return
187-
if rootErr != nil || extraErr != nil {
188-
return nil, fmt.Errorf("failed to obtain filesystem usage; rootDiskErr: %v, extraDiskErr: %v", rootErr, extraErr)
189-
}
190-
191-
return usage, nil
192-
}

container/containerd/client.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ import (
2222
"time"
2323

2424
containersapi "github.com/containerd/containerd/api/services/containers/v1"
25-
snapshotapi "github.com/containerd/containerd/api/services/snapshots/v1"
2625
tasksapi "github.com/containerd/containerd/api/services/tasks/v1"
2726
versionapi "github.com/containerd/containerd/api/services/version/v1"
28-
types "github.com/containerd/containerd/api/types"
2927
"github.com/containerd/containerd/containers"
3028
"github.com/containerd/containerd/errdefs"
3129
"github.com/containerd/containerd/pkg/dialer"
3230
ptypes "github.com/gogo/protobuf/types"
33-
criapi "github.com/google/cadvisor/cri-api/pkg/apis/runtime/v1alpha2"
3431
"google.golang.org/grpc"
3532
"google.golang.org/grpc/backoff"
3633
)
@@ -39,17 +36,12 @@ type client struct {
3936
containerService containersapi.ContainersClient
4037
taskService tasksapi.TasksClient
4138
versionService versionapi.VersionClient
42-
snapshotService snapshotapi.SnapshotsClient
43-
criService criapi.RuntimeServiceClient
4439
}
4540

4641
type ContainerdClient interface {
4742
LoadContainer(ctx context.Context, id string) (*containers.Container, error)
4843
TaskPid(ctx context.Context, id string) (uint32, error)
4944
Version(ctx context.Context) (string, error)
50-
SnapshotMounts(ctx context.Context, snapshotter, key string) ([]*types.Mount, error)
51-
ContainerStatus(ctx context.Context, id string) (*criapi.ContainerStatus, error)
52-
ContainerStats(ctx context.Context, id string) (*criapi.ContainerStats, error)
5345
}
5446

5547
var once sync.Once
@@ -100,8 +92,6 @@ func Client(address, namespace string) (ContainerdClient, error) {
10092
containerService: containersapi.NewContainersClient(conn),
10193
taskService: tasksapi.NewTasksClient(conn),
10294
versionService: versionapi.NewVersionClient(conn),
103-
snapshotService: snapshotapi.NewSnapshotsClient(conn),
104-
criService: criapi.NewRuntimeServiceClient(conn),
10595
}
10696
})
10797
return ctrdClient, retErr
@@ -135,38 +125,6 @@ func (c *client) Version(ctx context.Context) (string, error) {
135125
return response.Version, nil
136126
}
137127

138-
func (c *client) SnapshotMounts(ctx context.Context, snapshotter, key string) ([]*types.Mount, error) {
139-
response, err := c.snapshotService.Mounts(ctx, &snapshotapi.MountsRequest{
140-
Snapshotter: snapshotter,
141-
Key: key,
142-
})
143-
if err != nil {
144-
return nil, errdefs.FromGRPC(err)
145-
}
146-
return response.Mounts, nil
147-
}
148-
149-
func (c *client) ContainerStatus(ctx context.Context, id string) (*criapi.ContainerStatus, error) {
150-
response, err := c.criService.ContainerStatus(ctx, &criapi.ContainerStatusRequest{
151-
ContainerId: id,
152-
Verbose: false,
153-
})
154-
if err != nil {
155-
return nil, err
156-
}
157-
return response.Status, nil
158-
}
159-
160-
func (c *client) ContainerStats(ctx context.Context, id string) (*criapi.ContainerStats, error) {
161-
response, err := c.criService.ContainerStats(ctx, &criapi.ContainerStatsRequest{
162-
ContainerId: id,
163-
})
164-
if err != nil {
165-
return nil, err
166-
}
167-
return response.Stats, nil
168-
}
169-
170128
func containerFromProto(containerpb containersapi.Container) *containers.Container {
171129
var runtime containers.RuntimeInfo
172130
if containerpb.Runtime != nil {

0 commit comments

Comments
 (0)