Skip to content

added parsing of cgroups file #352

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

Closed
wants to merge 8 commits into from

Conversation

beniwohli
Copy link
Contributor

@beniwohli beniwohli commented Dec 5, 2018

due to the somewhat underdefined and volatile format of this file,
the "parsing" got pretty spaghetti-code-y :(

This implements #346 and #347

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Code looks fine overall. Might be a bit neater using regular expressions?

I think it would be ideal if all agents aligned on the approach used for identifying container IDs. If you disagree with my approach, perhaps let's take it back to elastic/apm#21 to discuss?

@beniwohli beniwohli changed the title added parsing of cgroups file [WIP] added parsing of cgroups file Dec 19, 2018
}
assert system_info["container"] == {"id": "123"}


Copy link
Member

Choose a reason for hiding this comment

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

Worth a test to ensure system hostname is used as pod name when kubernetes info is not detected but partially set by environ? Seems like overkill but figured I'd mention it to prove I reviewed this.

@mock.patch.dict(
    "os.environ",
    {
        "KUBERNETES_NAMESPACE": "namespace",
    },
)
def test_docker_kubernetes_system_info_except_hostname_from_environ():
    # initialize agent only after overriding environment
    elasticapm_client = Client()
    # mock docker/kubernetes data here to get consistent behavior if test is run in docker
    with mock.patch("elasticapm.utils.cgroup.get_cgroup_container_metadata") as mock_metadata, mock.patch(
        "socket.gethostname"
    ) as mock_gethostname:
        mock_metadata.return_value = {}
        mock_gethostname.return_value = "foo"
        system_info = elasticapm_client.get_system_info()
    assert "kubernetes" in system_info
    assert system_info["kubernetes"] == {
        "pod": {"name": "foo"},
        "namespace": "namespace",
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this would have been the ideal chance to use that new fancy review-as-commit thingy :D set you as author of the commit instead. Not that it makes a huge difference after I squash-merge this :D

beniwohli and others added 5 commits January 2, 2019 18:07
due to the somewhat underdefined and volatile format of this file,
the "parsing" got pretty spaghetti-code-y :(
environment variables take precedence over data from /proc/self/cgroup
also, account for larger payload in payload size check, due to added
metadata
@beniwohli beniwohli closed this in 073a539 Jan 3, 2019
@beniwohli beniwohli deleted the read-cgroups branch January 3, 2019 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants