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

Add hostfs option to Host and Process functions, fix OperatingSystem() #226

Merged
merged 18 commits into from
Jul 23, 2024

Conversation

fearful-symmetry
Copy link
Contributor

@fearful-symmetry fearful-symmetry commented Jul 2, 2024

This fixes a subtle issue in agent's metadata processor where the OS reported by agent will reflect the OS of the container and not the OS of the container host. This is confusing to some users. So, we add an option type that a user can pass to the various metrics methods, as well as alter OperatingSystem() so it can take an alternate HostFS value.

This also cleans up the error handling a bit, since we had lots of unwrapped errors.

So, I designed this in a way that required the least amount of disruption to the code, but it's at the point where the registry is kind of complicated, and now juggles multiple types around. I was tempted to refactor the whole thing to make it a tad simpler and to avoid casting bare interfaces everywhere, but that felt a little outside the scope of the issue.

@fearful-symmetry fearful-symmetry added the Team:Elastic-Agent Label for the Agent team label Jul 2, 2024
@fearful-symmetry fearful-symmetry self-assigned this Jul 2, 2024
@fearful-symmetry fearful-symmetry changed the title Add hostfs option to Host and Process functions, add HostFS functionality to OperatingSystem() Add hostfs option to Host and Process functions, fix OperatingSystem() Jul 2, 2024
@fearful-symmetry fearful-symmetry marked this pull request as draft July 2, 2024 18:57
@fearful-symmetry fearful-symmetry marked this pull request as ready for review July 3, 2024 19:03
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

I opened #229 to address the macos build issue.

providers/linux/os.go Outdated Show resolved Hide resolved
internal/registry/registry.go Outdated Show resolved Hide resolved
system.go Outdated Show resolved Hide resolved
system.go Outdated Show resolved Hide resolved
Copy link
Member

@aleksmaus aleksmaus left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks!

providers/linux/os.go Outdated Show resolved Hide resolved
andrewkroh
andrewkroh previously approved these changes Jul 16, 2024
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM. Made some suggestions to improve docs.

system.go Outdated Show resolved Hide resolved
.changelog/226.txt Outdated Show resolved Hide resolved
system.go Outdated
// in the container:
//
// - /proc:/hostfs/proc
// - /sys/fs/cgroup:/hostfs/sys/fs/cgroup
Copy link
Member

Choose a reason for hiding this comment

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

Considering all things that are "HostFS" aware, are there any other mounts that a user would need to add? What about some combination of /etc/{os,lsb}-release for the OS detection?

The machine ID code isn't host FS aware, and think that creates an inconsistency for users. Do you think that should also be made aware of hostfs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch. Lemme poke around...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, added the hostfs arg to MachineID. Did some poking around, it seems like everything else in the linux provider should be be hostfs aware if it can't be. One exception is NativeArchitecture(), which shouldn't matter.

Copy link
Member

Choose a reason for hiding this comment

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

Can you please list in the godoc all of the necessary mounts for this example to work.

andrewkroh
andrewkroh previously approved these changes Jul 22, 2024
system.go Outdated Show resolved Hide resolved
@fearful-symmetry fearful-symmetry merged commit 4f5410b into elastic:main Jul 23, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants