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

Add Zap logger and access log interceptor #944

Merged
merged 9 commits into from
Jan 25, 2021

Conversation

rinx
Copy link
Contributor

@rinx rinx commented Jan 21, 2021

Description:

This PR is cherry-picked from #852 and revised.

  • Add Zap logger.
  • Revise logger interfaces to add Debugd, Infod, etc...
  • Add logger finalizer method Close()
  • Add AccessLogInterceptor

Related Issue:

nothing

How Has This Been Tested?:

nothing

Environment:

  • Go Version: 1.15.7
  • Docker Version: 19.03.8
  • Kubernetes Version: 1.18.2
  • NGT Version: 1.13.1

Types of changes:

  • Bug fix [type/bug]
  • New feature [type/feature]
  • Add tests [type/test]
  • Security related changes [type/security]
  • Add documents [type/documentation]
  • Refactoring [type/refactoring]
  • Update dependencies [type/dependency]
  • Update benchmarks and performances [type/bench]
  • Update CI [type/ci]

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Checklist:

  • I have read the CONTRIBUTING document.
  • I have checked open Pull Requests for the similar feature or fixes?
  • I have added tests and benchmarks to cover my changes.
  • I have ensured all new and existing tests passed.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly.

@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - add changelog comment
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase master
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

@rinx rinx force-pushed the feature/internal/add-zap-and-access-log-interceptor branch from a333268 to dc740d1 Compare January 21, 2021 08:35
@@ -81,6 +85,10 @@ func (l *logger) Infof(format string, vals ...interface{}) {
l.retry.Outf(l.glg.Infof, format, vals...)
}

func (l *logger) Infod(msg string, details ...interface{}) {
l.Infof(msg+"\tdetails: %#v", 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.

Is this format okay? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

please define default details format as const value on the top

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.

@rinx rinx requested a review from kpango January 21, 2021 08:38
@codecov
Copy link

codecov bot commented Jan 21, 2021

Codecov Report

Merging #944 (98a97da) into master (5df9ec1) will increase coverage by 0.21%.
The diff coverage is 50.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #944      +/-   ##
==========================================
+ Coverage   16.03%   16.25%   +0.21%     
==========================================
  Files         476      479       +3     
  Lines       23839    24016     +177     
==========================================
+ Hits         3822     3903      +81     
- Misses      19772    19867      +95     
- Partials      245      246       +1     
Impacted Files Coverage Δ
internal/log/format/format.go 100.00% <ø> (ø)
internal/log/glg/glg.go 80.48% <0.00%> (-13.80%) ⬇️
internal/log/logger/type.go 100.00% <ø> (ø)
internal/log/mock/logger.go 62.50% <0.00%> (-37.50%) ⬇️
...l/net/grpc/interceptor/server/logging/accesslog.go 0.00% <0.00%> (ø)
internal/log/log.go 81.08% <50.00%> (-18.92%) ⬇️
internal/log/zap/zap.go 85.71% <85.71%> (ø)
internal/log/zap/option.go 100.00% <100.00%> (ø)
internal/runner/runner.go 88.52% <100.00%> (+0.19%) ⬆️
internal/servers/server/option.go 95.31% <100.00%> (+0.15%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5df9ec1...98a97da. Read the comment docs.

Copy link
Collaborator

@kpango kpango left a comment

Choose a reason for hiding this comment

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

I never thought that you implement Infod like klog's InfoS, seems good idea.

@@ -81,6 +85,10 @@ func (l *logger) Infof(format string, vals ...interface{}) {
l.retry.Outf(l.glg.Infof, format, vals...)
}

func (l *logger) Infod(msg string, details ...interface{}) {
l.Infof(msg+"\tdetails: %#v", details)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please define default details format as const value on the top

internal/log/zap/zap.go Show resolved Hide resolved
internal/net/grpc/interceptor/server/logging/accesslog.go Outdated Show resolved Hide resolved
internal/runner/runner.go Outdated Show resolved Hide resolved
@rinx rinx force-pushed the feature/internal/add-zap-and-access-log-interceptor branch 2 times, most recently from d268324 to fc1e535 Compare January 25, 2021 03:12
@kpango
Copy link
Collaborator

kpango commented Jan 25, 2021

can you please check CI (test/internal & golangci-lint)

rinx added 9 commits January 25, 2021 12:32
Signed-off-by: Rintaro Okamura <[email protected]>

:white_check_mark: fix tests for logger type, format

Signed-off-by: Rintaro Okamura <[email protected]>
Signed-off-by: Rintaro Okamura <[email protected]>

:heavy_plus_sign: add zap logger

Signed-off-by: Rintaro Okamura <[email protected]>

:white_check_mark: add zap tests

Signed-off-by: Rintaro Okamura <[email protected]>

:white_check_mark: add zap tests

Signed-off-by: Rintaro Okamura <[email protected]>

:arrow_up: Upgrade zap and revise tests

Signed-off-by: Rintaro Okamura <[email protected]>
Signed-off-by: Rintaro Okamura <[email protected]>

:sparkles: Add Close method to logger implementations

Signed-off-by: Rintaro Okamura <[email protected]>
Signed-off-by: Rintaro Okamura <[email protected]>
Signed-off-by: Rintaro Okamura <[email protected]>
Signed-off-by: Rintaro Okamura <[email protected]>
@rinx rinx force-pushed the feature/internal/add-zap-and-access-log-interceptor branch from fc1e535 to 98a97da Compare January 25, 2021 04:48
"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/log/format"
"github.com/vdaas/vald/internal/log/level"

Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
File is not gci-ed (gci)


type Option func(l *logger)

var (
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
File is not gofumpt-ed (gofumpt)

if err := test.checkFunc(test.want, got, err); err != nil {
tt.Errorf("error = %v", err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
File is not gofumpt-ed (gofumpt)

if err := test.checkFunc(test.want, l, err); err != nil {
tt.Errorf("error = %v", err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
File is not gofumpt-ed (gofumpt)

@@ -76,6 +76,7 @@ func Do(ctx context.Context, opts ...Option) error {

if p.ShowVersion() {
log.Init(log.WithLevel(level.INFO.String()))
defer log.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
Error return value of log.Close is not checked (errcheck)

@@ -95,6 +96,7 @@ func Do(ctx context.Context, opts ...Option) error {
} else {
log.Init()
}
defer log.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
Error return value of log.Close is not checked (errcheck)

@rinx
Copy link
Contributor Author

rinx commented Jan 25, 2021

resolved.

Copy link
Collaborator

@kpango kpango left a comment

Choose a reason for hiding this comment

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

LGTM

@kpango kpango merged commit 93b1cee into master Jan 25, 2021
@kpango kpango deleted the feature/internal/add-zap-and-access-log-interceptor branch January 25, 2021 08:59
@vdaas-ci vdaas-ci mentioned this pull request Jan 29, 2021
18 tasks
@kpango kpango mentioned this pull request Feb 2, 2021
11 tasks
@rinx rinx mentioned this pull request Feb 5, 2021
18 tasks
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.

3 participants