-
Notifications
You must be signed in to change notification settings - Fork 679
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 template function to syslog adapter to traverse .Container.Config.Env #182
base: master
Are you sure you want to change the base?
Conversation
@@ -29,6 +30,15 @@ func getopt(name, dfault string) string { | |||
return value | |||
} | |||
|
|||
func tplGetEnvVar(env []string, key string) string { | |||
for _, value := range env { | |||
if strings.HasPrefix(value, fmt.Sprintf("%s%s", key, "=")) { |
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.
Maybe do the fmt.Sprintf("%s%s", key, "=")
once in the beginning of the function? Saves a few allocs.
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, changed.
@josegonzalez any chance to get this merged? This would help us a lot in identifying logs from specific services. |
Ping. Another hopeful user. |
@@ -29,6 +30,16 @@ func getopt(name, dfault string) string { | |||
return value | |||
} | |||
|
|||
func tplGetEnvVar(env []string, key string) string { | |||
key_equals := fmt.Sprintf("%s%s", key, "=") |
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.
key_equals := key + "="
key_equals := fmt.Sprintf("%s%s", key, "=") | ||
for _, value := range env { | ||
if strings.HasPrefix(value, key_equals) { | ||
return strings.Split(value, "=")[1] |
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.
return value[strings.Index(value, "=")+1:]
key_equals := key + "=" | ||
for _, value := range env { | ||
if strings.HasPrefix(value, key_equals) { | ||
return value[strings.Index(value, "=")+1:] |
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.
Can simplify this to:
return value[len(key_equals)+1:]
Hope this PR could be merged soon. |
+1, we really need this. Envvars are the only way to pass additional info about the container in case if your container orchestrator doesn't allow setting a container labels, but allows setting container envvars. The good example is Kubernetes, which does not allow (kubernetes/kubernetes#3764) setting container labels, only pod labels |
Did somebody try to merge this and the CI somehow failed? If this PR has been approved many of us would like to use it. |
Hope this info was helpful for you :) |
When I try your solution I get
This would be a great improvement for me. I'm not sure if this commit dropped off the radar because no one is available to fix the test or because people have found other ways to include individual env vars in the log messages. Does anyone following this have a working solution? |
@mmoore0011 Just ran into this from another issue here. I'm really close to having to do something like was suggested here, but it's just essentially checking each character to see if it matches the environment variable name up until the |
This was created as a way to pass a specific environment variable that's inside of the docker container. The variable .Container.Config.Env is formed of an array of key=value so it's not sortable or findable from the templating engine. Calling the container with something like this:
will create a line as such:
where nginx-marathon is part of the .Container.Config.Env:
This would also help solve #163 and #137
PS. several envs can be also concatenated: