Skip to content

Conversation

@dqminh
Copy link
Contributor

@dqminh dqminh commented Dec 16, 2015

This rebase the patch in #780 and add a few more fixes:

  • fix regex in test to do the correct thing
  • sanitize all label name before setting them as prometheus label

@cadvisorJenkinsBot
Copy link

Can one of the admins verify this patch?

@googlebot
Copy link
Collaborator

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.

@k8s-bot
Copy link
Collaborator

k8s-bot commented Dec 16, 2015

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.

@dqminh
Copy link
Contributor Author

dqminh commented Dec 17, 2015

@vishh i've checked our CLAs and i think we are ok here. Let me know what you think.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

@dqminh
Copy link
Contributor Author

dqminh commented Jan 4, 2016

ping @vishh

Florian Pfitzer and others added 3 commits January 5, 2016 10:49
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>
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

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 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" }

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@dqminh
Copy link
Contributor Author

dqminh commented Jan 7, 2016

@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.

Copy link
Contributor

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.

@vishh
Copy link
Contributor

vishh commented Jan 8, 2016

Just a couple of nits. Otherwise LGTM! Thanks @dqminh

@dqminh
Copy link
Contributor Author

dqminh commented Jan 12, 2016

@vishh updated

@vishh
Copy link
Contributor

vishh commented Jan 12, 2016

LGTM

@vishh
Copy link
Contributor

vishh commented Jan 12, 2016

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>
@dqminh
Copy link
Contributor Author

dqminh commented Jan 13, 2016

@vishh squashed the changes to envs into 1 commits.

@vishh
Copy link
Contributor

vishh commented Jan 13, 2016

LGTM

@vishh
Copy link
Contributor

vishh commented Jan 13, 2016

@k8s-bot test this please

@k8s-bot
Copy link
Collaborator

k8s-bot commented Jan 13, 2016

Jenkins GCE e2e

Build/test failed for commit e5b6bfa.

@vishh vishh closed this Jan 13, 2016
@vishh vishh reopened this Jan 13, 2016
@vishh
Copy link
Contributor

vishh commented Jan 13, 2016

@k8s-bot test this please

@k8s-bot
Copy link
Collaborator

k8s-bot commented Jan 13, 2016

Jenkins GCE e2e

Build/test passed for commit e5b6bfa.

@vishh
Copy link
Contributor

vishh commented Jan 13, 2016

Merging this since e2e has passed.

vishh added a commit that referenced this pull request Jan 13, 2016
Carry #780: Export env variables as prometheus labels
@vishh vishh merged commit 9cfc8ce into google:master Jan 13, 2016
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.

6 participants