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

Check for nil hostfs option while setting up cgroups #131

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions metric/system/cgroup/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
memoryStat = "memory"
)

//nolint: deadcode,structcheck,unused // needed by other platforms

Check failure on line 73 in metric/system/cgroup/reader.go

View workflow job for this annotation

GitHub Actions / lint-darwin

File is not `goimports`-ed with -local github.com/elastic (goimports)

Check failure on line 73 in metric/system/cgroup/reader.go

View workflow job for this annotation

GitHub Actions / lint (linux)

File is not `goimports`-ed with -local github.com/elastic (goimports)
type mount struct {
subsystem string // Subsystem name (e.g. cpuacct).
mountpoint string // Mountpoint of the subsystem (e.g. /cgroup/cpuacct).
Expand Down Expand Up @@ -133,6 +133,11 @@

// NewReaderOptions creates and returns a new Reader with the given options.
func NewReaderOptions(opts ReaderOptions) (*Reader, error) {
// we don't want a nil pointer deref if someone forgets to set this
if opts.RootfsMountpoint == nil {
opts.RootfsMountpoint = resolve.NewTestResolver("/")
}

// Determine what subsystems are supported by the kernel.
subsystems, err := SupportedSubsystems(opts.RootfsMountpoint)
// We can return a not-quite-an-error ErrCgroupsMissing here, so return the bare error.
Expand Down
9 changes: 9 additions & 0 deletions metric/system/cgroup/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ const (
idv2 = "docker-1c8fa019edd4b9d4b2856f4932c55929c5c118c808ed5faee9a135ca6e84b039.scope"
)

func TestReaderOptsWithoutResolve(t *testing.T) {
reader, err := NewReaderOptions(ReaderOptions{})
require.NoError(t, err)

// actual value doesn't matter, the point is that we don't set RootfsMountpoint and we __don't__ get a nil pointer deref panic.
_, err = reader.CgroupsVersion(345)
require.Error(t, err)
}

func TestV1EventDifferentPaths(t *testing.T) {
pid := 3757
reader, err := NewReader(resolve.NewTestResolver("testdata/ubuntu1804"), true)
Expand Down
Loading