-
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
Aws logstream #27707
Aws logstream #27707
Conversation
@FrenchBen Thanks for writing this and thanks for tagging me! At first glance this looks like #25633 and #27480. While many of the log drivers are using |
@samuelkarp Thanks for the quick review. IMHO
|
I do agree with @FrenchBen on the two other PRs. For the naming, same things, I would have liked to keep using Aside from the naming, design LGTM on this one 👼 |
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.
@FrenchBen I'm still not wild about tag
since the primitive here is a log stream, but I think you're right that we could create an awslogs-tags
option if necessary.
@@ -350,6 +355,7 @@ func ValidateLogOpt(cfg map[string]string) error { | |||
case logGroupKey: | |||
case logStreamKey: | |||
case regionKey: | |||
case "tag": |
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.
Any reason this is not a constant? It would be useful to share the constant across all the log drivers that validate option names (maybe loggerutils.TagKey
?).
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.
@samuelkarp that's a good point… not sure why this (and labels
/env
) are not constant. But this could be done in a follow-up PR 👼
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.
Fixed!
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!
@@ -88,7 +89,11 @@ func init() { | |||
// the EC2 Instance Metadata Service. | |||
func New(ctx logger.Context) (logger.Logger, error) { | |||
logGroupName := ctx.Config[logGroupKey] | |||
logStreamName := ctx.ContainerID | |||
logStreamName, err := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate) |
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 you make it a validation error to specify both tag
and awslogs-stream
?
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 don't believe this should trigger an error - Specifying awslogs-stream
with tag
will have no error, as awslogs-stream
is "king" and overwrites the tag specified.
This allows you to update the driver and use the tag specified when no logstream have been specified, but not see any change in currently running containers that have the --log-opt awslogs-stream="someApp"
(keeps this driver backwards compatible)
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.
Is the use-case for setting --log-opt tag="{{.Name}}/{{.ID}}"
(or similar) on the daemon so that it provides the template by default? If so, can we get the docs updated as well?
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.
@samuelkarp that's exactly right, the idea is to set a template on the daemon for all new containers.
I'll make sure to create a PR for the docs to show that tag is now allowed but awslogs-stream
would overwrite the tag.
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 just looked at loggerutils.DefaultTemplate
and it's {{.ID}}
, which would be a change in behavior from the existing driver. Can you use {{.FullID}}
instead to keep the existing behavior?
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.
@FrenchBen Can you change the template to {{.FullID}}
by default so the driver retains its existing behavior?
} | ||
argument := <-mockClient.createLogStreamArgument | ||
|
||
if *argument.LogStreamName != "test-container/container-ab" { |
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.
Is ParseLogTag
enforcing a length limit here? The maximum length of the stream name is 512 characters.
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.
Tag only over-writes the logStreamName
; whatever restrictions were in place before, are still in place.
Essentially I went from taking the default for logStreamName := ctx.ContainerID
to use the default of the tag (which is also ctx.ContainerID
), but adds the flexibility of tag parsing as seen with all other log drivers.
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.
What's shortening "container-abcdefghijklmnopqrstuvwxyz01234567890" to "container-ab"? I would have expected this assertion to be "test-container/container-abcdefghijklmnopqrstuvwxyz01234567890".
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.
Per the docs:
https://docs.docker.com/engine/admin/logging/log_tags/
{{.ID}} The first 12 characters of the container id.
expr length "container-ab"
= 12
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.
Got it. It might be nicer to change the template used for the test to one that doesn't involve truncation (maybe {{.FullID}}
) so it's more obvious what's going on?
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 test came about to mimic the existing logging test found here:
https://github.com/docker/docker/blob/master/daemon/logger/loggerutils/log_tag_test.go#L21
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 don't feel super strongly about this, but having to look in another location to see why it's truncated makes the test more difficult for someone unfamiliar with the codebase to read.
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.
More than happy to update the PR to show the FullID
if that helps getting an LGTM from you ;)
/me tentatively add this to the 1.13.0 milestone 😝 |
@@ -719,6 +719,6 @@ func TestCreateTagSuccess(t *testing.T) { | |||
argument := <-mockClient.createLogStreamArgument | |||
|
|||
if *argument.LogStreamName != "test-container/container-ab" { |
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.
Looks like it's going to fail now because the assertion didn't get updated.
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.
Yup - make it fail, then show that it's working :)
2e7b5d6
to
01da0c6
Compare
@samuelkarp all green! 💚 |
@FrenchBen Are you planning to open a docs PR after this is merged? |
@samuelkarp absolutely! |
@FrenchBen Thanks for opening the docs PR! The only remaining feedback I have is about the default stream name when both |
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.
design LGTM 🐸
Missed the comment - Let me update the PR to reflect that |
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.
LGTM
@FrenchBen can you squash your commits? |
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.
LGTM 🐸 once commit squashed 👼
bfcdbc5
to
183a509
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.
LGTM
thanks for reviewing @samuelkarp!
@FrenchBen It'd be nice to get these into 1 commit. |
@thaJeztah Happy to help! |
oh! I thought it was squashed, darn. @FrenchBen ❤️ |
Signed-off-by: French Ben <[email protected]>
183a509
to
3661510
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.
LGTM
all :green: merging! |
Could anyone explain how to use this new feature with could you share the I did the same as
Here is the log stream name I saw, it doesn't show container id of
I did try these
|
Use |
Thanks a lot, that works.
seems log-opt |
- What I did
Added support for tags to the AWS log driver - The logstream flag will still over-write the tag, allowing for backwards compatibility. The tag parses the regular tag as seen in syslog, etc.
- How I did it
I updated the default of logStream from container ID to use the tag parsing default.
- How to verify it
make test (although I need to add some test for tags passed as flag)
make
- Description for the changelog
Update of AWS log driver to support tags. This enables support for things like
--log-opt tag="{{.ImageName}}/{{.Name}}/{{.ID}}"
as a tag for CloudWatch.- A picture of a cute animal (not mandatory but encouraged)

cc @samuelkarp