Serge Bazanski | bb7db92 | 2020-04-30 12:43:10 +0200 | [diff] [blame] | 1 | Copyright 2020 The Monogon Project Authors. |
| 2 | |
| 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | you may not use this file except in compliance with the License. |
| 5 | You may obtain a copy of the License at |
| 6 | |
| 7 | http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | |
| 9 | Unless required by applicable law or agreed to in writing, software |
| 10 | distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | |
| 15 | |
| 16 | This rips out ZFS support from cadvisor. This should be turned into an upstream change for allowing zfs to be disabled via a build tag. |
| 17 | |
| 18 | diff -ur com_github_google_cadvisor.orig/container/docker/factory.go com_github_google_cadvisor/container/docker/factory.go |
| 19 | --- com_github_google_cadvisor.orig/container/docker/factory.go 2020-04-15 17:54:23.082143453 +0200 |
| 20 | +++ com_github_google_cadvisor/container/docker/factory.go 2020-04-16 15:08:47.394501543 +0200 |
| 21 | @@ -34,7 +34,6 @@ |
| 22 | info "github.com/google/cadvisor/info/v1" |
| 23 | "github.com/google/cadvisor/machine" |
| 24 | "github.com/google/cadvisor/watcher" |
| 25 | - "github.com/google/cadvisor/zfs" |
| 26 | |
| 27 | docker "github.com/docker/docker/client" |
| 28 | "golang.org/x/net/context" |
| 29 | @@ -102,7 +101,6 @@ |
| 30 | aufsStorageDriver storageDriver = "aufs" |
| 31 | overlayStorageDriver storageDriver = "overlay" |
| 32 | overlay2StorageDriver storageDriver = "overlay2" |
| 33 | - zfsStorageDriver storageDriver = "zfs" |
| 34 | ) |
| 35 | |
| 36 | type dockerFactory struct { |
| 37 | @@ -127,8 +125,6 @@ |
| 38 | |
| 39 | thinPoolName string |
| 40 | thinPoolWatcher *devicemapper.ThinPoolWatcher |
| 41 | - |
| 42 | - zfsWatcher *zfs.ZfsWatcher |
| 43 | } |
| 44 | |
| 45 | func (self *dockerFactory) String() string { |
| 46 | @@ -157,7 +153,6 @@ |
| 47 | self.includedMetrics, |
| 48 | self.thinPoolName, |
| 49 | self.thinPoolWatcher, |
| 50 | - self.zfsWatcher, |
| 51 | ) |
| 52 | return |
| 53 | } |
| 54 | @@ -246,21 +241,6 @@ |
| 55 | return thinPoolWatcher, nil |
| 56 | } |
| 57 | |
| 58 | -func startZfsWatcher(dockerInfo *dockertypes.Info) (*zfs.ZfsWatcher, error) { |
| 59 | - filesystem, err := dockerutil.DockerZfsFilesystem(*dockerInfo) |
| 60 | - if err != nil { |
| 61 | - return nil, err |
| 62 | - } |
| 63 | - |
| 64 | - zfsWatcher, err := zfs.NewZfsWatcher(filesystem) |
| 65 | - if err != nil { |
| 66 | - return nil, err |
| 67 | - } |
| 68 | - |
| 69 | - go zfsWatcher.Start() |
| 70 | - return zfsWatcher, nil |
| 71 | -} |
| 72 | - |
| 73 | func ensureThinLsKernelVersion(kernelVersion string) error { |
| 74 | // kernel 4.4.0 has the proper bug fixes to allow thin_ls to work without corrupting the thin pool |
| 75 | minKernelVersion := semver.MustParse("4.4.0") |
| 76 | @@ -358,14 +338,6 @@ |
| 77 | thinPoolName = status.DriverStatus[dockerutil.DriverStatusPoolName] |
| 78 | } |
| 79 | |
| 80 | - var zfsWatcher *zfs.ZfsWatcher |
| 81 | - if storageDriver(dockerInfo.Driver) == zfsStorageDriver { |
| 82 | - zfsWatcher, err = startZfsWatcher(dockerInfo) |
| 83 | - if err != nil { |
| 84 | - klog.Errorf("zfs filesystem stats will not be reported: %v", err) |
| 85 | - } |
| 86 | - } |
| 87 | - |
| 88 | klog.V(1).Infof("Registering Docker factory") |
| 89 | f := &dockerFactory{ |
| 90 | cgroupSubsystems: cgroupSubsystems, |
| 91 | @@ -379,7 +351,6 @@ |
| 92 | includedMetrics: includedMetrics, |
| 93 | thinPoolName: thinPoolName, |
| 94 | thinPoolWatcher: thinPoolWatcher, |
| 95 | - zfsWatcher: zfsWatcher, |
| 96 | } |
| 97 | |
| 98 | container.RegisterContainerHandlerFactory(f, []watcher.ContainerWatchSource{watcher.Raw}) |
| 99 | diff -ur com_github_google_cadvisor.orig/container/docker/handler.go com_github_google_cadvisor/container/docker/handler.go |
| 100 | --- com_github_google_cadvisor.orig/container/docker/handler.go 2020-04-15 17:54:23.082143453 +0200 |
| 101 | +++ com_github_google_cadvisor/container/docker/handler.go 2020-04-16 15:45:56.432489633 +0200 |
| 102 | @@ -25,12 +25,10 @@ |
| 103 | |
| 104 | "github.com/google/cadvisor/container" |
| 105 | "github.com/google/cadvisor/container/common" |
| 106 | - dockerutil "github.com/google/cadvisor/container/docker/utils" |
| 107 | containerlibcontainer "github.com/google/cadvisor/container/libcontainer" |
| 108 | "github.com/google/cadvisor/devicemapper" |
| 109 | "github.com/google/cadvisor/fs" |
| 110 | info "github.com/google/cadvisor/info/v1" |
| 111 | - "github.com/google/cadvisor/zfs" |
| 112 | |
| 113 | dockercontainer "github.com/docker/docker/api/types/container" |
| 114 | docker "github.com/docker/docker/client" |
| 115 | @@ -87,9 +85,6 @@ |
| 116 | // the devicemapper poolname |
| 117 | poolName string |
| 118 | |
| 119 | - // zfsParent is the parent for docker zfs |
| 120 | - zfsParent string |
| 121 | - |
| 122 | // Reference to the container |
| 123 | reference info.ContainerReference |
| 124 | |
| 125 | @@ -130,7 +125,6 @@ |
| 126 | includedMetrics container.MetricSet, |
| 127 | thinPoolName string, |
| 128 | thinPoolWatcher *devicemapper.ThinPoolWatcher, |
| 129 | - zfsWatcher *zfs.ZfsWatcher, |
| 130 | ) (container.ContainerHandler, error) { |
| 131 | // Create the cgroup paths. |
| 132 | cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name) |
| 133 | @@ -164,8 +158,6 @@ |
| 134 | // For devicemapper, we only need the thin pool name, and that is passed in to this call |
| 135 | var ( |
| 136 | rootfsStorageDir string |
| 137 | - zfsFilesystem string |
| 138 | - zfsParent string |
| 139 | ) |
| 140 | switch storageDriver { |
| 141 | case aufsStorageDriver: |
| 142 | @@ -174,13 +166,6 @@ |
| 143 | rootfsStorageDir = path.Join(storageDir, string(storageDriver), rwLayerID, overlayRWLayer) |
| 144 | case overlay2StorageDriver: |
| 145 | rootfsStorageDir = path.Join(storageDir, string(storageDriver), rwLayerID, overlay2RWLayer) |
| 146 | - case zfsStorageDriver: |
| 147 | - status, err := Status() |
| 148 | - if err != nil { |
| 149 | - return nil, fmt.Errorf("unable to determine docker status: %v", err) |
| 150 | - } |
| 151 | - zfsParent = status.DriverStatus[dockerutil.DriverStatusParentDataset] |
| 152 | - zfsFilesystem = path.Join(zfsParent, rwLayerID) |
| 153 | } |
| 154 | |
| 155 | // We assume that if Inspect fails then the container is not known to docker. |
| 156 | @@ -200,7 +185,6 @@ |
| 157 | envs: make(map[string]string), |
| 158 | labels: ctnr.Config.Labels, |
| 159 | includedMetrics: includedMetrics, |
| 160 | - zfsParent: zfsParent, |
| 161 | } |
| 162 | // Timestamp returned by Docker is in time.RFC3339Nano format. |
| 163 | handler.creationTime, err = time.Parse(time.RFC3339Nano, ctnr.Created) |
| 164 | @@ -244,9 +228,6 @@ |
| 165 | handler.fsHandler = &dockerFsHandler{ |
| 166 | fsHandler: common.NewFsHandler(common.DefaultPeriod, rootfsStorageDir, otherStorageDir, fsInfo), |
| 167 | thinPoolWatcher: thinPoolWatcher, |
| 168 | - zfsWatcher: zfsWatcher, |
| 169 | - deviceID: ctnr.GraphDriver.Data["DeviceId"], |
| 170 | - zfsFilesystem: zfsFilesystem, |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | @@ -271,7 +252,7 @@ |
| 175 | } |
| 176 | |
| 177 | // dockerFsHandler is a composite FsHandler implementation the incorporates |
| 178 | -// the common fs handler, a devicemapper ThinPoolWatcher, and a zfsWatcher |
| 179 | +// the common fs handler and a devicemapper ThinPoolWatcher |
| 180 | type dockerFsHandler struct { |
| 181 | fsHandler common.FsHandler |
| 182 | |
| 183 | @@ -279,11 +260,6 @@ |
| 184 | thinPoolWatcher *devicemapper.ThinPoolWatcher |
| 185 | // deviceID is the id of the container's fs device |
| 186 | deviceID string |
| 187 | - |
| 188 | - // zfsWatcher is the zfs filesystem watcher |
| 189 | - zfsWatcher *zfs.ZfsWatcher |
| 190 | - // zfsFilesystem is the docker zfs filesystem |
| 191 | - zfsFilesystem string |
| 192 | } |
| 193 | |
| 194 | var _ common.FsHandler = &dockerFsHandler{} |
| 195 | @@ -316,16 +292,6 @@ |
| 196 | usage.TotalUsageBytes += thinPoolUsage |
| 197 | } |
| 198 | } |
| 199 | - |
| 200 | - if h.zfsWatcher != nil { |
| 201 | - zfsUsage, err := h.zfsWatcher.GetUsage(h.zfsFilesystem) |
| 202 | - if err != nil { |
| 203 | - klog.V(5).Infof("unable to get fs usage from zfs for filesystem %s: %v", h.zfsFilesystem, err) |
| 204 | - } else { |
| 205 | - usage.BaseUsageBytes = zfsUsage |
| 206 | - usage.TotalUsageBytes += zfsUsage |
| 207 | - } |
| 208 | - } |
| 209 | return usage |
| 210 | } |
| 211 | |
| 212 | @@ -389,8 +355,6 @@ |
| 213 | return fmt.Errorf("unable to determine device info for dir: %v: %v", self.rootfsStorageDir, err) |
| 214 | } |
| 215 | device = deviceInfo.Device |
| 216 | - case zfsStorageDriver: |
| 217 | - device = self.zfsParent |
| 218 | default: |
| 219 | return nil |
| 220 | } |
| 221 | diff -ur com_github_google_cadvisor.orig/container/docker/utils/docker.go com_github_google_cadvisor/container/docker/utils/docker.go |
| 222 | --- com_github_google_cadvisor.orig/container/docker/utils/docker.go 2020-04-15 17:54:23.082143453 +0200 |
| 223 | +++ com_github_google_cadvisor/container/docker/utils/docker.go 2020-04-16 15:10:30.379817831 +0200 |
| 224 | @@ -69,12 +69,3 @@ |
| 225 | |
| 226 | return metadataDevice, nil |
| 227 | } |
| 228 | - |
| 229 | -func DockerZfsFilesystem(info dockertypes.Info) (string, error) { |
| 230 | - filesystem := DriverStatusValue(info.DriverStatus, DriverStatusParentDataset) |
| 231 | - if len(filesystem) == 0 { |
| 232 | - return "", fmt.Errorf("Could not get zfs filesystem") |
| 233 | - } |
| 234 | - |
| 235 | - return filesystem, nil |
| 236 | -} |
| 237 | diff -ur com_github_google_cadvisor.orig/fs/fs.go com_github_google_cadvisor/fs/fs.go |
| 238 | --- com_github_google_cadvisor.orig/fs/fs.go 2020-04-15 17:54:23.086143468 +0200 |
| 239 | +++ com_github_google_cadvisor/fs/fs.go 2020-04-16 15:39:57.294333566 +0200 |
| 240 | @@ -32,7 +32,6 @@ |
| 241 | |
| 242 | "github.com/google/cadvisor/devicemapper" |
| 243 | "github.com/google/cadvisor/utils" |
| 244 | - zfs "github.com/mistifyio/go-zfs" |
| 245 | |
| 246 | "k8s.io/klog" |
| 247 | "k8s.io/utils/mount" |
| 248 | @@ -167,11 +166,9 @@ |
| 249 | |
| 250 | supportedFsType := map[string]bool{ |
| 251 | // all ext systems are checked through prefix. |
| 252 | - "btrfs": true, |
| 253 | "overlay": true, |
| 254 | "tmpfs": true, |
| 255 | "xfs": true, |
| 256 | - "zfs": true, |
| 257 | } |
| 258 | |
| 259 | for _, mount := range mounts { |
| 260 | @@ -200,17 +197,6 @@ |
| 261 | if mount.FsType == "tmpfs" { |
| 262 | mount.Source = mount.MountPoint |
| 263 | } |
| 264 | - // btrfs fix: following workaround fixes wrong btrfs Major and Minor Ids reported in /proc/self/mountinfo. |
| 265 | - // instead of using values from /proc/self/mountinfo we use stat to get Ids from btrfs mount point |
| 266 | - if mount.FsType == "btrfs" && mount.Major == 0 && strings.HasPrefix(mount.Source, "/dev/") { |
| 267 | - major, minor, err := getBtrfsMajorMinorIds(&mount) |
| 268 | - if err != nil { |
| 269 | - klog.Warningf("%s", err) |
| 270 | - } else { |
| 271 | - mount.Major = major |
| 272 | - mount.Minor = minor |
| 273 | - } |
| 274 | - } |
| 275 | |
| 276 | // overlay fix: Making mount source unique for all overlay mounts, using the mount's major and minor ids. |
| 277 | if mount.FsType == "overlay" { |
| 278 | @@ -312,7 +298,7 @@ |
| 279 | |
| 280 | // TODO(rjnagal): Detect docker root and graphdriver directories from docker info. |
| 281 | dockerRoot := context.Docker.Root |
| 282 | - for _, dir := range []string{"devicemapper", "btrfs", "aufs", "overlay", "overlay2", "zfs"} { |
| 283 | + for _, dir := range []string{"devicemapper", "overlay", "overlay2"} { |
| 284 | dockerImagePaths[path.Join(dockerRoot, dir)] = struct{}{} |
| 285 | } |
| 286 | for dockerRoot != "/" && dockerRoot != "." { |
| 287 | @@ -390,14 +376,6 @@ |
| 288 | fs.Capacity, fs.Free, fs.Available, err = getDMStats(device, partition.blockSize) |
| 289 | klog.V(5).Infof("got devicemapper fs capacity stats: capacity: %v free: %v available: %v:", fs.Capacity, fs.Free, fs.Available) |
| 290 | fs.Type = DeviceMapper |
| 291 | - case ZFS.String(): |
| 292 | - if _, devzfs := os.Stat("/dev/zfs"); os.IsExist(devzfs) { |
| 293 | - fs.Capacity, fs.Free, fs.Available, err = getZfstats(device) |
| 294 | - fs.Type = ZFS |
| 295 | - break |
| 296 | - } |
| 297 | - // if /dev/zfs is not present default to VFS |
| 298 | - fallthrough |
| 299 | default: |
| 300 | var inodes, inodesFree uint64 |
| 301 | if utils.FileExists(partition.mountpoint) { |
| 302 | @@ -521,30 +499,6 @@ |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | - mount, found := self.mounts[dir] |
| 307 | - // try the parent dir if not found until we reach the root dir |
| 308 | - // this is an issue on btrfs systems where the directory is not |
| 309 | - // the subvolume |
| 310 | - for !found { |
| 311 | - pathdir, _ := filepath.Split(dir) |
| 312 | - // break when we reach root |
| 313 | - if pathdir == "/" { |
| 314 | - break |
| 315 | - } |
| 316 | - // trim "/" from the new parent path otherwise the next possible |
| 317 | - // filepath.Split in the loop will not split the string any further |
| 318 | - dir = strings.TrimSuffix(pathdir, "/") |
| 319 | - mount, found = self.mounts[dir] |
| 320 | - } |
| 321 | - |
| 322 | - if found && mount.FsType == "btrfs" && mount.Major == 0 && strings.HasPrefix(mount.Source, "/dev/") { |
| 323 | - major, minor, err := getBtrfsMajorMinorIds(&mount) |
| 324 | - if err != nil { |
| 325 | - klog.Warningf("%s", err) |
| 326 | - } else { |
| 327 | - return &DeviceInfo{mount.Source, uint(major), uint(minor)}, nil |
| 328 | - } |
| 329 | - } |
| 330 | return nil, fmt.Errorf("could not find device with major: %d, minor: %d in cached partitions map", major, minor) |
| 331 | } |
| 332 | |
| 333 | @@ -715,18 +669,6 @@ |
| 334 | return used, total, nil |
| 335 | } |
| 336 | |
| 337 | -// getZfstats returns ZFS mount stats using zfsutils |
| 338 | -func getZfstats(poolName string) (uint64, uint64, uint64, error) { |
| 339 | - dataset, err := zfs.GetDataset(poolName) |
| 340 | - if err != nil { |
| 341 | - return 0, 0, 0, err |
| 342 | - } |
| 343 | - |
| 344 | - total := dataset.Used + dataset.Avail + dataset.Usedbydataset |
| 345 | - |
| 346 | - return total, dataset.Avail, dataset.Avail, nil |
| 347 | -} |
| 348 | - |
| 349 | // Simple io.Writer implementation that counts how many bytes were written. |
| 350 | type byteCounter struct{ bytesWritten uint64 } |
| 351 | |
| 352 | @@ -734,33 +676,3 @@ |
| 353 | b.bytesWritten += uint64(len(p)) |
| 354 | return len(p), nil |
| 355 | } |
| 356 | - |
| 357 | -// Get major and minor Ids for a mount point using btrfs as filesystem. |
| 358 | -func getBtrfsMajorMinorIds(mount *mount.MountInfo) (int, int, error) { |
| 359 | - // btrfs fix: following workaround fixes wrong btrfs Major and Minor Ids reported in /proc/self/mountinfo. |
| 360 | - // instead of using values from /proc/self/mountinfo we use stat to get Ids from btrfs mount point |
| 361 | - |
| 362 | - buf := new(syscall.Stat_t) |
| 363 | - err := syscall.Stat(mount.Source, buf) |
| 364 | - if err != nil { |
| 365 | - err = fmt.Errorf("stat failed on %s with error: %s", mount.Source, err) |
| 366 | - return 0, 0, err |
| 367 | - } |
| 368 | - |
| 369 | - klog.V(4).Infof("btrfs mount %#v", mount) |
| 370 | - if buf.Mode&syscall.S_IFMT == syscall.S_IFBLK { |
| 371 | - err := syscall.Stat(mount.MountPoint, buf) |
| 372 | - if err != nil { |
| 373 | - err = fmt.Errorf("stat failed on %s with error: %s", mount.MountPoint, err) |
| 374 | - return 0, 0, err |
| 375 | - } |
| 376 | - |
| 377 | - // The type Dev and Rdev in Stat_t are 32bit on mips. |
| 378 | - klog.V(4).Infof("btrfs dev major:minor %d:%d\n", int(major(uint64(buf.Dev))), int(minor(uint64(buf.Dev)))) // nolint: unconvert |
| 379 | - klog.V(4).Infof("btrfs rdev major:minor %d:%d\n", int(major(uint64(buf.Rdev))), int(minor(uint64(buf.Rdev)))) // nolint: unconvert |
| 380 | - |
| 381 | - return int(major(uint64(buf.Dev))), int(minor(uint64(buf.Dev))), nil // nolint: unconvert |
| 382 | - } else { |
| 383 | - return 0, 0, fmt.Errorf("%s is not a block device", mount.Source) |
| 384 | - } |
| 385 | -} |
| 386 | diff -ur com_github_google_cadvisor.orig/fs/fs_test.go com_github_google_cadvisor/fs/fs_test.go |
| 387 | --- com_github_google_cadvisor.orig/fs/fs_test.go 2020-04-15 17:54:23.086143468 +0200 |
| 388 | +++ com_github_google_cadvisor/fs/fs_test.go 2020-04-16 15:10:42.829856068 +0200 |
| 389 | @@ -516,7 +516,6 @@ |
| 390 | {Root: "/", MountPoint: "/b", Source: "/dev/sdb", FsType: "ext4", Major: 253, Minor: 1}, |
| 391 | {Root: "/", MountPoint: "/c", Source: "/dev/sdc", FsType: "btrfs", Major: 253, Minor: 2}, |
| 392 | {Root: "/", MountPoint: "/d", Source: "/dev/sdd", FsType: "xfs", Major: 253, Minor: 3}, |
| 393 | - {Root: "/", MountPoint: "/e", Source: "/dev/sde", FsType: "zfs", Major: 253, Minor: 4}, |
| 394 | {Root: "/", MountPoint: "/f", Source: "overlay", FsType: "overlay", Major: 253, Minor: 5}, |
| 395 | {Root: "/", MountPoint: "/test1", Source: "tmpfs", FsType: "tmpfs", Major: 253, Minor: 4}, |
| 396 | {Root: "/", MountPoint: "/test2", Source: "tmpfs", FsType: "tmpfs", Major: 253, Minor: 4}, |
| 397 | @@ -526,7 +525,6 @@ |
| 398 | "/dev/sdb": {fsType: "ext4", mountpoint: "/b", major: 253, minor: 1}, |
| 399 | "/dev/sdc": {fsType: "btrfs", mountpoint: "/c", major: 253, minor: 2}, |
| 400 | "/dev/sdd": {fsType: "xfs", mountpoint: "/d", major: 253, minor: 3}, |
| 401 | - "/dev/sde": {fsType: "zfs", mountpoint: "/e", major: 253, minor: 4}, |
| 402 | "overlay_253-5": {fsType: "overlay", mountpoint: "/f", major: 253, minor: 5}, |
| 403 | "/test1": {fsType: "tmpfs", mountpoint: "/test1", major: 253, minor: 4}, |
| 404 | "/test2": {fsType: "tmpfs", mountpoint: "/test2", major: 253, minor: 4}, |
| 405 | diff -ur com_github_google_cadvisor.orig/fs/types.go com_github_google_cadvisor/fs/types.go |
| 406 | --- com_github_google_cadvisor.orig/fs/types.go 2020-04-15 17:54:23.086143468 +0200 |
| 407 | +++ com_github_google_cadvisor/fs/types.go 2020-04-16 15:10:48.264872763 +0200 |
| 408 | @@ -47,7 +47,6 @@ |
| 409 | } |
| 410 | |
| 411 | const ( |
| 412 | - ZFS FsType = "zfs" |
| 413 | DeviceMapper FsType = "devicemapper" |
| 414 | VFS FsType = "vfs" |
| 415 | ) |