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

feature: add logs cli details opt support and add more cli tests #2261

Merged
merged 1 commit into from
Oct 16, 2018

Conversation

ZYecho
Copy link
Contributor

@ZYecho ZYecho commented Sep 20, 2018

Signed-off-by: zhangyue [email protected]

Ⅰ. Describe what this PR did

As title mentioned, as two parts:

  1. add pouch logs --details support
  2. add more logs cli integration tests

Ⅱ. Does this pull request fix one issue?

None.

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

add more cli integration test.

Ⅳ. Describe how to verify it

$ pouch run --name=test --label foo=bar -e baz=qux -e qq=we --log-opt labels=foo --log-opt env=baz,qq busybox echo hello
Run
$ pouch logs --details test
Got
baz=qux qq=we foo=bar hello

Ⅴ. Special notes for reviews

None.

@codecov
Copy link

codecov bot commented Sep 20, 2018

Codecov Report

Merging #2261 into master will increase coverage by 0.01%.
The diff coverage is 90.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2261      +/-   ##
==========================================
+ Coverage   67.25%   67.26%   +0.01%     
==========================================
  Files         213      213              
  Lines       17482    17511      +29     
==========================================
+ Hits        11757    11779      +22     
- Misses       4326     4329       +3     
- Partials     1399     1403       +4
Flag Coverage Δ
#criv1alpha1test 32.05% <29.26%> (-0.24%) ⬇️
#criv1alpha2test 36.38% <29.26%> (+0.17%) ⬆️
#integrationtest 40.07% <90.24%> (+0.06%) ⬆️
#nodee2etest 33.6% <29.26%> (+0.08%) ⬆️
#unittest 23.2% <39.02%> (ø) ⬆️
Impacted Files Coverage Δ
daemon/logger/logmessage.go 100% <ø> (ø) ⬆️
daemon/logger/jsonfile/encode.go 81.52% <100%> (+1.06%) ⬆️
apis/server/container_bridge.go 83.89% <100%> (+0.04%) ⬆️
apis/server/utils.go 71.15% <100%> (+4.48%) ⬆️
daemon/mgr/container_logs.go 84.41% <100%> (+0.2%) ⬆️
daemon/logger/jsonfile/jsonfile.go 78.37% <100%> (+0.6%) ⬆️
daemon/containerio/jsonfile.go 71.95% <66.66%> (-1.29%) ⬇️
cri/stream/httpstream/spdy/upgrade.go 54.28% <0%> (-5.72%) ⬇️
ctrd/watch.go 75.75% <0%> (-4.55%) ⬇️
... and 11 more

return err
}

if c.HostConfig.LogConfig.LogOpts != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the detail should be done in daemon/logger/logmessage.go, because the we don't want to split the logic into api bridge and daemon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK I try to change it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@ZYecho
Copy link
Contributor Author

ZYecho commented Sep 26, 2018

@fuweid Any echo about the update?

@@ -136,10 +140,52 @@ func convContainerLogsOptionsToReadConfig(logOpt *types.ContainerLogsOptions) (*
lines = -1
}

var logDetailBuffer bytes.Buffer
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, the tag information should be written into the json file.

}, nil
}

func buildLogDetailStr(tags string, config map[string]string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

daemon/logger/loggerutils/tag.go:GenerateLogTag maybe can help you

@allencloud
Copy link
Collaborator

Any update on this pull request? @ZYecho
I think it is quite useful for pouch.

@ZYecho
Copy link
Contributor Author

ZYecho commented Oct 9, 2018

Any update on this pull request? @ZYecho
I think it is quite useful for pouch.

Sorry for the delay, because of the holiday you know. Today I'll update.

var extra []byte
if len(attrs) > 0 {
var err error
extra, err = json.Marshal(attrs)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can't write one line with json.Marshal here. it's too expensive. since the attrs value is static, could we marshal it before start logging?

keyJ := strings.Split(ss[j], "=")
return keyI[0] < keyJ[0]
})
logLine = append([]byte(strings.Join(ss, ",")+" "), logLine...)
Copy link
Contributor

@zhuangqh zhuangqh Oct 15, 2018

Choose a reason for hiding this comment

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

There is a redundant space before log string if msg.Attrs is empty.
change the condition to if opt.Details && len(msg.Attrs) > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

out := suite.syncLogs(c, cname, "--details")
c.Assert(len(out), check.Equals, 1)
logFields := strings.Split(out[0], " ")

Copy link
Contributor

Choose a reason for hiding this comment

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

add a negative case: empty log option, but run pouch logs with --details

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@allencloud
Copy link
Collaborator

Does the update meet your request? @zhuangqh

@zhuangqh
Copy link
Contributor

Does the update meet your request? @zhuangqh

LGTM but waiting for the CI.

@allencloud
Copy link
Collaborator

I retrigger the cri-tools CI to re-run it.

@allencloud
Copy link
Collaborator

Since all the CI passes, we will merge this. Thanks again for your great work. @ZYecho

@allencloud allencloud merged commit 871085a into AliyunContainerService:master Oct 16, 2018
@ZYecho ZYecho deleted the add-logs-detail branch November 6, 2018 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants