-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Carry #780: Export env variables as prometheus labels #1023
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
Conversation
|
Can one of the admins verify this patch? |
|
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
|
Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist") If this message is too spammy, please complain to ixdy. |
|
@vishh i've checked our CLAs and i think we are ok here. Let me know what you think. |
container/docker/handler.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep env as a separate field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm in the end they all come back as metrics labels so i dont really think they are necessary.
Labels makes a lot of sense for metrics, env much less so. We are just stuck with env here because some orchestration platform doesnt support writing labels to docker container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. The data generated here can be exposed in many different ways - REST API, prometheus endpoint, storage sinks, etc. I'd prefer keeping env and labels separate at this layer.
If the prometheus endpoint chooses to combine labels and env, that's fine by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed. Updated it to add Envs as a source of metadata to ContainerSpec. PTAL
|
ping @vishh |
the previous regex wasnt able to match anything. This regex should hopefully do better. Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
container/docker/factory.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels more like labels. Why not expose this additional metadata as labels instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Infact why not add it to docker containers directly? Is this needed to provide backwards compat with old docker versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main reason was noted here: #78
tldr: the orchestrator doesnt understand docker labels, and set their metadata as env variable. Until that's fixed, we need this to make sense of those containers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Why add a flag to cadvisor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to select the env that we want to publish as metrics labels ( I made a similar flag for logging in docker moby/moby#16961 )
For example, a mesos container has the following configs:
"Env": [
"GOMAXPROCS=64",
"MARATHON_APP_VERSION=2015-11-18T22:55:53.442Z",
"MARATHON_APP_DOCKER_IMAGE=docker/service",
"MESOS_TASK_ID=service.3f90dfce-12314235",
"MARATHON_APP_ID=/service",
"MESOS_SANDBOX=/mnt/mesos/sandbox",
"MESOS_CONTAINER_NAME=mesos-asdsfdfds",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"container=docker"
],
"Labels": {}, // sad :(
we only interest in MARATHON_APP_ID,MESOS_TASK_ID,MESOS_CONTAINER_NAME as the container identifiers.
A flag is reasonably useful for use as we only use 1 orchestrator i.e. mesos, so all containers will have the same set of env keys. This is the chosen approach in the original PR.
I can imagine an alternative approach would be to let the administrator defined their desired env keys as a well known label, for example:
// this will not be set as metrics in prometheus
"Labels": { "cadvisor.metadata_env": "MARATHON_APP_ID,MESOS_TASK_ID,MESOS_CONTAINER_NAME" }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining @dqminh. The flag name doesn't seem to convey the fact that it is a filter. Can you fix the naming and description to make it clear that it is a filter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM. What do you think of
-allowed-docker-env-as-metadata: a comma-separated list of allowed environment variable names for docker container that should have their name values set as the container's metadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about --docker-env-metadata-whitelist: a comma-separated list of environment variable keys that needs to be collected for docker containers?
And BTW will this default to all env variables? To me that feels like a good default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--docker-env-metadata-whitelist: a comma-separated list of environment variable keys that needs to be collected for docker containers
👍
Hmm, i thinkcollecting all env variables as the default is debatable.
In term of metrics collection, many env variables are strictly for runtime usage and doesn't make much sense in term of metrics which is why the whitelist approach ( i.e. disabled by default ) feels right. I think enabling all env variables by default will likely bite some users in their foot if they are not careful.
However, if we are talking about collecting information of container for exposing to others i.e. cadvisor is the only place to discover containers' information on the system then collecting all env by default makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree with you. Env variables sometimes contain auth information. Disabled by default SGTM.
If we were to support collecting all env variables, then we might have to support wildcards in the flag though.
|
@vishh added references to API v2 and changed the flag. I'm keeping the env whitelist i.e. not collecting all env variables by default. PTAL. |
container/docker/factory.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dockerEnvWhitelist would be a more readable name for this variable.
|
Just a couple of nits. Otherwise LGTM! Thanks @dqminh |
|
@vishh updated |
|
LGTM |
|
can you squash your commits? |
This add Envs to container spec as a metadata source. When using prometheus exposition format, they will be merged into the list of metrics' labels. Also changed the cli flag to docker_env_metadata_whitelist, and add refenrences of whitelist envs to API Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
|
@vishh squashed the changes to envs into 1 commits. |
|
LGTM |
|
@k8s-bot test this please |
|
@k8s-bot test this please |
|
Merging this since e2e has passed. |
Carry #780: Export env variables as prometheus labels
This rebase the patch in #780 and add a few more fixes: