-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Allow templating of AWS log stream name #25633
Conversation
It would appear the win2lin test was broken for a bit this evening, if someone can retrigger that test, I believe it should pass. |
/cc @samuelkarp @cpuguy83 |
func New(ctx logger.Context) (logger.Logger, error) { | ||
logGroupName := ctx.Config[logGroupKey] | ||
logStreamName := ctx.ContainerID | ||
if ctx.Config[logStreamKey] != "" { | ||
logStreamName = ctx.Config[logStreamKey] | ||
} else if ctx.Config[logStreamTemplateKey] != "" { | ||
if t, err := template.New("t").Parse(ctx.Config[logStreamTemplateKey]); err == nil { |
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.
It would be good to extract this out to a separate function for readability.
Thanks for submitting this! Can you add some unit tests to exercise the new functionality you added? It would also be good to update the documentation (in |
ccac0b4
to
0993704
Compare
I think I got everything after some fighting with the code vetter, let me know if I left anything to be desired. |
# awslogs-stream-template | ||
|
||
Configure a [log stream](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchLogs.html) | ||
to a templated name. The template is executed with a [logger.Context](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchLogs.html) |
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 think you have the wrong link for logger.Context
.
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.
indeed - will fix
Templating seems fairly generic enough to support in all drivers. |
That is to say, +1. There isn't a need to implement all drivers here, but I don't think we need to namespace the option? WDYT? |
I think that makes sense; we should take care to properly document that it's currently only supported in this driver, but otherwise sgtm |
ping @jdnurmi can you address the review comments? |
0993704
to
675b057
Compare
Ok, I think I've got everything; Originally I'd thought that putting this on the Logger.Context directly might make sense, but I didn't want to muck with anything too deep unless there seemed like consensus. It would be short work to do that if that's what people would like. EDIT: And sorry for the delay! |
91c0e39
to
068d2cb
Compare
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.
Changes look great! I'm going to ask our doc writer if he has any suggestions on the documentation, but otherwise it looks good.
name = buff.String() | ||
} | ||
if err == nil && strings.IndexAny(name, ":*") >= 0 { | ||
// Arguably, we could let AWS reject this later, but by then your container is |
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.
(*logStream).create()
synchronously calls CreateLogStream
which should reject invalid names. Since errors resulting from that call cause New()
to return an error, the container should not actually start running. However, I don't object to local validity checks in the name like this.
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 @samuelkarp for suggesting for doc review. Just a few doc suggestions for the option for consistency with the existing docs.
to a templated name. The template is executed with a [logger.Context](https://godoc.org/github.com/docker/docker/daemon/logger#Context) | ||
as context, so awslogs-stream-template="{{ .ContainerID }}" would be equivelant to the default behavior. | ||
|
||
See the note above with regards to name uniqueness and performance. |
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.
It wouldn't hurt to copy the above note to here, to avoid ambiguity.
@@ -63,6 +63,14 @@ specified, the container ID is used as the log stream. | |||
> at a time. Using the same log stream for multiple containers concurrently | |||
> can cause reduced logging performance. | |||
|
|||
# awslogs-stream-template | |||
|
|||
Configure a [log stream](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchLogs.html) |
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.
You might try something like this:
Specify a template to automatically generate the log stream name to use. The template supports logger.Context, so awslogs-stream-template="{{ .ContainerID }}"
would be equivalent to the default behavior.
068d2cb
to
5ef3a5e
Compare
- fixes moby#17747 - Uses the logging.Context for template context - Add tests, check for conflicting options, gofmt - Add documentation - golint ++ vs += - testing pedantry: 'text/template.ExecError composite literal uses unkeyed fields' in tests per @samuelkarp - Moved location - fixed up log message * ahem. and fix the test - refactor style (explict returns) to match rest of file per @nrdlngr - Documentation clarity improvements - Fix logging link - Remove spurious note Signed-off-by: James Nurmi <[email protected]>
5ef3a5e
to
2dd50e3
Compare
Note copied, text changed as specified - let me know if I've dropped any comments here. |
ping @dnephin @vdemeester PTAL |
fwiw, I believe the windows failure is just a fluke, if someone could retrigger it, I believe this will be passing again. |
ping @dnephin @vdemeester could you review this, in combination with #27480 to see which implementation is best, and what we should to to get these moving? |
@vdemeester @thaJeztah this PR is actually superior over the tags option I could state multiple reasons for this:
I believe the current aws log driver options does not provide any useful implementation for production deployment. The ability to fine tune the logstream |
I ended up needing something similar to 17747 and drafted this guy up - it's a fairly straight-forward implementation, but let me know if I'm missing any style-wants/etc.
There's items it could probably use (strip ':'s from ImageId's comes to mind since they're forbidden by the CW logs API), but hopefully a good enough start for others as well.