diff --git a/go.mod b/go.mod index d911e25dd..479b279b0 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/gogo/status v1.1.1 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 - github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/lib/pq v1.10.9 github.com/pkg/errors v0.9.1 github.com/puzpuzpuz/xsync/v2 v2.4.1 diff --git a/go.sum b/go.sum index 3b4785468..97975a123 100644 --- a/go.sum +++ b/go.sum @@ -253,8 +253,6 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw= -github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 h1:BZHcxBETFHIdVyhyEfOvn/RdU/QGdLI4y34qQGjGWO0= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= @@ -361,7 +359,6 @@ github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= -github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= @@ -519,17 +516,14 @@ go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLk go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME= go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -808,7 +802,6 @@ google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= diff --git a/internal/admin/admin.go b/internal/admin/admin.go index 2588ee739..413aac41a 100644 --- a/internal/admin/admin.go +++ b/internal/admin/admin.go @@ -9,9 +9,6 @@ import ( "github.com/gogo/protobuf/proto" "github.com/gogo/status" - grpcmiddleware "github.com/grpc-ecosystem/go-grpc-middleware" - grpczap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" - grpcctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags" "github.com/pkg/errors" "go.uber.org/multierr" "go.uber.org/zap" @@ -21,6 +18,7 @@ import ( "google.golang.org/grpc/health/grpc_health_v1" "github.com/kakao/varlog/internal/admin/snwatcher" + "github.com/kakao/varlog/pkg/rpc/interceptors/logging" "github.com/kakao/varlog/pkg/types" "github.com/kakao/varlog/pkg/util/netutil" "github.com/kakao/varlog/pkg/verrors" @@ -72,13 +70,8 @@ func New(ctx context.Context, opts ...Option) (*Admin, error) { } grpcServer := grpc.NewServer( - grpcmiddleware.WithUnaryServerChain( - grpcctxtags.UnaryServerInterceptor(), - grpczap.UnaryServerInterceptor(cfg.logger, grpczap.WithDecider( - func(fullMethodName string, err error) bool { - return err != nil || !grpcHandlerLogDenyList[fullMethodName] - }, - )), + grpc.ChainUnaryInterceptor( + logging.UnaryServerInterceptor(cfg.logger), ), ) diff --git a/internal/storagenode/storagenode.go b/internal/storagenode/storagenode.go index cb55122a9..1eed68edf 100644 --- a/internal/storagenode/storagenode.go +++ b/internal/storagenode/storagenode.go @@ -3,7 +3,6 @@ package storagenode import ( "context" "errors" - "fmt" "net" "net/http" "os" @@ -13,7 +12,6 @@ import ( "sync/atomic" "time" - "github.com/gogo/status" "github.com/puzpuzpuz/xsync/v2" "github.com/soheilhy/cmux" "go.opentelemetry.io/otel" @@ -32,6 +30,7 @@ import ( "github.com/kakao/varlog/internal/storagenode/pprof" "github.com/kakao/varlog/internal/storagenode/telemetry" "github.com/kakao/varlog/internal/storagenode/volume" + "github.com/kakao/varlog/pkg/rpc/interceptors/logging" "github.com/kakao/varlog/pkg/types" "github.com/kakao/varlog/pkg/util/fputil" "github.com/kakao/varlog/pkg/util/netutil" @@ -105,21 +104,8 @@ func NewStorageNode(opts ...Option) (*StorageNode, error) { grpc.ReadBufferSize(int(cfg.grpcServerReadBufferSize)), grpc.WriteBufferSize(int(cfg.grpcServerWriteBufferSize)), grpc.MaxRecvMsgSize(int(cfg.grpcServerMaxRecvMsgSize)), - grpc.UnaryInterceptor( - func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - start := time.Now() - resp, err := handler(ctx, req) - if err != nil { - duration := time.Since(start) - cfg.logger.Error(info.FullMethod, - zap.Stringer("code", status.Code(err)), - zap.Int64("duration", duration.Microseconds()), - zap.Stringer("request", req.(fmt.Stringer)), - zap.Error(err), - ) - } - return resp, err - }, + grpc.ChainUnaryInterceptor( + logging.UnaryServerInterceptor(cfg.logger), ), } if opt := cfg.grpcServerInitialConnWindowSize; opt.set { diff --git a/pkg/rpc/interceptors/logging/interceptor.go b/pkg/rpc/interceptors/logging/interceptor.go new file mode 100644 index 000000000..2137aa4fb --- /dev/null +++ b/pkg/rpc/interceptors/logging/interceptor.go @@ -0,0 +1,57 @@ +package logging + +import ( + "context" + "fmt" + "net" + "time" + + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/status" +) + +// UnaryServerInterceptor returns a new unary server interceptor that logs a +// gRPC error. +func UnaryServerInterceptor(logger *zap.Logger) grpc.UnaryServerInterceptor { + if logger == nil { + return func(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { + return handler(ctx, req) + } + } + + return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { + start := time.Now() + resp, err = handler(ctx, req) + if err != nil { + duration := time.Since(start) + logger.Error(info.FullMethod, + zap.Stringer("code", status.Code(err)), + zap.Duration("duration", duration), + zap.Stringer("request", req.(fmt.Stringer)), + zap.Stringer("response", resp.(fmt.Stringer)), + zap.String("peer", peerAddr(ctx)), + zap.Error(err), + ) + } + return resp, err + } +} + +func peerAddr(ctx context.Context) string { + p, ok := peer.FromContext(ctx) + if !ok { + return "" + } + + host, _, err := net.SplitHostPort(p.Addr.String()) + if err != nil { + return "" + } + + if host == "" { + return "127.0.0.1" + } + return host +} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/.gitignore b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/.gitignore deleted file mode 100644 index 826caa390..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/.gitignore +++ /dev/null @@ -1,204 +0,0 @@ -# Created by .ignore support plugin (hsz.mobi) -### Go template -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof -### Windows template -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk -### Kate template -# Swap Files # -.*.kate-swp -.swp.* -### SublimeText template -# cache files for sublime text -*.tmlanguage.cache -*.tmPreferences.cache -*.stTheme.cache - -# workspace files are user-specific -*.sublime-workspace - -# project files should be checked into the repository, unless a significant -# proportion of contributors will probably not be using SublimeText -# *.sublime-project - -# sftp configuration file -sftp-config.json -### Linux template -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea -.idea/tasks.xml -.idea/dictionaries -.idea/vcs.xml -.idea/jsLibraryMappings.xml - -# Sensitive or high-churn files: -.idea/dataSources.ids -.idea/dataSources.xml -.idea/dataSources.local.xml -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml - -# Gradle: -.idea/gradle.xml -.idea/libraries - -# Mongo Explorer plugin: -.idea/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties -### Xcode template -# Xcode -# -# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore - -## Build generated -build/ -DerivedData/ - -## Various settings -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 -xcuserdata/ - -## Other -*.moved-aside -*.xccheckout -*.xcscmblueprint -### Eclipse template - -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# Eclipse Core -.project - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - - -coverage.txt - -#vendor -vendor/ - -.envrc \ No newline at end of file diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/.travis.yml b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/.travis.yml deleted file mode 100644 index fc198d882..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -sudo: false -language: go -go: - - 1.13.x - - 1.14.x - - 1.15.x - -env: - global: - - GO111MODULE=on - -script: - - make test - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/CHANGELOG.md b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/CHANGELOG.md deleted file mode 100644 index 6eeb7e2dc..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/CHANGELOG.md +++ /dev/null @@ -1,51 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - -Types of changes: -- `Added` for new features. -- `Changed` for changes in existing functionality. -- `Deprecated` for soon-to-be removed features. -- `Removed` for now removed features. -- `Fixed` for any bug fixes. -- `Security` in case of vulnerabilities. - -## [Unreleased] - -### Added - -- [#223](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/223) Add go-kit logging middleware - [adrien-f](https://github.com/adrien-f) - -## [v1.1.0] - 2019-09-12 -### Added -- [#226](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/226) Support for go modules. -- [#221](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/221) logging/zap add support for gRPC LoggerV2 - [kush-patel-hs](https://github.com/kush-patel-hs) -- [#181](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/181) Rate Limit support - [ceshihao](https://github.com/ceshihao) -- [#161](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/161) Retry on server stream call - [lonnblad](https://github.com/lonnblad) -- [#152](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/152) Exponential backoff functions - [polyfloyd](https://github.com/polyfloyd) -- [#147](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/147) Jaeger support for ctxtags extraction - [vporoshok](https://github.com/vporoshok) -- [#184](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/184) ctxTags identifies if the call was sampled - -### Deprecated -- [#201](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/201) `golang.org/x/net/context` - [houz42](https://github.com/houz42) -- [#183](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/183) Documentation Generation in favour of . - -### Fixed -- [172](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/172) Passing ctx into retry and recover - [johanbrandhorst](https://github.com/johanbrandhorst) -- Numerious documentation fixes. - -## v1.0.0 - 2018-05-08 -### Added -- grpc_auth -- grpc_ctxtags -- grpc_zap -- grpc_logrus -- grpc_opentracing -- grpc_retry -- grpc_validator -- grpc_recovery - -[Unreleased]: https://github.com/grpc-ecosystem/go-grpc-middleware/compare/v1.1.0...HEAD -[v1.1.0]: https://github.com/grpc-ecosystem/go-grpc-middleware/compare/v1.0.0...v1.1.0 diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/CONTRIBUTING.md b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/CONTRIBUTING.md deleted file mode 100644 index dd52ab893..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/CONTRIBUTING.md +++ /dev/null @@ -1,20 +0,0 @@ -# Contributing - -We would love to have people submit pull requests and help make `grpc-ecosystem/go-grpc-middleware` even better 👍. - -Fork, then clone the repo: - -```bash -git clone git@github.com:your-username/go-grpc-middleware.git -``` - -Before checking in please run the following: - -```bash -make all -``` - -This will `vet`, `fmt`, regenerate documentation and run all tests. - - -Push to your fork and open a pull request. \ No newline at end of file diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/LICENSE b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/LICENSE deleted file mode 100644 index b2b065037..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/README.md b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/README.md deleted file mode 100644 index 814e15517..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/README.md +++ /dev/null @@ -1,86 +0,0 @@ -# Go gRPC Middleware - -[![Travis Build](https://travis-ci.org/grpc-ecosystem/go-grpc-middleware.svg?branch=master)](https://travis-ci.org/grpc-ecosystem/go-grpc-middleware) -[![Go Report Card](https://goreportcard.com/badge/github.com/grpc-ecosystem/go-grpc-middleware)](https://goreportcard.com/report/github.com/grpc-ecosystem/go-grpc-middleware) -[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/grpc-ecosystem/go-grpc-middleware) -[![SourceGraph](https://sourcegraph.com/github.com/grpc-ecosystem/go-grpc-middleware/-/badge.svg)](https://sourcegraph.com/github.com/grpc-ecosystem/go-grpc-middleware/?badge) -[![codecov](https://codecov.io/gh/grpc-ecosystem/go-grpc-middleware/branch/master/graph/badge.svg)](https://codecov.io/gh/grpc-ecosystem/go-grpc-middleware) -[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) -[![quality: production](https://img.shields.io/badge/quality-production-orange.svg)](#status) -[![Slack](https://img.shields.io/badge/slack-%23grpc--middleware-brightgreen)](https://slack.com/share/IRUQCFC23/9Tm7hxRFVKKNoajQfMOcUiIk/enQtODc4ODI4NTIyMDcxLWM5NDA0ZTE4Njg5YjRjYWZkMTI5MzQwNDY3YzBjMzE1YzdjOGM5ZjI1NDNiM2JmNzI2YjM5ODE5OTRiNTEyOWE) - -[gRPC Go](https://github.com/grpc/grpc-go) Middleware: interceptors, helpers, utilities. - -## Middleware - -[gRPC Go](https://github.com/grpc/grpc-go) recently acquired support for -Interceptors, i.e. [middleware](https://medium.com/@matryer/writing-middleware-in-golang-and-how-go-makes-it-so-much-fun-4375c1246e81#.gv7tdlghs) -that is executed either on the gRPC Server before the request is passed onto the user's application logic, or on the gRPC client around the user call. It is a perfect way to implement -common patterns: auth, logging, message, validation, retries or monitoring. - -These are generic building blocks that make it easy to build multiple microservices easily. -The purpose of this repository is to act as a go-to point for such reusable functionality. It contains -some of them itself, but also will link to useful external repos. - -`grpc_middleware` itself provides support for chaining interceptors, here's an example: - -```go -import "github.com/grpc-ecosystem/go-grpc-middleware" - -myServer := grpc.NewServer( - grpc.StreamInterceptor(grpc_middleware.ChainStreamServer( - grpc_recovery.StreamServerInterceptor(), - grpc_ctxtags.StreamServerInterceptor(), - grpc_opentracing.StreamServerInterceptor(), - grpc_prometheus.StreamServerInterceptor, - grpc_zap.StreamServerInterceptor(zapLogger), - grpc_auth.StreamServerInterceptor(myAuthFunction), - )), - grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( - grpc_recovery.UnaryServerInterceptor(), - grpc_ctxtags.UnaryServerInterceptor(), - grpc_opentracing.UnaryServerInterceptor(), - grpc_prometheus.UnaryServerInterceptor, - grpc_zap.UnaryServerInterceptor(zapLogger), - grpc_auth.UnaryServerInterceptor(myAuthFunction), - )), -) -``` - -## Interceptors - -*Please send a PR to add new interceptors or middleware to this list* - -#### Auth - * [`grpc_auth`](auth) - a customizable (via `AuthFunc`) piece of auth middleware - -#### Logging - * [`grpc_ctxtags`](tags/) - a library that adds a `Tag` map to context, with data populated from request body - * [`grpc_zap`](logging/zap/) - integration of [zap](https://github.com/uber-go/zap) logging library into gRPC handlers. - * [`grpc_logrus`](logging/logrus/) - integration of [logrus](https://github.com/sirupsen/logrus) logging library into gRPC handlers. - * [`grpc_kit`](logging/kit/) - integration of [go-kit](https://github.com/go-kit/kit/tree/master/log) logging library into gRPC handlers. - * [`grpc_grpc_logsettable`](logging/settable/) - a wrapper around `grpclog.LoggerV2` that allows to replace loggers in runtime (thread-safe). - -#### Monitoring - * [`grpc_prometheus`⚡](https://github.com/grpc-ecosystem/go-grpc-prometheus) - Prometheus client-side and server-side monitoring middleware - * [`otgrpc`⚡](https://github.com/grpc-ecosystem/grpc-opentracing/tree/master/go/otgrpc) - [OpenTracing](http://opentracing.io/) client-side and server-side interceptors - * [`grpc_opentracing`](tracing/opentracing) - [OpenTracing](http://opentracing.io/) client-side and server-side interceptors with support for streaming and handler-returned tags - -#### Client - * [`grpc_retry`](retry/) - a generic gRPC response code retry mechanism, client-side middleware - -#### Server - * [`grpc_validator`](validator/) - codegen inbound message validation from `.proto` options - * [`grpc_recovery`](recovery/) - turn panics into gRPC errors - * [`ratelimit`](ratelimit/) - grpc rate limiting by your own limiter - - -## Status - -This code has been running in *production* since May 2016 as the basis of the gRPC micro services stack at [Improbable](https://improbable.io). - -Additional tooling will be added, and contributions are welcome. - -## License - -`go-grpc-middleware` is released under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details. diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/chain.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/chain.go deleted file mode 100644 index ea3738b89..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/chain.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2016 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -// gRPC Server Interceptor chaining middleware. - -package grpc_middleware - -import ( - "context" - - "google.golang.org/grpc" -) - -// ChainUnaryServer creates a single interceptor out of a chain of many interceptors. -// -// Execution is done in left-to-right order, including passing of context. -// For example ChainUnaryServer(one, two, three) will execute one before two before three, and three -// will see context changes of one and two. -func ChainUnaryServer(interceptors ...grpc.UnaryServerInterceptor) grpc.UnaryServerInterceptor { - n := len(interceptors) - - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - chainer := func(currentInter grpc.UnaryServerInterceptor, currentHandler grpc.UnaryHandler) grpc.UnaryHandler { - return func(currentCtx context.Context, currentReq interface{}) (interface{}, error) { - return currentInter(currentCtx, currentReq, info, currentHandler) - } - } - - chainedHandler := handler - for i := n - 1; i >= 0; i-- { - chainedHandler = chainer(interceptors[i], chainedHandler) - } - - return chainedHandler(ctx, req) - } -} - -// ChainStreamServer creates a single interceptor out of a chain of many interceptors. -// -// Execution is done in left-to-right order, including passing of context. -// For example ChainUnaryServer(one, two, three) will execute one before two before three. -// If you want to pass context between interceptors, use WrapServerStream. -func ChainStreamServer(interceptors ...grpc.StreamServerInterceptor) grpc.StreamServerInterceptor { - n := len(interceptors) - - return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - chainer := func(currentInter grpc.StreamServerInterceptor, currentHandler grpc.StreamHandler) grpc.StreamHandler { - return func(currentSrv interface{}, currentStream grpc.ServerStream) error { - return currentInter(currentSrv, currentStream, info, currentHandler) - } - } - - chainedHandler := handler - for i := n - 1; i >= 0; i-- { - chainedHandler = chainer(interceptors[i], chainedHandler) - } - - return chainedHandler(srv, ss) - } -} - -// ChainUnaryClient creates a single interceptor out of a chain of many interceptors. -// -// Execution is done in left-to-right order, including passing of context. -// For example ChainUnaryClient(one, two, three) will execute one before two before three. -func ChainUnaryClient(interceptors ...grpc.UnaryClientInterceptor) grpc.UnaryClientInterceptor { - n := len(interceptors) - - return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - chainer := func(currentInter grpc.UnaryClientInterceptor, currentInvoker grpc.UnaryInvoker) grpc.UnaryInvoker { - return func(currentCtx context.Context, currentMethod string, currentReq, currentRepl interface{}, currentConn *grpc.ClientConn, currentOpts ...grpc.CallOption) error { - return currentInter(currentCtx, currentMethod, currentReq, currentRepl, currentConn, currentInvoker, currentOpts...) - } - } - - chainedInvoker := invoker - for i := n - 1; i >= 0; i-- { - chainedInvoker = chainer(interceptors[i], chainedInvoker) - } - - return chainedInvoker(ctx, method, req, reply, cc, opts...) - } -} - -// ChainStreamClient creates a single interceptor out of a chain of many interceptors. -// -// Execution is done in left-to-right order, including passing of context. -// For example ChainStreamClient(one, two, three) will execute one before two before three. -func ChainStreamClient(interceptors ...grpc.StreamClientInterceptor) grpc.StreamClientInterceptor { - n := len(interceptors) - - return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { - chainer := func(currentInter grpc.StreamClientInterceptor, currentStreamer grpc.Streamer) grpc.Streamer { - return func(currentCtx context.Context, currentDesc *grpc.StreamDesc, currentConn *grpc.ClientConn, currentMethod string, currentOpts ...grpc.CallOption) (grpc.ClientStream, error) { - return currentInter(currentCtx, currentDesc, currentConn, currentMethod, currentStreamer, currentOpts...) - } - } - - chainedStreamer := streamer - for i := n - 1; i >= 0; i-- { - chainedStreamer = chainer(interceptors[i], chainedStreamer) - } - - return chainedStreamer(ctx, desc, cc, method, opts...) - } -} - -// Chain creates a single interceptor out of a chain of many interceptors. -// -// WithUnaryServerChain is a grpc.Server config option that accepts multiple unary interceptors. -// Basically syntactic sugar. -func WithUnaryServerChain(interceptors ...grpc.UnaryServerInterceptor) grpc.ServerOption { - return grpc.UnaryInterceptor(ChainUnaryServer(interceptors...)) -} - -// WithStreamServerChain is a grpc.Server config option that accepts multiple stream interceptors. -// Basically syntactic sugar. -func WithStreamServerChain(interceptors ...grpc.StreamServerInterceptor) grpc.ServerOption { - return grpc.StreamInterceptor(ChainStreamServer(interceptors...)) -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/doc.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/doc.go deleted file mode 100644 index 718e10046..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/doc.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -/* -`grpc_middleware` is a collection of gRPC middleware packages: interceptors, helpers and tools. - -Middleware - -gRPC is a fantastic RPC middleware, which sees a lot of adoption in the Golang world. However, the -upstream gRPC codebase is relatively bare bones. - -This package, and most of its child packages provides commonly needed middleware for gRPC: -client-side interceptors for retires, server-side interceptors for input validation and auth, -functions for chaining said interceptors, metadata convenience methods and more. - -Chaining - -By default, gRPC doesn't allow one to have more than one interceptor either on the client nor on -the server side. `grpc_middleware` provides convenient chaining methods - -Simple way of turning a multiple interceptors into a single interceptor. Here's an example for -server chaining: - - myServer := grpc.NewServer( - grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(loggingStream, monitoringStream, authStream)), - grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(loggingUnary, monitoringUnary, authUnary)), - ) - -These interceptors will be executed from left to right: logging, monitoring and auth. - -Here's an example for client side chaining: - - clientConn, err = grpc.Dial( - address, - grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(monitoringClientUnary, retryUnary)), - grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient(monitoringClientStream, retryStream)), - ) - client = pb_testproto.NewTestServiceClient(clientConn) - resp, err := client.PingEmpty(s.ctx, &myservice.Request{Msg: "hello"}) - -These interceptors will be executed from left to right: monitoring and then retry logic. - -The retry interceptor will call every interceptor that follows it whenever when a retry happens. - -Writing Your Own - -Implementing your own interceptor is pretty trivial: there are interfaces for that. But the interesting -bit exposing common data to handlers (and other middleware), similarly to HTTP Middleware design. -For example, you may want to pass the identity of the caller from the auth interceptor all the way -to the handling function. - -For example, a client side interceptor example for auth looks like: - - func FakeAuthUnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - newCtx := context.WithValue(ctx, "user_id", "john@example.com") - return handler(newCtx, req) - } - -Unfortunately, it's not as easy for streaming RPCs. These have the `context.Context` embedded within -the `grpc.ServerStream` object. To pass values through context, a wrapper (`WrappedServerStream`) is -needed. For example: - - func FakeAuthStreamingInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - newStream := grpc_middleware.WrapServerStream(stream) - newStream.WrappedContext = context.WithValue(ctx, "user_id", "john@example.com") - return handler(srv, newStream) - } -*/ -package grpc_middleware diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/common.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/common.go deleted file mode 100644 index 3e905cf1e..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/common.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_logging - -import ( - "context" - "io" - - "github.com/golang/protobuf/proto" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// ErrorToCode function determines the error code of an error -// This makes using custom errors with grpc middleware easier -type ErrorToCode func(err error) codes.Code - -func DefaultErrorToCode(err error) codes.Code { - return status.Code(err) -} - -// Decider function defines rules for suppressing any interceptor logs -type Decider func(fullMethodName string, err error) bool - -// DefaultDeciderMethod is the default implementation of decider to see if you should log the call -// by default this if always true so all calls are logged -func DefaultDeciderMethod(fullMethodName string, err error) bool { - return true -} - -// ServerPayloadLoggingDecider is a user-provided function for deciding whether to log the server-side -// request/response payloads -type ServerPayloadLoggingDecider func(ctx context.Context, fullMethodName string, servingObject interface{}) bool - -// ClientPayloadLoggingDecider is a user-provided function for deciding whether to log the client-side -// request/response payloads -type ClientPayloadLoggingDecider func(ctx context.Context, fullMethodName string) bool - -// JsonPbMarshaller is a marshaller that serializes protobuf messages. -type JsonPbMarshaler interface { - Marshal(out io.Writer, pb proto.Message) error -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/doc.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/doc.go deleted file mode 100644 index d8fcea081..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/doc.go +++ /dev/null @@ -1,32 +0,0 @@ -// -/* -grpc_logging is a "parent" package for gRPC logging middlewares. - -General functionality of all middleware - -The gRPC logging middleware populates request-scoped data to `grpc_ctxtags.Tags` that relate to the current gRPC call -(e.g. service and method names). - -Once the gRPC logging middleware has added the gRPC specific Tags to the ctx they will then be written with the logs -that are made using the `ctx_logrus` or `ctx_zap` loggers. - -All logging middleware will emit a final log statement. It is based on the error returned by the handler function, -the gRPC status code, an error (if any) and it will emit at a level controlled via `WithLevels`. - -This parent package - -This particular package is intended for use by other middleware, logging or otherwise. It contains interfaces that other -logging middlewares *could* share . This allows code to be shared between different implementations. - -Field names - -All field names of loggers follow the OpenTracing semantics definitions, with `grpc.` prefix if needed: -https://github.com/opentracing/specification/blob/master/semantic_conventions.md - -Implementations - -There are three implementations at the moment: logrus, zap and kit - -See relevant packages below. -*/ -package grpc_logging diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/settable/doc.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/settable/doc.go deleted file mode 100644 index c447ec6b9..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/settable/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// -/* -grpc_logsettable contains a thread-safe wrapper around grpc-logging -infrastructure. - -The go-grpc assumes that logger can be only configured once as the `SetLoggerV2` -method is: -```Not mutex-protected, should be called before any gRPC functions.``` - -This package allows to supply parent logger once ("before any grpc"), but -later change underlying implementation in thread-safe way when needed. - -It's in particular useful for testing, where each testcase might need its own -logger. -*/ -package grpc_logsettable diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/settable/logsettable.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/settable/logsettable.go deleted file mode 100644 index 9e403b2b2..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/settable/logsettable.go +++ /dev/null @@ -1,99 +0,0 @@ -package grpc_logsettable - -import ( - "io/ioutil" - "sync" - - "google.golang.org/grpc/grpclog" -) - -// SettableLoggerV2 is thread-safe. -type SettableLoggerV2 interface { - grpclog.LoggerV2 - // Sets given logger as the underlying implementation. - Set(loggerv2 grpclog.LoggerV2) - // Sets `discard` logger as the underlying implementation. - Reset() -} - -// ReplaceGrpcLoggerV2 creates and configures SettableLoggerV2 as grpc logger. -func ReplaceGrpcLoggerV2() SettableLoggerV2 { - settable := &settableLoggerV2{} - settable.Reset() - grpclog.SetLoggerV2(settable) - return settable -} - -// SettableLoggerV2 implements SettableLoggerV2 -type settableLoggerV2 struct { - log grpclog.LoggerV2 - mu sync.RWMutex -} - -func (s *settableLoggerV2) Set(log grpclog.LoggerV2) { - s.mu.Lock() - defer s.mu.Unlock() - s.log = log -} - -func (s *settableLoggerV2) Reset() { - s.Set(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)) -} - -func (s *settableLoggerV2) get() grpclog.LoggerV2 { - s.mu.RLock() - defer s.mu.RUnlock() - return s.log -} - -func (s *settableLoggerV2) Info(args ...interface{}) { - s.get().Info(args) -} - -func (s *settableLoggerV2) Infoln(args ...interface{}) { - s.get().Infoln(args) -} - -func (s *settableLoggerV2) Infof(format string, args ...interface{}) { - s.get().Infof(format, args) -} - -func (s *settableLoggerV2) Warning(args ...interface{}) { - s.get().Warning(args) -} - -func (s *settableLoggerV2) Warningln(args ...interface{}) { - s.get().Warningln(args) -} - -func (s *settableLoggerV2) Warningf(format string, args ...interface{}) { - s.get().Warningf(format, args) -} - -func (s *settableLoggerV2) Error(args ...interface{}) { - s.get().Error(args) -} - -func (s *settableLoggerV2) Errorln(args ...interface{}) { - s.get().Errorln(args) -} - -func (s *settableLoggerV2) Errorf(format string, args ...interface{}) { - s.get().Errorf(format, args) -} - -func (s *settableLoggerV2) Fatal(args ...interface{}) { - s.get().Fatal(args) -} - -func (s *settableLoggerV2) Fatalln(args ...interface{}) { - s.get().Fatalln(args) -} - -func (s *settableLoggerV2) Fatalf(format string, args ...interface{}) { - s.get().Fatalf(format, args) -} - -func (s *settableLoggerV2) V(l int) bool { - return s.get().V(l) -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/client_interceptors.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/client_interceptors.go deleted file mode 100644 index de80c1cc0..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/client_interceptors.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2017 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_zap - -import ( - "context" - "path" - "time" - - "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "google.golang.org/grpc" -) - -var ( - // ClientField is used in every client-side log statement made through grpc_zap. Can be overwritten before initialization. - ClientField = zap.String("span.kind", "client") -) - -// UnaryClientInterceptor returns a new unary client interceptor that optionally logs the execution of external gRPC calls. -func UnaryClientInterceptor(logger *zap.Logger, opts ...Option) grpc.UnaryClientInterceptor { - o := evaluateClientOpt(opts) - return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - fields := newClientLoggerFields(ctx, method) - startTime := time.Now() - err := invoker(ctx, method, req, reply, cc, opts...) - newCtx := ctxzap.ToContext(ctx, logger.With(fields...)) - logFinalClientLine(newCtx, o, startTime, err, "finished client unary call") - return err - } -} - -// StreamClientInterceptor returns a new streaming client interceptor that optionally logs the execution of external gRPC calls. -func StreamClientInterceptor(logger *zap.Logger, opts ...Option) grpc.StreamClientInterceptor { - o := evaluateClientOpt(opts) - return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { - fields := newClientLoggerFields(ctx, method) - startTime := time.Now() - clientStream, err := streamer(ctx, desc, cc, method, opts...) - newCtx := ctxzap.ToContext(ctx, logger.With(fields...)) - logFinalClientLine(newCtx, o, startTime, err, "finished client streaming call") - return clientStream, err - } -} - -func logFinalClientLine(ctx context.Context, o *options, startTime time.Time, err error, msg string) { - code := o.codeFunc(err) - level := o.levelFunc(code) - duration := o.durationFunc(time.Now().Sub(startTime)) - o.messageFunc(ctx, msg, level, code, err, duration) -} - -func newClientLoggerFields(ctx context.Context, fullMethodString string) []zapcore.Field { - service := path.Dir(fullMethodString)[1:] - method := path.Base(fullMethodString) - return []zapcore.Field{ - SystemField, - ClientField, - zap.String("grpc.service", service), - zap.String("grpc.method", method), - } -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/context.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/context.go deleted file mode 100644 index 56f6408a6..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/context.go +++ /dev/null @@ -1,21 +0,0 @@ -package grpc_zap - -import ( - "context" - - "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -// AddFields adds zap fields to the logger. -// Deprecated: should use the ctxzap.AddFields instead -func AddFields(ctx context.Context, fields ...zapcore.Field) { - ctxzap.AddFields(ctx, fields...) -} - -// Extract takes the call-scoped Logger from grpc_zap middleware. -// Deprecated: should use the ctxzap.Extract instead -func Extract(ctx context.Context) *zap.Logger { - return ctxzap.Extract(ctx) -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap/context.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap/context.go deleted file mode 100644 index 05dc12120..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap/context.go +++ /dev/null @@ -1,88 +0,0 @@ -package ctxzap - -import ( - "context" - - "github.com/grpc-ecosystem/go-grpc-middleware/tags" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -type ctxMarker struct{} - -type ctxLogger struct { - logger *zap.Logger - fields []zapcore.Field -} - -var ( - ctxMarkerKey = &ctxMarker{} - nullLogger = zap.NewNop() -) - -// AddFields adds zap fields to the logger. -func AddFields(ctx context.Context, fields ...zapcore.Field) { - l, ok := ctx.Value(ctxMarkerKey).(*ctxLogger) - if !ok || l == nil { - return - } - l.fields = append(l.fields, fields...) -} - -// Extract takes the call-scoped Logger from grpc_zap middleware. -// -// It always returns a Logger that has all the grpc_ctxtags updated. -func Extract(ctx context.Context) *zap.Logger { - l, ok := ctx.Value(ctxMarkerKey).(*ctxLogger) - if !ok || l == nil { - return nullLogger - } - // Add grpc_ctxtags tags metadata until now. - fields := TagsToFields(ctx) - // Add zap fields added until now. - fields = append(fields, l.fields...) - return l.logger.With(fields...) -} - -// TagsToFields transforms the Tags on the supplied context into zap fields. -func TagsToFields(ctx context.Context) []zapcore.Field { - fields := []zapcore.Field{} - tags := grpc_ctxtags.Extract(ctx) - for k, v := range tags.Values() { - fields = append(fields, zap.Any(k, v)) - } - return fields -} - -// ToContext adds the zap.Logger to the context for extraction later. -// Returning the new context that has been created. -func ToContext(ctx context.Context, logger *zap.Logger) context.Context { - l := &ctxLogger{ - logger: logger, - } - return context.WithValue(ctx, ctxMarkerKey, l) -} - -// Debug is equivalent to calling Debug on the zap.Logger in the context. -// It is a no-op if the context does not contain a zap.Logger. -func Debug(ctx context.Context, msg string, fields ...zap.Field) { - Extract(ctx).Debug(msg, fields...) -} - -// Info is equivalent to calling Info on the zap.Logger in the context. -// It is a no-op if the context does not contain a zap.Logger. -func Info(ctx context.Context, msg string, fields ...zap.Field) { - Extract(ctx).Info(msg, fields...) -} - -// Warn is equivalent to calling Warn on the zap.Logger in the context. -// It is a no-op if the context does not contain a zap.Logger. -func Warn(ctx context.Context, msg string, fields ...zap.Field) { - Extract(ctx).Warn(msg, fields...) -} - -// Error is equivalent to calling Error on the zap.Logger in the context. -// It is a no-op if the context does not contain a zap.Logger. -func Error(ctx context.Context, msg string, fields ...zap.Field) { - Extract(ctx).Error(msg, fields...) -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap/doc.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap/doc.go deleted file mode 100644 index 3591e3585..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap/doc.go +++ /dev/null @@ -1,14 +0,0 @@ -/* -`ctxzap` is a ctxlogger that is backed by Zap - -It accepts a user-configured `zap.Logger` that will be used for logging. The same `zap.Logger` will -be populated into the `context.Context` passed into gRPC handler code. - -You can use `ctxzap.Extract` to log into a request-scoped `zap.Logger` instance in your handler code. - -As `ctxzap.Extract` will iterate all tags on from `grpc_ctxtags` it is therefore expensive so it is advised that you -extract once at the start of the function from the context and reuse it for the remainder of the function (see examples). - -Please see examples and tests for examples of use. -*/ -package ctxzap diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/doc.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/doc.go deleted file mode 100644 index ffa6b5c31..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/doc.go +++ /dev/null @@ -1,75 +0,0 @@ -/* -`grpc_zap` is a gRPC logging middleware backed by ZAP loggers - -It accepts a user-configured `zap.Logger` that will be used for logging completed gRPC calls. The same `zap.Logger` will -be used for logging completed gRPC calls, and be populated into the `context.Context` passed into gRPC handler code. - -On calling `StreamServerInterceptor` or `UnaryServerInterceptor` this logging middleware will add gRPC call information -to the ctx so that it will be present on subsequent use of the `ctx_zap` logger. - -If a deadline is present on the gRPC request the grpc.request.deadline tag is populated when the request begins. grpc.request.deadline -is a string representing the time (RFC3339) when the current call will expire. - -This package also implements request and response *payload* logging, both for server-side and client-side. These will be -logged as structured `jsonpb` fields for every message received/sent (both unary and streaming). For that please use -`Payload*Interceptor` functions for that. Please note that the user-provided function that determines whether to log -the full request/response payload needs to be written with care, this can significantly slow down gRPC. - -ZAP can also be made as a backend for gRPC library internals. For that use `ReplaceGrpcLoggerV2`. - - -*Server Interceptor* -Below is a JSON formatted example of a log that would be logged by the server interceptor: - - { - "level": "info", // string zap log levels - "msg": "finished unary call", // string log message - - "grpc.code": "OK", // string grpc status code - "grpc.method": "Ping", // string method name - "grpc.service": "mwitkow.testproto.TestService", // string full name of the called service - "grpc.start_time": "2006-01-02T15:04:05Z07:00", // string RFC3339 representation of the start time - "grpc.request.deadline": "2006-01-02T15:04:05Z07:00", // string RFC3339 deadline of the current request if supplied - "grpc.request.value": "something", // string value on the request - "grpc.time_ms": 1.345, // float32 run time of the call in ms - - "peer.address": { - "IP": "127.0.0.1", // string IP address of calling party - "Port": 60216, // int port call is coming in on - "Zone": "" // string peer zone for caller - }, - "span.kind": "server", // string client | server - "system": "grpc" // string - - "custom_field": "custom_value", // string user defined field - "custom_tags.int": 1337, // int user defined tag on the ctx - "custom_tags.string": "something", // string user defined tag on the ctx - } - -*Payload Interceptor* -Below is a JSON formatted example of a log that would be logged by the payload interceptor: - - { - "level": "info", // string zap log levels - "msg": "client request payload logged as grpc.request.content", // string log message - - "grpc.request.content": { // object content of RPC request - "msg" : { // object ZAP specific inner object - "value": "something", // string defined by caller - "sleepTimeMs": 9999 // int defined by caller - } - }, - "grpc.method": "Ping", // string method being called - "grpc.service": "mwitkow.testproto.TestService", // string service being called - - "span.kind": "client", // string client | server - "system": "grpc" // string - } - -Note - due to implementation ZAP differs from Logrus in the "grpc.request.content" object by having an inner "msg" object. - - -Please see examples and tests for examples of use. -Please see settable_test.go for canonical integration through "zaptest" with golang testing infrastructure. -*/ -package grpc_zap diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/grpclogger.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/grpclogger.go deleted file mode 100644 index 85fc2100a..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/grpclogger.go +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2017 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_zap - -import ( - "fmt" - - grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable" - "go.uber.org/zap" - "google.golang.org/grpc/grpclog" -) - -// ReplaceGrpcLogger sets the given zap.Logger as a gRPC-level logger. -// This should be called *before* any other initialization, preferably from init() functions. -// Deprecated: use ReplaceGrpcLoggerV2. -func ReplaceGrpcLogger(logger *zap.Logger) { - zgl := &zapGrpcLogger{logger.With(SystemField, zap.Bool("grpc_log", true))} - grpclog.SetLogger(zgl) -} - -type zapGrpcLogger struct { - logger *zap.Logger -} - -func (l *zapGrpcLogger) Fatal(args ...interface{}) { - l.logger.Fatal(fmt.Sprint(args...)) -} - -func (l *zapGrpcLogger) Fatalf(format string, args ...interface{}) { - l.logger.Fatal(fmt.Sprintf(format, args...)) -} - -func (l *zapGrpcLogger) Fatalln(args ...interface{}) { - l.logger.Fatal(fmt.Sprint(args...)) -} - -func (l *zapGrpcLogger) Print(args ...interface{}) { - l.logger.Info(fmt.Sprint(args...)) -} - -func (l *zapGrpcLogger) Printf(format string, args ...interface{}) { - l.logger.Info(fmt.Sprintf(format, args...)) -} - -func (l *zapGrpcLogger) Println(args ...interface{}) { - l.logger.Info(fmt.Sprint(args...)) -} - -// ReplaceGrpcLoggerV2 replaces the grpc_log.LoggerV2 with the provided logger. -// It should be called before any gRPC functions. -func ReplaceGrpcLoggerV2(logger *zap.Logger) { - ReplaceGrpcLoggerV2WithVerbosity(logger, 0) -} - -// ReplaceGrpcLoggerV2WithVerbosity replaces the grpc_.LoggerV2 with the provided logger and verbosity. -// It should be called before any gRPC functions. -func ReplaceGrpcLoggerV2WithVerbosity(logger *zap.Logger, verbosity int) { - zgl := &zapGrpcLoggerV2{ - logger: logger.With(SystemField, zap.Bool("grpc_log", true)), - verbosity: verbosity, - } - grpclog.SetLoggerV2(zgl) -} - -// SetGrpcLoggerV2 replaces the grpc_log.LoggerV2 with the provided logger. -// It can be used even when grpc infrastructure was initialized. -func SetGrpcLoggerV2(settable grpc_logsettable.SettableLoggerV2, logger *zap.Logger) { - SetGrpcLoggerV2WithVerbosity(settable, logger, 0) -} - -// SetGrpcLoggerV2WithVerbosity replaces the grpc_.LoggerV2 with the provided logger and verbosity. -// It can be used even when grpc infrastructure was initialized. -func SetGrpcLoggerV2WithVerbosity(settable grpc_logsettable.SettableLoggerV2, logger *zap.Logger, verbosity int) { - zgl := &zapGrpcLoggerV2{ - logger: logger.With(SystemField, zap.Bool("grpc_log", true)), - verbosity: verbosity, - } - settable.Set(zgl) -} - -type zapGrpcLoggerV2 struct { - logger *zap.Logger - verbosity int -} - -func (l *zapGrpcLoggerV2) Info(args ...interface{}) { - l.logger.Info(fmt.Sprint(args...)) -} - -func (l *zapGrpcLoggerV2) Infoln(args ...interface{}) { - l.logger.Info(fmt.Sprint(args...)) -} - -func (l *zapGrpcLoggerV2) Infof(format string, args ...interface{}) { - l.logger.Info(fmt.Sprintf(format, args...)) -} - -func (l *zapGrpcLoggerV2) Warning(args ...interface{}) { - l.logger.Warn(fmt.Sprint(args...)) -} - -func (l *zapGrpcLoggerV2) Warningln(args ...interface{}) { - l.logger.Warn(fmt.Sprint(args...)) -} - -func (l *zapGrpcLoggerV2) Warningf(format string, args ...interface{}) { - l.logger.Warn(fmt.Sprintf(format, args...)) -} - -func (l *zapGrpcLoggerV2) Error(args ...interface{}) { - l.logger.Error(fmt.Sprint(args...)) -} - -func (l *zapGrpcLoggerV2) Errorln(args ...interface{}) { - l.logger.Error(fmt.Sprint(args...)) -} - -func (l *zapGrpcLoggerV2) Errorf(format string, args ...interface{}) { - l.logger.Error(fmt.Sprintf(format, args...)) -} - -func (l *zapGrpcLoggerV2) Fatal(args ...interface{}) { - l.logger.Fatal(fmt.Sprint(args...)) -} - -func (l *zapGrpcLoggerV2) Fatalln(args ...interface{}) { - l.logger.Fatal(fmt.Sprint(args...)) -} - -func (l *zapGrpcLoggerV2) Fatalf(format string, args ...interface{}) { - l.logger.Fatal(fmt.Sprintf(format, args...)) -} - -func (l *zapGrpcLoggerV2) V(level int) bool { - return l.verbosity <= level -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/options.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/options.go deleted file mode 100644 index b59db9ad6..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/options.go +++ /dev/null @@ -1,217 +0,0 @@ -package grpc_zap - -import ( - "context" - "time" - - grpc_logging "github.com/grpc-ecosystem/go-grpc-middleware/logging" - "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "google.golang.org/grpc/codes" -) - -var ( - defaultOptions = &options{ - levelFunc: DefaultCodeToLevel, - shouldLog: grpc_logging.DefaultDeciderMethod, - codeFunc: grpc_logging.DefaultErrorToCode, - durationFunc: DefaultDurationToField, - messageFunc: DefaultMessageProducer, - timestampFormat: time.RFC3339, - } -) - -type options struct { - levelFunc CodeToLevel - shouldLog grpc_logging.Decider - codeFunc grpc_logging.ErrorToCode - durationFunc DurationToField - messageFunc MessageProducer - timestampFormat string -} - -func evaluateServerOpt(opts []Option) *options { - optCopy := &options{} - *optCopy = *defaultOptions - optCopy.levelFunc = DefaultCodeToLevel - for _, o := range opts { - o(optCopy) - } - return optCopy -} - -func evaluateClientOpt(opts []Option) *options { - optCopy := &options{} - *optCopy = *defaultOptions - optCopy.levelFunc = DefaultClientCodeToLevel - for _, o := range opts { - o(optCopy) - } - return optCopy -} - -type Option func(*options) - -// CodeToLevel function defines the mapping between gRPC return codes and interceptor log level. -type CodeToLevel func(code codes.Code) zapcore.Level - -// DurationToField function defines how to produce duration fields for logging -type DurationToField func(duration time.Duration) zapcore.Field - -// WithDecider customizes the function for deciding if the gRPC interceptor logs should log. -func WithDecider(f grpc_logging.Decider) Option { - return func(o *options) { - o.shouldLog = f - } -} - -// WithLevels customizes the function for mapping gRPC return codes and interceptor log level statements. -func WithLevels(f CodeToLevel) Option { - return func(o *options) { - o.levelFunc = f - } -} - -// WithCodes customizes the function for mapping errors to error codes. -func WithCodes(f grpc_logging.ErrorToCode) Option { - return func(o *options) { - o.codeFunc = f - } -} - -// WithDurationField customizes the function for mapping request durations to Zap fields. -func WithDurationField(f DurationToField) Option { - return func(o *options) { - o.durationFunc = f - } -} - -// WithMessageProducer customizes the function for message formation. -func WithMessageProducer(f MessageProducer) Option { - return func(o *options) { - o.messageFunc = f - } -} - -// WithTimestampFormat customizes the timestamps emitted in the log fields. -func WithTimestampFormat(format string) Option { - return func(o *options) { - o.timestampFormat = format - } -} - -// DefaultCodeToLevel is the default implementation of gRPC return codes and interceptor log level for server side. -func DefaultCodeToLevel(code codes.Code) zapcore.Level { - switch code { - case codes.OK: - return zap.InfoLevel - case codes.Canceled: - return zap.InfoLevel - case codes.Unknown: - return zap.ErrorLevel - case codes.InvalidArgument: - return zap.InfoLevel - case codes.DeadlineExceeded: - return zap.WarnLevel - case codes.NotFound: - return zap.InfoLevel - case codes.AlreadyExists: - return zap.InfoLevel - case codes.PermissionDenied: - return zap.WarnLevel - case codes.Unauthenticated: - return zap.InfoLevel // unauthenticated requests can happen - case codes.ResourceExhausted: - return zap.WarnLevel - case codes.FailedPrecondition: - return zap.WarnLevel - case codes.Aborted: - return zap.WarnLevel - case codes.OutOfRange: - return zap.WarnLevel - case codes.Unimplemented: - return zap.ErrorLevel - case codes.Internal: - return zap.ErrorLevel - case codes.Unavailable: - return zap.WarnLevel - case codes.DataLoss: - return zap.ErrorLevel - default: - return zap.ErrorLevel - } -} - -// DefaultClientCodeToLevel is the default implementation of gRPC return codes to log levels for client side. -func DefaultClientCodeToLevel(code codes.Code) zapcore.Level { - switch code { - case codes.OK: - return zap.DebugLevel - case codes.Canceled: - return zap.DebugLevel - case codes.Unknown: - return zap.InfoLevel - case codes.InvalidArgument: - return zap.DebugLevel - case codes.DeadlineExceeded: - return zap.InfoLevel - case codes.NotFound: - return zap.DebugLevel - case codes.AlreadyExists: - return zap.DebugLevel - case codes.PermissionDenied: - return zap.InfoLevel - case codes.Unauthenticated: - return zap.InfoLevel // unauthenticated requests can happen - case codes.ResourceExhausted: - return zap.DebugLevel - case codes.FailedPrecondition: - return zap.DebugLevel - case codes.Aborted: - return zap.DebugLevel - case codes.OutOfRange: - return zap.DebugLevel - case codes.Unimplemented: - return zap.WarnLevel - case codes.Internal: - return zap.WarnLevel - case codes.Unavailable: - return zap.WarnLevel - case codes.DataLoss: - return zap.WarnLevel - default: - return zap.InfoLevel - } -} - -// DefaultDurationToField is the default implementation of converting request duration to a Zap field. -var DefaultDurationToField = DurationToTimeMillisField - -// DurationToTimeMillisField converts the duration to milliseconds and uses the key `grpc.time_ms`. -func DurationToTimeMillisField(duration time.Duration) zapcore.Field { - return zap.Float32("grpc.time_ms", durationToMilliseconds(duration)) -} - -// DurationToDurationField uses a Duration field to log the request duration -// and leaves it up to Zap's encoder settings to determine how that is output. -func DurationToDurationField(duration time.Duration) zapcore.Field { - return zap.Duration("grpc.duration", duration) -} - -func durationToMilliseconds(duration time.Duration) float32 { - return float32(duration.Nanoseconds()/1000) / 1000 -} - -// MessageProducer produces a user defined log message -type MessageProducer func(ctx context.Context, msg string, level zapcore.Level, code codes.Code, err error, duration zapcore.Field) - -// DefaultMessageProducer writes the default message -func DefaultMessageProducer(ctx context.Context, msg string, level zapcore.Level, code codes.Code, err error, duration zapcore.Field) { - // re-extract logger from newCtx, as it may have extra fields that changed in the holder. - ctxzap.Extract(ctx).Check(level, msg).Write( - zap.Error(err), - zap.String("grpc.code", code.String()), - duration, - ) -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/payload_interceptors.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/payload_interceptors.go deleted file mode 100644 index 329019b17..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/payload_interceptors.go +++ /dev/null @@ -1,150 +0,0 @@ -package grpc_zap - -import ( - "bytes" - "context" - "fmt" - - "github.com/golang/protobuf/jsonpb" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/go-grpc-middleware/logging" - "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "google.golang.org/grpc" -) - -var ( - // JsonPbMarshaller is the marshaller used for serializing protobuf messages. - // If needed, this variable can be reassigned with a different marshaller with the same Marshal() signature. - JsonPbMarshaller grpc_logging.JsonPbMarshaler = &jsonpb.Marshaler{} -) - -// PayloadUnaryServerInterceptor returns a new unary server interceptors that logs the payloads of requests. -// -// This *only* works when placed *after* the `grpc_zap.UnaryServerInterceptor`. However, the logging can be done to a -// separate instance of the logger. -func PayloadUnaryServerInterceptor(logger *zap.Logger, decider grpc_logging.ServerPayloadLoggingDecider) grpc.UnaryServerInterceptor { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - if !decider(ctx, info.FullMethod, info.Server) { - return handler(ctx, req) - } - // Use the provided zap.Logger for logging but use the fields from context. - logEntry := logger.With(append(serverCallFields(info.FullMethod), ctxzap.TagsToFields(ctx)...)...) - logProtoMessageAsJson(logEntry, req, "grpc.request.content", "server request payload logged as grpc.request.content field") - resp, err := handler(ctx, req) - if err == nil { - logProtoMessageAsJson(logEntry, resp, "grpc.response.content", "server response payload logged as grpc.response.content field") - } - return resp, err - } -} - -// PayloadStreamServerInterceptor returns a new server server interceptors that logs the payloads of requests. -// -// This *only* works when placed *after* the `grpc_zap.StreamServerInterceptor`. However, the logging can be done to a -// separate instance of the logger. -func PayloadStreamServerInterceptor(logger *zap.Logger, decider grpc_logging.ServerPayloadLoggingDecider) grpc.StreamServerInterceptor { - return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - if !decider(stream.Context(), info.FullMethod, srv) { - return handler(srv, stream) - } - logEntry := logger.With(append(serverCallFields(info.FullMethod), ctxzap.TagsToFields(stream.Context())...)...) - newStream := &loggingServerStream{ServerStream: stream, logger: logEntry} - return handler(srv, newStream) - } -} - -// PayloadUnaryClientInterceptor returns a new unary client interceptor that logs the payloads of requests and responses. -func PayloadUnaryClientInterceptor(logger *zap.Logger, decider grpc_logging.ClientPayloadLoggingDecider) grpc.UnaryClientInterceptor { - return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - if !decider(ctx, method) { - return invoker(ctx, method, req, reply, cc, opts...) - } - logEntry := logger.With(newClientLoggerFields(ctx, method)...) - logProtoMessageAsJson(logEntry, req, "grpc.request.content", "client request payload logged as grpc.request.content") - err := invoker(ctx, method, req, reply, cc, opts...) - if err == nil { - logProtoMessageAsJson(logEntry, reply, "grpc.response.content", "client response payload logged as grpc.response.content") - } - return err - } -} - -// PayloadStreamClientInterceptor returns a new streaming client interceptor that logs the payloads of requests and responses. -func PayloadStreamClientInterceptor(logger *zap.Logger, decider grpc_logging.ClientPayloadLoggingDecider) grpc.StreamClientInterceptor { - return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { - if !decider(ctx, method) { - return streamer(ctx, desc, cc, method, opts...) - } - logEntry := logger.With(newClientLoggerFields(ctx, method)...) - clientStream, err := streamer(ctx, desc, cc, method, opts...) - newStream := &loggingClientStream{ClientStream: clientStream, logger: logEntry} - return newStream, err - } -} - -type loggingClientStream struct { - grpc.ClientStream - logger *zap.Logger -} - -func (l *loggingClientStream) SendMsg(m interface{}) error { - err := l.ClientStream.SendMsg(m) - if err == nil { - logProtoMessageAsJson(l.logger, m, "grpc.request.content", "server request payload logged as grpc.request.content field") - } - return err -} - -func (l *loggingClientStream) RecvMsg(m interface{}) error { - err := l.ClientStream.RecvMsg(m) - if err == nil { - logProtoMessageAsJson(l.logger, m, "grpc.response.content", "server response payload logged as grpc.response.content field") - } - return err -} - -type loggingServerStream struct { - grpc.ServerStream - logger *zap.Logger -} - -func (l *loggingServerStream) SendMsg(m interface{}) error { - err := l.ServerStream.SendMsg(m) - if err == nil { - logProtoMessageAsJson(l.logger, m, "grpc.response.content", "server response payload logged as grpc.response.content field") - } - return err -} - -func (l *loggingServerStream) RecvMsg(m interface{}) error { - err := l.ServerStream.RecvMsg(m) - if err == nil { - logProtoMessageAsJson(l.logger, m, "grpc.request.content", "server request payload logged as grpc.request.content field") - } - return err -} - -func logProtoMessageAsJson(logger *zap.Logger, pbMsg interface{}, key string, msg string) { - if p, ok := pbMsg.(proto.Message); ok { - logger.Check(zapcore.InfoLevel, msg).Write(zap.Object(key, &jsonpbObjectMarshaler{pb: p})) - } -} - -type jsonpbObjectMarshaler struct { - pb proto.Message -} - -func (j *jsonpbObjectMarshaler) MarshalLogObject(e zapcore.ObjectEncoder) error { - // ZAP jsonEncoder deals with AddReflect by using json.MarshalObject. The same thing applies for consoleEncoder. - return e.AddReflected("msg", j) -} - -func (j *jsonpbObjectMarshaler) MarshalJSON() ([]byte, error) { - b := &bytes.Buffer{} - if err := JsonPbMarshaller.Marshal(b, j.pb); err != nil { - return nil, fmt.Errorf("jsonpb serializer failed: %v", err) - } - return b.Bytes(), nil -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/server_interceptors.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/server_interceptors.go deleted file mode 100644 index 1db035897..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/server_interceptors.go +++ /dev/null @@ -1,85 +0,0 @@ -package grpc_zap - -import ( - "context" - "path" - "time" - - grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" - "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "google.golang.org/grpc" -) - -var ( - // SystemField is used in every log statement made through grpc_zap. Can be overwritten before any initialization code. - SystemField = zap.String("system", "grpc") - - // ServerField is used in every server-side log statement made through grpc_zap.Can be overwritten before initialization. - ServerField = zap.String("span.kind", "server") -) - -// UnaryServerInterceptor returns a new unary server interceptors that adds zap.Logger to the context. -func UnaryServerInterceptor(logger *zap.Logger, opts ...Option) grpc.UnaryServerInterceptor { - o := evaluateServerOpt(opts) - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - startTime := time.Now() - - newCtx := newLoggerForCall(ctx, logger, info.FullMethod, startTime, o.timestampFormat) - - resp, err := handler(newCtx, req) - if !o.shouldLog(info.FullMethod, err) { - return resp, err - } - code := o.codeFunc(err) - level := o.levelFunc(code) - duration := o.durationFunc(time.Since(startTime)) - - o.messageFunc(newCtx, "finished unary call with code "+code.String(), level, code, err, duration) - return resp, err - } -} - -// StreamServerInterceptor returns a new streaming server interceptor that adds zap.Logger to the context. -func StreamServerInterceptor(logger *zap.Logger, opts ...Option) grpc.StreamServerInterceptor { - o := evaluateServerOpt(opts) - return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - startTime := time.Now() - newCtx := newLoggerForCall(stream.Context(), logger, info.FullMethod, startTime, o.timestampFormat) - wrapped := grpc_middleware.WrapServerStream(stream) - wrapped.WrappedContext = newCtx - - err := handler(srv, wrapped) - if !o.shouldLog(info.FullMethod, err) { - return err - } - code := o.codeFunc(err) - level := o.levelFunc(code) - duration := o.durationFunc(time.Since(startTime)) - - o.messageFunc(newCtx, "finished streaming call with code "+code.String(), level, code, err, duration) - return err - } -} - -func serverCallFields(fullMethodString string) []zapcore.Field { - service := path.Dir(fullMethodString)[1:] - method := path.Base(fullMethodString) - return []zapcore.Field{ - SystemField, - ServerField, - zap.String("grpc.service", service), - zap.String("grpc.method", method), - } -} - -func newLoggerForCall(ctx context.Context, logger *zap.Logger, fullMethodString string, start time.Time, timestampFormat string) context.Context { - var f []zapcore.Field - f = append(f, zap.String("grpc.start_time", start.Format(timestampFormat))) - if d, ok := ctx.Deadline(); ok { - f = append(f, zap.String("grpc.request.deadline", d.Format(timestampFormat))) - } - callLog := logger.With(append(f, serverCallFields(fullMethodString)...)...) - return ctxzap.ToContext(ctx, callLog) -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/makefile b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/makefile deleted file mode 100644 index b18d2d2bb..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/makefile +++ /dev/null @@ -1,17 +0,0 @@ -SHELL=/bin/bash - -GOFILES_NOVENDOR = $(shell go list ./... | grep -v /vendor/) - -all: vet fmt test - -fmt: - go fmt $(GOFILES_NOVENDOR) - -vet: - # do not check lostcancel, they are intentional. - go vet -lostcancel=false $(GOFILES_NOVENDOR) - -test: vet - ./scripts/test_all.sh - -.PHONY: all test diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/slack.png b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/slack.png deleted file mode 100644 index cc8f9a68a..000000000 Binary files a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/slack.png and /dev/null differ diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/context.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/context.go deleted file mode 100644 index 0da1658bb..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/context.go +++ /dev/null @@ -1,78 +0,0 @@ -package grpc_ctxtags - -import ( - "context" -) - -type ctxMarker struct{} - -var ( - // ctxMarkerKey is the Context value marker used by *all* logging middleware. - // The logging middleware object must interf - ctxMarkerKey = &ctxMarker{} - // NoopTags is a trivial, minimum overhead implementation of Tags for which all operations are no-ops. - NoopTags = &noopTags{} -) - -// Tags is the interface used for storing request tags between Context calls. -// The default implementation is *not* thread safe, and should be handled only in the context of the request. -type Tags interface { - // Set sets the given key in the metadata tags. - Set(key string, value interface{}) Tags - // Has checks if the given key exists. - Has(key string) bool - // Values returns a map of key to values. - // Do not modify the underlying map, please use Set instead. - Values() map[string]interface{} -} - -type mapTags struct { - values map[string]interface{} -} - -func (t *mapTags) Set(key string, value interface{}) Tags { - t.values[key] = value - return t -} - -func (t *mapTags) Has(key string) bool { - _, ok := t.values[key] - return ok -} - -func (t *mapTags) Values() map[string]interface{} { - return t.values -} - -type noopTags struct{} - -func (t *noopTags) Set(key string, value interface{}) Tags { - return t -} - -func (t *noopTags) Has(key string) bool { - return false -} - -func (t *noopTags) Values() map[string]interface{} { - return nil -} - -// Extracts returns a pre-existing Tags object in the Context. -// If the context wasn't set in a tag interceptor, a no-op Tag storage is returned that will *not* be propagated in context. -func Extract(ctx context.Context) Tags { - t, ok := ctx.Value(ctxMarkerKey).(Tags) - if !ok { - return NoopTags - } - - return t -} - -func SetInContext(ctx context.Context, tags Tags) context.Context { - return context.WithValue(ctx, ctxMarkerKey, tags) -} - -func NewTags() Tags { - return &mapTags{values: make(map[string]interface{})} -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/doc.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/doc.go deleted file mode 100644 index 960638d0f..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/doc.go +++ /dev/null @@ -1,22 +0,0 @@ -/* -`grpc_ctxtags` adds a Tag object to the context that can be used by other middleware to add context about a request. - -Request Context Tags - -Tags describe information about the request, and can be set and used by other middleware, or handlers. Tags are used -for logging and tracing of requests. Tags are populated both upwards, *and* downwards in the interceptor-handler stack. - -You can automatically extract tags (in `grpc.request.`) from request payloads. - -For unary and server-streaming methods, pass in the `WithFieldExtractor` option. For client-streams and bidirectional-streams, you can -use `WithFieldExtractorForInitialReq` which will extract the tags from the first message passed from client to server. -Note the tags will not be modified for subsequent requests, so this option only makes sense when the initial message -establishes the meta-data for the stream. - -If a user doesn't use the interceptors that initialize the `Tags` object, all operations following from an `Extract(ctx)` -will be no-ops. This is to ensure that code doesn't panic if the interceptors weren't used. - -Tags fields are typed, and shallow and should follow the OpenTracing semantics convention: -https://github.com/opentracing/specification/blob/master/semantic_conventions.md -*/ -package grpc_ctxtags diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/fieldextractor.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/fieldextractor.go deleted file mode 100644 index a4073ab49..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/fieldextractor.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_ctxtags - -import ( - "reflect" -) - -// RequestFieldExtractorFunc is a user-provided function that extracts field information from a gRPC request. -// It is called from tags middleware on arrival of unary request or a server-stream request. -// Keys and values will be added to the context tags of the request. If there are no fields, you should return a nil. -type RequestFieldExtractorFunc func(fullMethod string, req interface{}) map[string]interface{} - -type requestFieldsExtractor interface { - // ExtractRequestFields is a method declared on a Protobuf message that extracts fields from the interface. - // The values from the extracted fields should be set in the appendToMap, in order to avoid allocations. - ExtractRequestFields(appendToMap map[string]interface{}) -} - -// CodeGenRequestFieldExtractor is a function that relies on code-generated functions that export log fields from requests. -// These are usually coming from a protoc-plugin that generates additional information based on custom field options. -func CodeGenRequestFieldExtractor(fullMethod string, req interface{}) map[string]interface{} { - if ext, ok := req.(requestFieldsExtractor); ok { - retMap := make(map[string]interface{}) - ext.ExtractRequestFields(retMap) - if len(retMap) == 0 { - return nil - } - return retMap - } - return nil -} - -// TagBasedRequestFieldExtractor is a function that relies on Go struct tags to export log fields from requests. -// These are usually coming from a protoc-plugin, such as Gogo protobuf. -// -// message Metadata { -// repeated string tags = 1 [ (gogoproto.moretags) = "log_field:\"meta_tags\"" ]; -// } -// -// The tagName is configurable using the tagName variable. Here it would be "log_field". -func TagBasedRequestFieldExtractor(tagName string) RequestFieldExtractorFunc { - return func(fullMethod string, req interface{}) map[string]interface{} { - retMap := make(map[string]interface{}) - reflectMessageTags(req, retMap, tagName) - if len(retMap) == 0 { - return nil - } - return retMap - } -} - -func reflectMessageTags(msg interface{}, existingMap map[string]interface{}, tagName string) { - v := reflect.ValueOf(msg) - // Only deal with pointers to structs. - if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct { - return - } - // Deref the pointer get to the struct. - v = v.Elem() - t := v.Type() - for i := 0; i < v.NumField(); i++ { - field := v.Field(i) - kind := field.Kind() - // Only recurse down direct pointers, which should only be to nested structs. - if (kind == reflect.Ptr || kind == reflect.Interface) && field.CanInterface() { - reflectMessageTags(field.Interface(), existingMap, tagName) - } - // In case of arrays/slices (repeated fields) go down to the concrete type. - if kind == reflect.Array || kind == reflect.Slice { - if field.Len() == 0 { - continue - } - kind = field.Index(0).Kind() - } - // Only be interested in - if (kind >= reflect.Bool && kind <= reflect.Float64) || kind == reflect.String { - if tag := t.Field(i).Tag.Get(tagName); tag != "" { - existingMap[tag] = field.Interface() - } - } - } - return -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/interceptors.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/interceptors.go deleted file mode 100644 index a7ced60f5..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/interceptors.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_ctxtags - -import ( - "context" - - "google.golang.org/grpc" - "google.golang.org/grpc/peer" - - "github.com/grpc-ecosystem/go-grpc-middleware" -) - -// UnaryServerInterceptor returns a new unary server interceptors that sets the values for request tags. -func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor { - o := evaluateOptions(opts) - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - newCtx := newTagsForCtx(ctx) - if o.requestFieldsFunc != nil { - setRequestFieldTags(newCtx, o.requestFieldsFunc, info.FullMethod, req) - } - return handler(newCtx, req) - } -} - -// StreamServerInterceptor returns a new streaming server interceptor that sets the values for request tags. -func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor { - o := evaluateOptions(opts) - return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - newCtx := newTagsForCtx(stream.Context()) - if o.requestFieldsFunc == nil { - // Short-circuit, don't do the expensive bit of allocating a wrappedStream. - wrappedStream := grpc_middleware.WrapServerStream(stream) - wrappedStream.WrappedContext = newCtx - return handler(srv, wrappedStream) - } - wrapped := &wrappedStream{stream, info, o, newCtx, true} - err := handler(srv, wrapped) - return err - } -} - -// wrappedStream is a thin wrapper around grpc.ServerStream that allows modifying context and extracts log fields from the initial message. -type wrappedStream struct { - grpc.ServerStream - info *grpc.StreamServerInfo - opts *options - // WrappedContext is the wrapper's own Context. You can assign it. - WrappedContext context.Context - initial bool -} - -// Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context() -func (w *wrappedStream) Context() context.Context { - return w.WrappedContext -} - -func (w *wrappedStream) RecvMsg(m interface{}) error { - err := w.ServerStream.RecvMsg(m) - // We only do log fields extraction on the single-request of a server-side stream. - if !w.info.IsClientStream || w.opts.requestFieldsFromInitial && w.initial { - w.initial = false - - setRequestFieldTags(w.Context(), w.opts.requestFieldsFunc, w.info.FullMethod, m) - } - return err -} - -func newTagsForCtx(ctx context.Context) context.Context { - t := NewTags() - if peer, ok := peer.FromContext(ctx); ok { - t.Set("peer.address", peer.Addr.String()) - } - return SetInContext(ctx, t) -} - -func setRequestFieldTags(ctx context.Context, f RequestFieldExtractorFunc, fullMethodName string, req interface{}) { - if valMap := f(fullMethodName, req); valMap != nil { - t := Extract(ctx) - for k, v := range valMap { - t.Set("grpc.request."+k, v) - } - } -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/options.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/options.go deleted file mode 100644 index 952775f88..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags/options.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2017 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_ctxtags - -var ( - defaultOptions = &options{ - requestFieldsFunc: nil, - } -) - -type options struct { - requestFieldsFunc RequestFieldExtractorFunc - requestFieldsFromInitial bool -} - -func evaluateOptions(opts []Option) *options { - optCopy := &options{} - *optCopy = *defaultOptions - for _, o := range opts { - o(optCopy) - } - return optCopy -} - -type Option func(*options) - -// WithFieldExtractor customizes the function for extracting log fields from protobuf messages, for -// unary and server-streamed methods only. -func WithFieldExtractor(f RequestFieldExtractorFunc) Option { - return func(o *options) { - o.requestFieldsFunc = f - } -} - -// WithFieldExtractorForInitialReq customizes the function for extracting log fields from protobuf messages, -// for all unary and streaming methods. For client-streams and bidirectional-streams, the tags will be -// extracted from the first message from the client. -func WithFieldExtractorForInitialReq(f RequestFieldExtractorFunc) Option { - return func(o *options) { - o.requestFieldsFunc = f - o.requestFieldsFromInitial = true - } -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/wrappers.go b/vendor/github.com/grpc-ecosystem/go-grpc-middleware/wrappers.go deleted file mode 100644 index 05ccfb3f2..000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-middleware/wrappers.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_middleware - -import ( - "context" - - "google.golang.org/grpc" -) - -// WrappedServerStream is a thin wrapper around grpc.ServerStream that allows modifying context. -type WrappedServerStream struct { - grpc.ServerStream - // WrappedContext is the wrapper's own Context. You can assign it. - WrappedContext context.Context -} - -// Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context() -func (w *WrappedServerStream) Context() context.Context { - return w.WrappedContext -} - -// WrapServerStream returns a ServerStream that has the ability to overwrite context. -func WrapServerStream(stream grpc.ServerStream) *WrappedServerStream { - if existing, ok := stream.(*WrappedServerStream); ok { - return existing - } - return &WrappedServerStream{ServerStream: stream, WrappedContext: stream.Context()} -} diff --git a/vendor/modules.txt b/vendor/modules.txt index b31aba856..6dd7ab316 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -179,14 +179,6 @@ github.com/google/uuid # github.com/gopherjs/gopherjs v1.17.2 ## explicit; go 1.17 github.com/gopherjs/gopherjs/js -# github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 -## explicit; go 1.14 -github.com/grpc-ecosystem/go-grpc-middleware -github.com/grpc-ecosystem/go-grpc-middleware/logging -github.com/grpc-ecosystem/go-grpc-middleware/logging/settable -github.com/grpc-ecosystem/go-grpc-middleware/logging/zap -github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap -github.com/grpc-ecosystem/go-grpc-middleware/tags # github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 ## explicit; go 1.14 github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule