-
Notifications
You must be signed in to change notification settings - Fork 77
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 access log gRPC interceptor & Update observability features #852
Conversation
[CHATOPS:HELP] ChatOps commands.
|
Codecov Report
@@ Coverage Diff @@
## master #852 +/- ##
==========================================
+ Coverage 15.93% 16.05% +0.11%
==========================================
Files 474 475 +1
Lines 23693 23786 +93
==========================================
+ Hits 3776 3818 +42
- Misses 19680 19722 +42
- Partials 237 246 +9
Continue to review full report at Codecov.
|
1663540
to
f7dcc29
Compare
f7dcc29
to
a2329f0
Compare
a2329f0
to
55b731a
Compare
13f0884
to
eb7a89f
Compare
89771b9
to
1444329
Compare
import ( | ||
"github.com/vdaas/vald/internal/log/format" | ||
"github.com/vdaas/vald/internal/log/level" | ||
|
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.
[golangci] reported by reviewdog 🐶
File is not gci
-ed (gci)
type Option func(l *logger) | ||
|
||
var ( | ||
defaultOpts = []Option{ |
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.
[golangci] reported by reviewdog 🐶
defaultOpts
is a global variable (gochecknoglobals)
) | ||
|
||
var ( | ||
zapcore_NewConsoleEncoder = zapcore.NewConsoleEncoder |
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.
[golangci] reported by reviewdog 🐶
zapcore_NewConsoleEncoder
is a global variable (gochecknoglobals)
|
||
var ( | ||
zapcore_NewConsoleEncoder = zapcore.NewConsoleEncoder | ||
zapcore_NewJSONEncoder = zapcore.NewJSONEncoder |
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.
[golangci] reported by reviewdog 🐶
zapcore_NewJSONEncoder
is a global variable (gochecknoglobals)
@@ -0,0 +1,56 @@ | |||
// |
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.
[golangci] reported by reviewdog 🐶
package comment should be of the form "Package zap ..." (golint)
@@ -0,0 +1,189 @@ | |||
// |
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.
[golangci] reported by reviewdog 🐶
package comment should be of the form "Package zap ..." (golint)
} | ||
|
||
// New returns a new logger instance. | ||
func New(opts ...Option) (*logger, error) { |
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.
[golangci] reported by reviewdog 🐶
exported func New returns unexported type *github.com/vdaas/vald/internal/log/zap.logger, which can be annoying to use (golint)
// New returns a new logger instance. | ||
func New(opts ...Option) (*logger, error) { | ||
l := new(logger) | ||
for _, opt := range append(defaultOpts, opts...) { |
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.
[golangci] reported by reviewdog 🐶
ranges should only be cuddled with assignments used in the iteration (wsl)
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package zap |
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.
[golangci] reported by reviewdog 🐶
package should be zap_test
instead of zap
(testpackage)
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package zap |
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.
[golangci] reported by reviewdog 🐶
package should be zap_test
instead of zap
(testpackage)
0402bb6
to
1f66615
Compare
f699079
to
ee598eb
Compare
ad99d8b
to
df36f12
Compare
l.logger = zap.New(core, opts...) | ||
|
||
l.sugar = l.logger.Sugar() |
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 think we should be define finelizer for logger & sugar.
zap has internal buffering we should call .Sync() method when application exits
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.
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]>
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]>
Signed-off-by: Rintaro Okamura <[email protected]>
Signed-off-by: Rintaro Okamura <[email protected]>
|
||
resp, err = handler(ctx, req) | ||
|
||
latency := float64(time.Since(start)) / float64(time.Second) |
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 think it would be better to store time as unix nano second scale.
then we can calculate it on the monitoring query
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.
okay i'll revise it.
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.
thank you!
Signed-off-by: Rintaro Okamura <[email protected]> :wrench: update Grafana dashboards & Prometheus config Signed-off-by: Rintaro Okamura <[email protected]> :pencil2: Use same rule for task naming 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]>
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.
Others LGTM
entity.Error = err | ||
log.Error("rpc completed", entity) | ||
} else { | ||
log.Info("rpc completed", entity) |
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 think debug is better
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.
AccessLogInterceptor is disabled by default, so i think it is okay to use Info level here.
I think it is too many logs when turning on Debug logs (such as Agent's CreateIndex operation log). it is better to put access logs in different level compared to them.
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.
If there is a lot of access, it will be difficult to get other Info logs according to the number of accesses, so I think this Interceptor is used for Debug, I think Debug is fine.
The Info log should contain more important information, and I think it is too much to output every successful access.
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.
The users of this AccessLogInterceptor will use Loki or something to query the aggregated logs. so there's no problem if there is a lot of accesses.
If access logs is Debug level, it is bigger problem that meaningless Debug level logs require large storage capacity to store them.
Also I think it is correct according to contributing guide. https://github.com/vdaas/vald/blob/master/docs/contributing/coding-style.md#logging
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.
hmm, but I'd like to divide trace log and Info log, so how about make new log level called TRACE?
|
||
if err != nil { | ||
entity.Error = err | ||
log.Error("rpc completed", entity) |
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.
may be you want print entity on error log right?
so, entity print should be %#v print pragma because of entity is pointer type , error log will show thier address only...
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.
We should use log.Error
instead of log.Errorf
here because Zap logger prints the second argument as the "details"
field.
https://pkg.go.dev/go.uber.org/zap#Logger.Info
Please see the description of this PR. There's an example.
So you know, there's a known problem (as described in the description) when using Glg logger.
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.
Since the log.Error interface is independent of zap, it should not be implemented to work only with zap.
Even if we specify a standard Go logger here, if the group of arguments is the same interface, the address will be displayed as in Glg.
I think it would be more appropriate to consider a more explicit Print method, but I'm not sure.
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.
hmm...
I don't know how to print correctly structured JSON logs with that format without using log.Error
.
Okay, I'll close this 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.
wait, you don't need to close this pr.
let's discuss about it.
this pr feature is really effective.
Signed-off-by: Rintaro Okamura <[email protected]>
Signed-off-by: Rintaro Okamura <[email protected]>
df36f12
to
3e558e5
Compare
Description:
Changes
server_config.servers.grpc.server.grpc.interceptors
field in config.yaml, it will be enabled.Add zap logger
Update Grafana dashboards
Add values-observability-demo.yaml to charts/vald
Known problem
Related Issue:
nothing
How Has This Been Tested?:
nothing
Environment:
Types of changes:
Changes to Core Features:
Checklist: