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

feat: cgroups host collector #1581

Merged
merged 8 commits into from
Jul 24, 2024
Merged

feat: cgroups host collector #1581

merged 8 commits into from
Jul 24, 2024

Conversation

banjoh
Copy link
Member

@banjoh banjoh commented Jul 19, 2024

Description, Motivation and Context

Linux control groups host collector that detects whether the specified mountPoint is a cgroup filesystem and what version it is. The collector also collects information of the configured cgroup controllers. Since the output is a JSON object, the JSON compare analyser can be utilised. (#1582 PR is WIP to allow host collectors to use this analyzer)

Collector spec

apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
  name: cgroups
spec:
  hostCollectors:
    - cgroups:
         mountPoint: /cgroup/mount # default to /sys/fs/cgroup if not defined 

cgroup v1 results

{
  "cgroup-enabled": true,
  "cgroup-v1": {
    "enabled": true,
    "mountPoint": "/sys/fs/cgroup",
    "controllers": [
      "cpuset",
      "cpu",
      "cpuacct",
      "blkio",
      "memory",
      "devices",
      "freezer",
      "net_cls",
      "perf_event",
      "net_prio",
      "hugetlb",
      "pids",
      "rdma",
      "misc"
    ]
  },
  "cgroup-v2": {
    "enabled": false,
    "mounts": null,
    "controllers": null
  },
  "allControllers": [
    "cpuset",
    "cpu",
    "cpuacct",
    "blkio",
    "memory",
    "devices",
    "freezer",
    "net_cls",
    "perf_event",
    "net_prio",
    "hugetlb",
    "pids",
    "rdma",
    "misc"
  ]
}

cgroup v2 results

{
  "cgroup-enabled": true,
  "cgroup-v1": {
    "enabled": false,
    "mountPoint": "",
    "controllers": []
  },
  "cgroup-v2": {
    "enabled": true,
    "mountPoint": "/sys/fs/cgroup",
    "controllers": [
      "cpuset",
      "cpu",
      "io",
      "memory",
      "hugetlb",
      "pids",
      "rdma",
      "misc",
      "freezer",
      "devices"
    ]
  },
  "allControllers": [
    "cpu",
    "cpuset",
    "devices",
    "freezer",
    "hugetlb",
    "io",
    "memory",
    "misc",
    "pids",
    "rdma"
  ]
}

cgroup v1 configuration
https://asciinema.org/a/v93LLPLKxgLjUXiLWRNi0SEpp

cgroup v2 configuration
https://asciinema.org/a/WGxafFNfPUL4my1sQoyxJO1uy

Fixes: #1579

Checklist

  • New and existing tests pass locally with introduced changes.
  • Tests for the changes have been added (for bug fixes / features)
  • The commit message(s) are informative and highlight any breaking changes
  • Any documentation required has been added/updated. For changes to https://troubleshoot.sh/ create a PR here

Does this PR introduce a breaking change?

  • Yes
  • No

@banjoh banjoh requested a review from a team as a code owner July 19, 2024 13:33
@banjoh banjoh added the type::feature New feature or request label Jul 19, 2024
@banjoh banjoh changed the title feat: cgroups collector feat: cgroups host collector Jul 19, 2024
Linux control groups host collector that detects whether the specified
mountPath is a cgroup filesystem and what version it is.
The collector also collects information of the configured cgroup controllers.

Signed-off-by: Evans Mungai <evans@replicated.com>
Signed-off-by: Evans Mungai <evans@replicated.com>
@banjoh
Copy link
Member Author

banjoh commented Jul 19, 2024

replicatedhq/troubleshoot.sh#566 is the docs PR

Signed-off-by: Evans Mungai <evans@replicated.com>
This list makes it easy for an analyser that would
like to check if a controller is present

Signed-off-by: Evans Mungai <evans@replicated.com>
Signed-off-by: Evans Mungai <evans@replicated.com>
pkg/collect/host_cgroup_linux.go Outdated Show resolved Hide resolved
pkg/collect/host_cgroup_linux.go Outdated Show resolved Hide resolved
pkg/collect/host_cgroup_linux.go Outdated Show resolved Hide resolved
// Get the available controllers from /proc/cgroups.
// See https://www.man7.org/linux/man-pages/man7/cgroups.7.html#NOTES

f, err := os.Open("/proc/cgroups")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this should be set to mountPoint instead of being hardcoded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cgroup v1, information about controllers is always stored in /proc/cgroups file. This is different from the cgroup mount points.

From https://www.man7.org/linux/man-pages/man7/cgroups.7.html#NOTES

   /proc files
       /proc/cgroups (since Linux 2.6.24)
              This file contains information about the controllers that
              are compiled into the kernel.  An example of the contents
              of this file (reformatted for readability) is the

Signed-off-by: Evans Mungai <evans@replicated.com>
diamonwiggins
diamonwiggins previously approved these changes Jul 23, 2024
@banjoh banjoh merged commit 01d5804 into replicatedhq:main Jul 24, 2024
27 checks passed
@banjoh banjoh deleted the em/cgroups branch July 24, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type::feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cgroup collector/analyzer
3 participants