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

enhance: add ExtraAttribute functionality in LogInfo #1714

Merged
merged 1 commit into from
Jul 12, 2018
Merged

enhance: add ExtraAttribute functionality in LogInfo #1714

merged 1 commit into from
Jul 12, 2018

Conversation

fuweid
Copy link
Contributor

@fuweid fuweid commented Jul 11, 2018

Signed-off-by: Wei Fu fhfuwei@163.com

Ⅰ. Describe what this PR did

Allow user to consume container's labels and envs data in log file.

Ⅱ. Does this pull request fix one issue?

NONE

Ⅲ. Describe how you did it

Add ExtraAttributes function for Info so that we can use template to consume the data from container.

Ⅳ. Describe how to verify it

pouch run -it \
     --env VERSION=unknown-oops \
     --label from=me \
     --log-driver syslog \
     --log-opt env=VERSION \
     --log-opt labels=from \
     --log-opt "tag={{with .ExtraAttributes nil}}version is {{.VERSION}} from {{.from}}{{end}}" \
     busybox echo hello

We will get the log data in /var/log/syslog

Jul 11 18:00:59 ubuntu-xenial version is unknown-oops from me[6609]: hello

Ⅴ. Special notes for reviews

@codecov-io
Copy link

codecov-io commented Jul 11, 2018

Codecov Report

Merging #1714 into master will increase coverage by 0.09%.
The diff coverage is 71.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1714      +/-   ##
==========================================
+ Coverage   41.18%   41.27%   +0.09%     
==========================================
  Files         274      274              
  Lines       18091    18123      +32     
==========================================
+ Hits         7451     7481      +30     
- Misses       9728     9730       +2     
  Partials      912      912
Impacted Files Coverage Δ
daemon/mgr/container_logger.go 84.61% <100%> (+0.61%) ⬆️
daemon/logger/info.go 53.65% <70.96%> (+53.65%) ⬆️
apis/server/utils.go 61.9% <0%> (-4.77%) ⬇️
ctrd/image.go 80.21% <0%> (+4.94%) ⬆️

extra := make(map[string]string)

// extra specific labels from container labels
labels, ok := i.LogConfig["labels"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question, can we get which key --log-opt support?

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 list available keys

flagSet.StringSliceVar(&c.logOpts, "log-opt", nil, "Log driver options")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected: "APP is <no value>",
hasError: false,
}, {
tag: "{{with .ExtraAttributes nil}}Version is {{.VERSION}}{{end}}",
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 some {{with .ExtraAttributes notnil}} test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the go template doesn't support the function as args, I add other for the ExtractAttributes.

BTW, the definition of ExtracAttributes function which has the keyMod is used to compatible with moby.

Please take a look

Allow user to consume container's labels and envs data in log file.

Signed-off-by: Wei Fu <fhfuwei@163.com>
@pouchrobot pouchrobot added size/XL and removed size/L labels Jul 11, 2018
@Ace-Tang
Copy link
Contributor

lgtm

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Jul 12, 2018
@Ace-Tang Ace-Tang merged commit c83ff22 into AliyunContainerService:master Jul 12, 2018
@fuweid fuweid deleted the enhance_syslog_log_opt branch July 12, 2018 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
areas/log LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants