Skip to content

Cherry-pick #22879 to 7.x: libbeat: override /sys/fs/cgroup paths in Docker#23050

Merged
axw merged 3 commits intoelastic:7.xfrom
axw:backport_22879_7.x
Dec 16, 2020
Merged

Cherry-pick #22879 to 7.x: libbeat: override /sys/fs/cgroup paths in Docker#23050
axw merged 3 commits intoelastic:7.xfrom
axw:backport_22879_7.x

Conversation

@axw
Copy link
Copy Markdown
Member

@axw axw commented Dec 10, 2020

Cherry-pick of PR #22879 to 7.x branch. Original message:

What does this PR do?

This PR adds an undocumented environment variable, LIBBEAT_MONITORING_CGROUPS_HIERARCHY_OVERRIDE, which can be used to override where cgroup metrics are found. This follows the approach taken by Elasticsearch (elastic/elasticsearch#22757), Kibana, and Logstash. The environment variable is set (to "/") in the Docker images.

Why is it important?

Under Docker, the paths in /proc/<pid>/cgroup do not have corresponding paths under /sys/fs/cgroup/<subsystem>. Instead, we should assume a root cgroup and read directly from the files in the subsystem directories.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
    - [ ] I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
    - [ ] I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

  • Build the Docker image for x-pack/filebeat: PLATFORMS=linux/amd64 TYPES=docker mage package)
  • Load the Docker image: docker image load < build/distributions/filebeat-8.0.0-linux-amd64.docker.tar.gz
  • Run a filebeat container under Docker with monitoring enabled, and with a CPU quota defined (I set it to 20000, for example).
  • Wait for metrics to be reported, and check that the cgroup metrics are non-zero:
GET /.monitoring-beats-7-2020.12.03/_search
{
  "sort": [
    {
      "timestamp": {
        "order": "desc"
      }
    }
  ],
  "_source": "beats_stats.metrics.beat.cgroup"
}
        "_index" : ".monitoring-beats-7-2020.12.03",
        "_id" : "cz-vJnYBjbWE_R3aj_hz",
        "_score" : null,
        "_source" : {
          "beats_stats" : {
            "metrics" : {
              "beat" : {
                "cgroup" : {
                  "memory" : {
                    "mem" : {
                      "usage" : {
                        "bytes" : 29429760
                      },
                      "limit" : {
                        "bytes" : 9223372036854771712
                      }
                    },
                    "id" : "e62f3fa5f16f05d6edc680e2303ccfb6a323599db6f7dfd2b02640390d1b8319"
                  },
                  "cpu" : {
                    "cfs" : {
                      "period" : {
                        "us" : 100000
                      },
                      "quota" : {
                        "us" : 20000
                      }
                    },
                    "stats" : {
                      "periods" : 254,
                      "throttled" : {
                        "ns" : 9362053609,
                        "periods" : 40
                      }
                    },
                    "id" : "e62f3fa5f16f05d6edc680e2303ccfb6a323599db6f7dfd2b02640390d1b8319"
                  },
                  "cpuacct" : {
                    "total" : {
                      "ns" : 1476308159
                    },
                    "id" : "e62f3fa5f16f05d6edc680e2303ccfb6a323599db6f7dfd2b02640390d1b8319"
                  }
                }
              }
            }
          }
        },

Related issues

Fixes #22844

* libbeat: override /sys/fs/cgroup paths in Docker

When running in Docker, make sure metrics are read
from `/sys/fs/cgroup/<subsystem>`, ignoring any paths
in `/proc/self/cgroup`.

Fixes elastic#22844

(cherry picked from commit 7e1520f)
@axw axw added [zube]: In Review backport Team:Services (Deprecated) Label for the former Integrations-Services team labels Dec 10, 2020
@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 10, 2020
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/integrations-services (Team:Services)

@botelastic botelastic Bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Dec 10, 2020
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Dec 10, 2020

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #23050 updated

  • Start Time: 2020-12-16T03:52:26.859+0000

  • Duration: 106 min 7 sec

Test stats 🧪

Test Results
Failed 0
Passed 17458
Skipped 1408
Total 18866

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 17458
Skipped 1408
Total 18866

@axw axw merged commit 190be26 into elastic:7.x Dec 16, 2020
@axw axw deleted the backport_22879_7.x branch December 16, 2020 06:02
@zube zube Bot added [zube]: Done and removed [zube]: Inbox labels Dec 16, 2020
@zube zube Bot removed the [zube]: Done label Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Team:Services (Deprecated) Label for the former Integrations-Services team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants