Skip to content
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

awslogs driver support for variables using template markup in awslogs-stream #17747

Closed
CameronGo opened this issue Nov 6, 2015 · 16 comments
Closed
Labels
area/logging kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. version/1.9

Comments

@CameronGo
Copy link

This is a feature request to allow the use of specific variables or the template markup syntax when specifying the awslogs-stream option. The current implementation allows you to use a static value for awslogs-stream or else by default it uses the long container ID. The container ID alone can be difficult to trace and associate with a specific host, so I would like to be able to specify get both the docker hosts hostname along with the short container ID using something like the following:
docker run --log-driver=awslogs --log-opt awslogs-region=us-east-1
--log-opt awslogs-group="hello-world"
--log-opt awslogs-stream="$HOSTNAME-{{.ID}}"
hello-world

docker version:
Client:
Version: 1.9.0
API version: 1.21
Go version: go1.4.2
Git commit: 76d6bc9
Built: Tue Nov 3 17:43:42 UTC 2015
OS/Arch: linux/amd64

Server:
Version: 1.9.0
API version: 1.21
Go version: go1.4.2
Git commit: 76d6bc9
Built: Tue Nov 3 17:43:42 UTC 2015
OS/Arch: linux/amd64

docker info:
Containers: 8
Images: 2
Server Version: 1.9.0
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 18
Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.13.0-43-generic
Operating System: Ubuntu 14.04.2 LTS
CPUs: 1
Total Memory: 992.5 MiB
Name: chlorine
ID: DG52:Y3T4:2BGU:HRHN:TVQK:IFII:X26U:V733:VHX3:YU7Z:ZSRC:4UQI

uname -a:
Linux chlorine 3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Environment:
AWS EC2 Container Services running on custom Ubuntu AMI with ecs-agent container.

@CameronGo CameronGo changed the title awslogs driver support for template markup in awslogs-stream awslogs driver support for variables using template markup in awslogs-stream Nov 6, 2015
@ianneub
Copy link

ianneub commented Nov 21, 2015

@samuelkarp I also want this feature, so I started to look at how it could be implemented. The other loggers use the function loggerutils.ParseLogTag in order to render the user provided template. Unfortunately this function will work only with the logger config option named tag, and will not check awslogs-stream.

Here is the relevant portion of the awslogs driver:
https://github.com/docker/docker/blob/692bfdaee3b48f4e5174bb80098692a0ded1aecf/daemon/logger/awslogs/cloudwatchlogs.go#L92

This shows how the syslog driver uses loggerutils.ParseLogTag:
https://github.com/docker/docker/blob/692bfdaee3b48f4e5174bb80098692a0ded1aecf/daemon/logger/syslog/syslog.go#L65

And here is the source for loggerutils.ParseLogTag:
https://github.com/docker/docker/blob/692bfdaee3b48f4e5174bb80098692a0ded1aecf/daemon/logger/loggerutils/log_tag.go#L14

Here are the docs for tag in the other drivers:
https://docs.docker.com/engine/reference/logging/log_tags/

What do you think a good way to handle this situation would be? Here are some ideas:

  1. We can change the config option awslogs-stream to tag.
  2. We can also allow a user to specify tag which will overwrite awslogs-stream.
  3. We can rewrite loggerutils.ParseLogTag to allow specifying the option name to use.
  4. We can write/duplicate the loggerutils.ParseLogTag code inside awslogs driver and hard code it to use the awslogs-stream.

What do you think?

@thaJeztah thaJeztah added area/logging kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels Nov 23, 2015
@samuelkarp
Copy link
Member

@ianneub, thanks for pinging me.

Of your ideas, I'd lean toward number 3. Tags have a different meaning for many AWS resources, so I'd prefer to avoid introducing the potential for confusion.

@jhovell
Copy link

jhovell commented Apr 15, 2016

+1

I'd also add the ability to use log tags in awslogs-group as well as awslogs-stream.

Are there any known workarounds for this limitation? Given awslog-streams should be unique per running container, I don't see any way to effectively override awslogs-stream.

ECS task definitions don't really have enough context to specify log groups / streams effectively (e.g. you likely want different log groups for different environments or stacks)

@CameronGo
Copy link
Author

