Repository: go-kratos/kratos
Pull request #2935 (2023-07-28 10:10:37)

build(deps): bump google.golang.org/grpc from 1.56.1 to 1.57.0 in /contrib/config/etcd
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.56.1 to 1.57.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/grpc/grpc-go/releases">google.golang.org/grpc's releases</a>.</em></p>
<blockquote>
<h2>Release 1.57.0</h2>
<h1>API Changes</h1>
<ul>
<li>resolver: remove deprecated <code>Target.Scheme</code> and <code>Target.Authority</code>.  Use <code>URL.Scheme</code> and <code>URL.Host</code> instead, respectively (<a href="https://redirect.github.com/grpc/grpc-go/issues/6363">#6363</a>)</li>
</ul>
<h1>Behavior Changes</h1>
<ul>
<li>client: percent-encode the default authority for the channel (<a href="https://redirect.github.com/grpc/grpc-go/issues/6428">#6428</a>)</li>
<li>xds: require EDS service name to be set in a CDS cluster with an 'xdstp' resource name (gRFC A47) (<a href="https://redirect.github.com/grpc/grpc-go/issues/6438">#6438</a>)</li>
</ul>
<h1>New Features</h1>
<ul>
<li>reflection: support the v1 reflection service and update <code>Register</code> to register both v1alpha and v1 (<a href="https://redirect.github.com/grpc/grpc-go/issues/6329">#6329</a>)</li>
<li>xds: add support for string matcher in RBAC header matching (<a href="https://redirect.github.com/grpc/grpc-go/issues/6419">#6419</a>)</li>
<li>alts: add support for <code>GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES</code> env var (<a href="https://redirect.github.com/grpc/grpc-go/issues/6267">#6267</a>)</li>
<li>balancer/weightedroundrobin: de-experimentalize name of LB policy (<a href="https://redirect.github.com/grpc/grpc-go/issues/6477">#6477</a>)</li>
</ul>
<h1>Bug Fixes</h1>
<ul>
<li>status: <code>status.FromError</code> now returns an error with <code>codes.Unknown</code> when the error implements the <code>GRPCStatus()</code> method, and calling <code>GRPCStatus()</code> returns <code>nil</code> (<a href="https://redirect.github.com/grpc/grpc-go/issues/6374">#6374</a>)
<ul>
<li>Special Thanks: <a href="https://github.com/atollena"><code>@​atollena</code></a></li>
</ul>
</li>
<li>server: fix bug preventing TCP user timeout from being set on the connection when TLS is used (<a href="https://redirect.github.com/grpc/grpc-go/issues/6321">#6321</a>)
<ul>
<li>Special Thanks: <a href="https://github.com/tobotg"><code>@​tobotg</code></a></li>
</ul>
</li>
<li>client: eliminate connection churn during an address update that differs only in balancer attributes (<a href="https://redirect.github.com/grpc/grpc-go/issues/6439">#6439</a>)</li>
<li>clusterresolver: handle EDS nacks, resource-not-found errors, and DNS Resolver errors correctly (<a href="https://redirect.github.com/grpc/grpc-go/issues/6436">#6436</a>, <a href="https://redirect.github.com/grpc/grpc-go/issues/6461">#6461</a>)</li>
<li>xds/ringhash: cache connectivity state of subchannels inside picker to avoid rare races (<a href="https://redirect.github.com/grpc/grpc-go/issues/6351">#6351</a>)</li>
</ul>
<h2>Release 1.56.2</h2>
<ul>
<li>status: To fix a panic, <code>status.FromError</code> now returns an error with <code>codes.Unknown</code> when the error implements the <code>GRPCStatus()</code> method, and calling <code>GRPCStatus()</code> returns <code>nil</code>. (<a href="https://redirect.github.com/grpc/grpc-go/issues/6374">#6374</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/grpc/grpc-go/commit/87bf02ad24f6cc071d2553eb5d62332194bba1fe"><code>87bf02a</code></a> Change version to 1.57.0 (<a href="https://redirect.github.com/grpc/grpc-go/issues/6448">#6448</a>)</li>
<li><a href="https://github.com/grpc/grpc-go/commit/6b64be9784958b37d2b1d7618b37a7f8a824654b"><code>6b64be9</code></a> resolver/weighted_round_robin: remove experimental suffix from name</li>
<li><a href="https://github.com/grpc/grpc-go/commit/9489082068eb8cade6ea4f943ac83a205e0e382b"><code>9489082</code></a> github: replace deprecated command with environment file (<a href="https://redirect.github.com/grpc/grpc-go/issues/6417">#6417</a>)</li>
<li><a href="https://github.com/grpc/grpc-go/commit/d1868a539b5acb10daceeeb4fcbc6a8dedc7a532"><code>d1868a5</code></a> clusterresolver: add logs for dns discovery mechanism error cases (<a href="https://redirect.github.com/grpc/grpc-go/issues/6444">#6444</a>)</li>
<li><a href="https://github.com/grpc/grpc-go/commit/8e9c8f8e7133eb7ed64438837636dae2c5d92ce6"><code>8e9c8f8</code></a> grpc: do not use balancer attributes during address comparison (<a href="https://redirect.github.com/grpc/grpc-go/issues/6439">#6439</a>)</li>
<li><a href="https://github.com/grpc/grpc-go/commit/db32c5bfeb563e7ce6661b37d6a55688cbeb4a20"><code>db32c5b</code></a> Fix preloader mode in benchmarks (<a href="https://redirect.github.com/grpc/grpc-go/issues/6359">#6359</a>)</li>
<li><a href="https://github.com/grpc/grpc-go/commit/f0280f9d3d2f3fbe45de1ab5873a19ec678c74c8"><code>f0280f9</code></a> xds: require EDS service name in new-style CDS clusters (gRFC A47) (<a href="https://redirect.github.com/grpc/grpc-go/issues/6438">#6438</a>)</li>
<li><a href="https://github.com/grpc/grpc-go/commit/bf5b7aecd53ba679d72d43bbf61dee40633f6344"><code>bf5b7ae</code></a> clusterresolver: handle EDS nacks and resource-not-found errors correctly (<a href="https://redirect.github.com/grpc/grpc-go/issues/6">#6</a>...</li>
<li><a href="https://github.com/grpc/grpc-go/commit/fc0aa4689cd434c21cd4cbbbe9ef5af842ccb326"><code>fc0aa46</code></a> client: encode the authority by default (<a href="https://redirect.github.com/grpc/grpc-go/issues/6428">#6428</a>)</li>
<li><a href="https://github.com/grpc/grpc-go/commit/11feb0a9afd844fd2ab1f18dca02ad6a344b21bf"><code>11feb0a</code></a> resolver: delete Target.Scheme and Target.Authority (<a href="https://redirect.github.com/grpc/grpc-go/issues/6363">#6363</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/grpc/grpc-go/compare/v1.56.1...v1.57.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=google.golang.org/grpc&package-manager=go_modules&previous-version=1.56.1&new-version=1.57.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/.github/workflows/gitee-sync.yml b/.github/workflows/gitee-sync.yml
index 843b2819..58d7f352 100644
--- a/.github/workflows/gitee-sync.yml
+++ b/.github/workflows/gitee-sync.yml
@@ -14,7 +14,7 @@ jobs:
       - name: Checkout source code
         uses: actions/checkout@v3
       - name: Mirror Github to Gitee
-        uses: Yikun/hub-mirror-action@v1.2
+        uses: Yikun/hub-mirror-action@v1.3
         with:
           src: github/go-kratos
           dst: gitee/go-kratos
@@ -24,4 +24,4 @@ jobs:
           timeout: 600
           debug: true
           force_update: true
-          static_list: "kratos"
\ No newline at end of file
+          static_list: "kratos"
diff --git a/contrib/config/etcd/go.mod b/contrib/config/etcd/go.mod
index fddf3a24..f95daca9 100644
--- a/contrib/config/etcd/go.mod
+++ b/contrib/config/etcd/go.mod
@@ -5,7 +5,7 @@ go 1.19
 require (
 	github.com/go-kratos/kratos/v2 v2.6.3
 	go.etcd.io/etcd/client/v3 v3.5.8
-	google.golang.org/grpc v1.56.1
+	google.golang.org/grpc v1.57.0
 )
 
 require (
diff --git a/contrib/config/etcd/go.sum b/contrib/config/etcd/go.sum
index f882aee4..3037f49d 100644
--- a/contrib/config/etcd/go.sum
+++ b/contrib/config/etcd/go.sum
@@ -81,8 +81,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 h1:
 google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig=
 google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 h1:DEH99RbiLZhMxrpEJCZ0A+wdTe0EOgou/poSLx9vWf4=
 google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
-google.golang.org/grpc v1.56.1 h1:z0dNfjIl0VpaZ9iSVjA6daGatAYwPGstTjt5vkRMFkQ=
-google.golang.org/grpc v1.56.1/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
+google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
+google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
diff --git a/contrib/config/nacos/go.sum b/contrib/config/nacos/go.sum
index c036030d..3830a339 100644
--- a/contrib/config/nacos/go.sum
+++ b/contrib/config/nacos/go.sum
@@ -2,6 +2,7 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 h1:zOVTBdCKFd9JbCKz9/nt+FovbjPFmb7mUnp8nH9fQBA=
 github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk=
+github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
 github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
 github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
diff --git a/contrib/log/zerolog/go.mod b/contrib/log/zerolog/go.mod
new file mode 100644
index 00000000..048ec449
--- /dev/null
+++ b/contrib/log/zerolog/go.mod
@@ -0,0 +1,14 @@
+module github.com/go-kratos/kratos/contrib/log/zerolog/v2
+
+go 1.19
+
+require (
+	github.com/go-kratos/kratos/v2 v2.6.3
+	github.com/rs/zerolog v1.30.0
+)
+
+require (
+	github.com/mattn/go-colorable v0.1.12 // indirect
+	github.com/mattn/go-isatty v0.0.14 // indirect
+	golang.org/x/sys v0.8.0 // indirect
+)
diff --git a/contrib/log/zerolog/go.sum b/contrib/log/zerolog/go.sum
new file mode 100644
index 00000000..219247d0
--- /dev/null
+++ b/contrib/log/zerolog/go.sum
@@ -0,0 +1,16 @@
+github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
+github.com/go-kratos/kratos/v2 v2.6.3 h1:zuejN8CnszyMnbLWd7ObCN9rLuKucJe2/2P6hHpePDc=
+github.com/go-kratos/kratos/v2 v2.6.3/go.mod h1:nlBMkZueZps7UaP3GdbqG8V8N/eAX0jh019OKSm4xew=
+github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
+github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
+github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
+github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
+github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
+github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
+github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
+golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
+golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
diff --git a/contrib/log/zerolog/zerolog.go b/contrib/log/zerolog/zerolog.go
new file mode 100644
index 00000000..bca49ba0
--- /dev/null
+++ b/contrib/log/zerolog/zerolog.go
@@ -0,0 +1,54 @@
+package zerolog
+
+import (
+	"github.com/rs/zerolog"
+
+	"github.com/go-kratos/kratos/v2/log"
+)
+
+var _ log.Logger = (*Logger)(nil)
+
+type Logger struct {
+	log *zerolog.Logger
+}
+
+func NewLogger(logger *zerolog.Logger) log.Logger {
+	return &Logger{
+		log: logger,
+	}
+}
+
+func (l *Logger) Log(level log.Level, keyvals ...interface{}) (err error) {
+	var event *zerolog.Event
+	if len(keyvals) == 0 {
+		return nil
+	}
+	if len(keyvals)%2 != 0 {
+		keyvals = append(keyvals, "")
+	}
+
+	switch level {
+	case log.LevelDebug:
+		event = l.log.Debug()
+	case log.LevelInfo:
+		event = l.log.Info()
+	case log.LevelWarn:
+		event = l.log.Warn()
+	case log.LevelError:
+		event = l.log.Error()
+	case log.LevelFatal:
+		event = l.log.Fatal()
+	default:
+		event = l.log.Debug()
+	}
+
+	for i := 0; i < len(keyvals); i += 2 {
+		key, ok := keyvals[i].(string)
+		if !ok {
+			continue
+		}
+		event = event.Any(key, keyvals[i+1])
+	}
+	event.Send()
+	return
+}
diff --git a/transport/http/server.go b/transport/http/server.go
index 31a3c95e..9958a08a 100644
--- a/transport/http/server.go
+++ b/transport/http/server.go
@@ -220,6 +220,14 @@ func (s *Server) WalkRoute(fn WalkRouteFunc) error {
 	})
 }
 
+// WalkHandle walks the router and all its sub-routers, calling walkFn for each route in the tree.
+func (s *Server) WalkHandle(handle func(method, path string, handler http.HandlerFunc)) error {
+	return s.WalkRoute(func(r RouteInfo) error {
+		handle(r.Method, r.Path, s.ServeHTTP)
+		return nil
+	})
+}
+
 // Route registers an HTTP router.
 func (s *Server) Route(prefix string, filters ...FilterFunc) *Router {
 	return newRouter(prefix, s, filters...)


Test patch:
diff --git a/contrib/log/zerolog/zerolog_test.go b/contrib/log/zerolog/zerolog_test.go
new file mode 100644
index 00000000..4f3714b5
--- /dev/null
+++ b/contrib/log/zerolog/zerolog_test.go
@@ -0,0 +1,45 @@
+package zerolog
+
+import (
+	"testing"
+
+	"github.com/rs/zerolog"
+
+	"github.com/go-kratos/kratos/v2/log"
+)
+
+type testWriteSyncer struct {
+	output []string
+}
+
+func (x *testWriteSyncer) Write(p []byte) (n int, err error) {
+	x.output = append(x.output, string(p))
+	return len(p), nil
+}
+
+func TestLogger(t *testing.T) {
+	syncer := &testWriteSyncer{}
+	zerolog.TimeFieldFormat = "2006-01-02 15:04:05.000"
+	zlogger := zerolog.New(syncer)
+	logger := NewLogger(&zlogger)
+
+	klog := log.NewHelper(logger)
+
+	klog.Debugw("log", "debug")
+	klog.Infow("log", "info")
+	klog.Warnw("log", "warn")
+	klog.Errorw("log", "error")
+
+	except := []string{
+		"{\"level\":\"debug\",\"log\":\"debug\"}\n",
+		"{\"level\":\"info\",\"log\":\"info\"}\n",
+		"{\"level\":\"warn\",\"log\":\"warn\"}\n",
+		"{\"level\":\"error\",\"log\":\"error\"}\n",
+	}
+	for i, s := range except {
+		if s != syncer.output[i] {
+			t.Logf("except=%s, got=%s", s, syncer.output[i])
+			t.Fail()
+		}
+	}
+}