This one has been quiet for a while. I see a version/1.9 label applied, though I don't see any comments in that or any subsequent releases about this functionality. The documentation doesn't seem to indicate any different behavior for the awslogs driver and my test using the log-opt tag on version 1.10.1 is not supported with the awslogs driver. Does anyone know what the status is or future plans?

@cpuguy83
Copy link
Member

cpuguy83 commented Jun 7, 2016

@CameronGo This would most likely have to be coded up by someone who wants this feature.
Right off the bat, I can say the syntax is not likely to be accepted, but I do believe we have support for go-template thin these options, and that would be the place to start.

@thaJeztah
Copy link
Member

@CameronGo the "1.9" label is automatically applied, based on the version an issue was reported with (in the top description)

@PeterRJones
Copy link

+1 for this feature

1 similar comment
@mgpotter
Copy link

mgpotter commented Sep 6, 2016

+1 for this feature

@samuelkarp
Copy link
Member

@CameronGo @jhovell (any anyone else using ECS) We just added the ability to specify a stream prefix in the ECS task definition as awslogs-stream-prefix (the full stream name ends up being $prefix/$container-name/$task-id). See this blog post and our documentation for details.

jdnurmi pushed a commit to jdnurmi/docker that referenced this issue Sep 29, 2016
- 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]>
@thaJeztah
Copy link
Member

@samuelkarp @CameronGo #27707 was merged, does that satisfy this feature request?

@samuelkarp
Copy link
Member

@thaJeztah Yes, I believe so.

@thaJeztah
Copy link
Member

Thanks @samuelkarp, I'll go ahead and close this issue, but @CameronGo let me know if there's still something that needs to be addressed 👍

@CameronGo
Copy link
Author

Thanks @thaJeztah - yes that is working and fits my needs. Thanks for checking!

@thaJeztah
Copy link
Member

Good to hear @CameronGo!

@ghost
Copy link

ghost commented Apr 24, 2017

Sorry, but this is not really fixed. Im using the prefix, and its alot better. thx!.

But i still got about 12 log streams, because they a grouped by the service ID.

DOMAIN/stage-DOMAIN/273ac3de-0bca-4bee-a35b-9e0206009380
DOMAIN/stage-DOMAIN/324c52f3-0f5c-4063-8b03-b490885aef3c
DOMAIN/stage-DOMAIN/355251f2-4e7f-4837-86c5-f2f187bf509c
DOMAIN/stage-DOMAIN/4cbd1975-3aad-46e5-a8bd-3241f2233bd0
DOMAIN/stage-DOMAIN/5cc3307b-c5ac-4f1c-9421-f2d2f1f9b0f6
DOMAIN/stage-DOMAIN/62b4cccf-c4a6-474e-8478-58912977168f
DOMAIN/stage-DOMAIN/71e60952-ce6d-4f8b-a901-445b811f6165
...

In an debugging situation, i need to click on all stream to find the error..

@ozbillwang
Copy link
Contributor

ozbillwang commented Jul 23, 2020

@ghost

could you share the docker run command and docker version?

I did the same as --log-opt awslogs-stream="$HOSTNAME-{{.ID}}", but I didn't get the docker container id properly.

docker run --log-driver=awslogs --log-opt awslogs-region=ap-southeast-2
  --log-opt awslogs-create-group=true
  --log-opt awslogs-group="hello-world"
  --log-opt awslogs-stream="$HOSTNAME-{{.ID}}"
  hello-world

Here is the log stream name I saw, it doesn't show container id of {{.ID}}

ip-10-0-2-123.ap-southeast-2.compute.internal-{{.ID}}

I did try these log_tags one by one, seems no one works.

https://docs.docker.com/config/containers/logging/log_tags/

{{.ID}} | The first 12 characters of the container ID.
{{.FullID}} | The full container ID.
{{.Name}} | The container name.
{{.ImageID}} | The first 12 characters of the container’s image ID.
{{.ImageFullID}} | The container’s full image ID.
{{.ImageName}} | The name of the image used by the container.
{{.DaemonName}} | The name of the docker program (docker).

Updates

I fixed to replace awslogs-stream with tag, they can't be used together.

  --log-opt tag="$HOSTNAME-{{.ID}}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. version/1.9
Projects
None yet
Development

No branches or pull requests

10 participants