From ffa1f6f809340f48355a7c620d91059aac1c4365 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Tue, 26 Jul 2022 11:03:10 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20benchmark=20testing=20for?= =?UTF-8?q?=20Ranger=20RPC,=20GRPC=20and=20Twirp=20(#8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Hartmann --- .gitignore | 3 + benchmark/Makefile | 14 + benchmark/README.md | 33 + benchmark/go.mod | 33 + benchmark/go.sum | 429 ++++++ benchmark/grpcbench/grpcbench.go | 42 + benchmark/grpcbench/grpcbench.pb.go | 375 +++++ benchmark/grpcbench/grpcbench.proto | 27 + benchmark/grpcbench/grpcbench_grpc.pb.go | 141 ++ benchmark/rangerbench/rangerbench.go | 56 + benchmark/rangerbench/rangerbench.pb.go | 376 +++++ benchmark/rangerbench/rangerbench.proto | 27 + benchmark/rangerbench/rangerbench.ranger.go | 142 ++ benchmark/request_time_test.go | 85 ++ benchmark/sample/cert.go | 51 + benchmark/sample/sample.go | 22 + benchmark/twirpbench/twirpbench.go | 56 + benchmark/twirpbench/twirpbench.pb.go | 376 +++++ benchmark/twirpbench/twirpbench.proto | 27 + benchmark/twirpbench/twirpbench.twirp.go | 1385 +++++++++++++++++++ client.go | 1 - 21 files changed, 3700 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 benchmark/Makefile create mode 100644 benchmark/README.md create mode 100644 benchmark/go.mod create mode 100644 benchmark/go.sum create mode 100644 benchmark/grpcbench/grpcbench.go create mode 100644 benchmark/grpcbench/grpcbench.pb.go create mode 100644 benchmark/grpcbench/grpcbench.proto create mode 100644 benchmark/grpcbench/grpcbench_grpc.pb.go create mode 100644 benchmark/rangerbench/rangerbench.go create mode 100644 benchmark/rangerbench/rangerbench.pb.go create mode 100644 benchmark/rangerbench/rangerbench.proto create mode 100644 benchmark/rangerbench/rangerbench.ranger.go create mode 100644 benchmark/request_time_test.go create mode 100644 benchmark/sample/cert.go create mode 100644 benchmark/sample/sample.go create mode 100644 benchmark/twirpbench/twirpbench.go create mode 100644 benchmark/twirpbench/twirpbench.pb.go create mode 100644 benchmark/twirpbench/twirpbench.proto create mode 100644 benchmark/twirpbench/twirpbench.twirp.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f9e6413 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +benchmark/cpu.out +benchmark/mem.out +benchmark/trace.out diff --git a/benchmark/Makefile b/benchmark/Makefile new file mode 100644 index 0000000..32b103f --- /dev/null +++ b/benchmark/Makefile @@ -0,0 +1,14 @@ + +prep: + command -v protoc-gen-go || go install github.com/golang/protobuf/protoc-gen-go + command -v protoc-gen-go-grpc || go install google.golang.org/grpc/cmd/protoc-gen-go-grpc + command -v protoc-gen-twirp || go install github.com/twitchtv/twirp/protoc-gen-twirp + command -v hey || go install github.com/rakyll/hey + go generate ./twirpbench + go generate ./grpcbench + go generate ./rangerbench + +.PHONY: bench +bench: + # NOTE: if you see too many open files error, set `ulimit -n 10240` on macOS + go test -v -benchmem -benchtime 5s -bench . # -cpuprofile=cpu.out -memprofile=mem.out -trace trace.out \ No newline at end of file diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 0000000..87fb43c --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,33 @@ + + +Tested on M1 macOS + +# Twirp + +``` +=== RUN TestLoad/twrip_http_protobuf_roundtrip + +Summary: + Total: 0.0104 secs + Slowest: 0.0066 secs + Fastest: 0.0008 secs + Average: 0.0024 secs + Requests/sec: 19211.2956 + + Total data: 33600 bytes + Size/request: 168 bytes +``` + +# Ranger + +``` +=== RUN TestLoad/ranger_http_protobuf_roundtrip + +Summary: + Total: 0.1280 secs + Slowest: 0.0871 secs + Fastest: 0.0010 secs + Average: 0.0276 secs + Requests/sec: 1562.8643 +``` + diff --git a/benchmark/go.mod b/benchmark/go.mod new file mode 100644 index 0000000..7bd30eb --- /dev/null +++ b/benchmark/go.mod @@ -0,0 +1,33 @@ +module go.mondoo.com/ranger-rpc/benchmark + +go 1.18 + +require ( + github.com/rakyll/hey v0.1.4 + github.com/twitchtv/twirp v8.1.2+incompatible + go.mondoo.com/ranger-rpc v0.0.0-00010101000000-000000000000 + golang.org/x/net v0.0.0-20220708220712-1185a9018129 + google.golang.org/grpc v1.48.0 + google.golang.org/protobuf v1.28.0 +) + +require ( + github.com/cockroachdb/errors v1.9.0 // indirect + github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect + github.com/cockroachdb/redact v1.1.3 // indirect + github.com/getsentry/sentry-go v0.13.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/kr/pretty v0.3.0 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/rogpeppe/go-internal v1.8.1 // indirect + github.com/rs/zerolog v1.27.0 // indirect + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect + golang.org/x/text v0.3.7 // indirect + google.golang.org/genproto v0.0.0-20220715211116-798f69b842b9 // indirect +) + +replace go.mondoo.com/ranger-rpc => /Users/chris/go/src/go.mondoo.com/ranger-rpc diff --git a/benchmark/go.sum b/benchmark/go.sum new file mode 100644 index 0000000..04a5c6b --- /dev/null +++ b/benchmark/go.sum @@ -0,0 +1,429 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw= +github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= +github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w= +github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo= +github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= +github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM= +github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= +github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cockroachdb/datadriven v1.0.1-0.20211007161720-b558070c3be0/go.mod h1:5Ib8Meh+jk1RlHIXej6Pzevx/NLlNvQB9pmSBZErGA4= +github.com/cockroachdb/datadriven v1.0.1-0.20220214170620-9913f5bc19b7/go.mod h1:hi0MtSY3AYDQNDi83kDkMH5/yqM/CsIrsOITkSoH7KI= +github.com/cockroachdb/errors v1.6.1/go.mod h1:tm6FTP5G81vwJ5lC0SizQo374JNCOPrHyXGitRJoDqM= +github.com/cockroachdb/errors v1.8.8/go.mod h1:z6VnEL3hZ/2ONZEvG7S5Ym0bU2AqPcEKnIiA1wbsSu0= +github.com/cockroachdb/errors v1.9.0 h1:B48dYem5SlAY7iU8AKsgedb4gH6mo+bDkbtLIvM/a88= +github.com/cockroachdb/errors v1.9.0/go.mod h1:vaNcEYYqbIqB5JhKBhFV9CneUqeuEbB2OYJBK4GBNYQ= +github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= +github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f h1:6jduT9Hfc0njg5jJ1DdKCFPdMBrp/mdZfCpa5h+WM74= +github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= +github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= +github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= +github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc= +github.com/getsentry/sentry-go v0.12.0/go.mod h1:NSap0JBYWzHND8oMbyi0+XZhUalc1TBdRL1M71JZW2c= +github.com/getsentry/sentry-go v0.13.0 h1:20dgTiUSfxRB/EhMPtxcL9ZEbM1ZdR+W/7f7NWD+xWo= +github.com/getsentry/sentry-go v0.13.0/go.mod h1:EOsfu5ZdvKPfeHYV6pTVQnsjfp30+XA7//UooKNumH0= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= +github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= +github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= +github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= +github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= +github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= +github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= +github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= +github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4= +github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/gomodule/redigo v1.7.1-0.20190724094224-574c33c3df38/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/hydrogen18/memlistener v0.0.0-20141126152155-54553eb933fb/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= +github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= +github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI= +github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0= +github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0/go.mod h1:pMCz62A0xJL6I+umB2YTlFRwWXaDFA0jy+5HzGiJjqI= +github.com/iris-contrib/jade v1.1.3/go.mod h1:H/geBymxJhShH5kecoiOCSssPX7QWYH7UaeZTSWddIk= +github.com/iris-contrib/pongo2 v0.0.1/go.mod h1:Ssh+00+3GAZqSQb30AvBRNxBx7rf0GqwkjqxNd0u65g= +github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= +github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= +github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= +github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk= +github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8= +github.com/kataras/iris/v12 v12.0.1/go.mod h1:udK4vLQKkdDqMGJJVd/msuMtN6hpYJhg/lSzuxjhO+U= +github.com/kataras/iris/v12 v12.1.8/go.mod h1:LMYy4VlP67TQ3Zgriz8RE2h2kMZV2SgMYbq3UhfoFmE= +github.com/kataras/neffos v0.0.10/go.mod h1:ZYmJC07hQPW67eKuzlfY7SO3bC0mw83A3j6im82hfqw= +github.com/kataras/neffos v0.0.14/go.mod h1:8lqADm8PnbeFfL7CLXh1WHw53dG27MC3pgi2R1rmoTE= +github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d/go.mod h1:NV88laa9UiiDuX9AhMbDPkGYSPugBOV6yTZB1l2K9Z0= +github.com/kataras/pio v0.0.2/go.mod h1:hAoW0t9UmXi4R5Oyq5Z4irTbaTsOemSrDGUtaTl7Dro= +github.com/kataras/sitemap v0.0.5/go.mod h1:KY2eugMKiPwsJgx7+U103YZehfvNGOXURubcGyk0Bz8= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.9.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= +github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y= +github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +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.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +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/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= +github.com/mediocregopher/mediocre-go-lib v0.0.0-20181029021733-cb65787f37ed/go.mod h1:dSsfyI2zABAdhcbvkXqgxOxrCsbYeHCPgrZkku60dSg= +github.com/mediocregopher/radix/v3 v3.3.0/go.mod h1:EmfVyvspXz1uZEyPBMyGK+kjWiKQGvsUt6O3Pj+LDCQ= +github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= +github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= +github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= +github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= +github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= +github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= +github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= +github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0= +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/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= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rakyll/hey v0.1.4 h1:hhc8GIqHN4+rPFZvkM9lkCQGi7da0sINM83xxpFkbPA= +github.com/rakyll/hey v0.1.4/go.mod h1:nAOTOo+L52KB9SZq/M6J18kxjto4yVtXQDjU2HgjUPI= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= +github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs= +github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g= +github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/twitchtv/twirp v8.1.2+incompatible h1:0O6TfzZW09ZP5r+ORA90XQEE3PTgA6C7MBbl2KxvVgE= +github.com/twitchtv/twirp v8.1.2+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w= +github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= +github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= +github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= +github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= +github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181017193950-04a2e542c03f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190327091125-710a502c58a2/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220708220712-1185a9018129 h1:vucSRfWwTsoXro7P+3Cjlr6flUMtzCwzlvkxEQtHHB0= +golang.org/x/net v0.0.0-20220708220712-1185a9018129/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +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.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180518175338-11a468237815/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20220715211116-798f69b842b9 h1:1aEQRgZ4Gks2SRAkLzIPpIszRazwVfjSFe1cKc+e0Jg= +google.golang.org/genproto v0.0.0-20220715211116-798f69b842b9/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE= +google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +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.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= +gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/benchmark/grpcbench/grpcbench.go b/benchmark/grpcbench/grpcbench.go new file mode 100644 index 0000000..e462174 --- /dev/null +++ b/benchmark/grpcbench/grpcbench.go @@ -0,0 +1,42 @@ +package grpcbench + +import ( + fmt "fmt" + "net" + + "go.mondoo.com/ranger-rpc/benchmark/sample" + context "golang.org/x/net/context" + "google.golang.org/grpc" +) + +//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative grpcbench.proto + +type BenchmarkServer struct { + UnimplementedBenchmarkServiceServer +} + +func (b *BenchmarkServer) RpcSmall(ctx context.Context, in *SmallQuery) (*SmallResponse, error) { + return &SmallResponse{Id: in.Id, Message: in.Message, Name: in.Name}, nil +} +func (b *BenchmarkServer) RpcEmpty(ctx context.Context, in *Empty) (*DefaultResponse, error) { + return &DefaultResponse{Message: sample.Message}, nil +} + +func Serve(port int) int { + lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port)) + if err != nil { + panic(fmt.Sprintf("GRPC error %v", err)) + } + + s := grpc.NewServer() + RegisterBenchmarkServiceServer(s, &BenchmarkServer{}) + + go func() { + err := s.Serve(lis) + if err != nil { + fmt.Printf("GRPC error %v", err) + } + }() + + return lis.Addr().(*net.TCPAddr).Port +} diff --git a/benchmark/grpcbench/grpcbench.pb.go b/benchmark/grpcbench/grpcbench.pb.go new file mode 100644 index 0000000..e8a1f2a --- /dev/null +++ b/benchmark/grpcbench/grpcbench.pb.go @@ -0,0 +1,375 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.19.1 +// source: grpcbench.proto + +package grpcbench + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type SmallQuery struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Name []string `protobuf:"bytes,3,rep,name=name,proto3" json:"name,omitempty"` +} + +func (x *SmallQuery) Reset() { + *x = SmallQuery{} + if protoimpl.UnsafeEnabled { + mi := &file_grpcbench_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SmallQuery) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SmallQuery) ProtoMessage() {} + +func (x *SmallQuery) ProtoReflect() protoreflect.Message { + mi := &file_grpcbench_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SmallQuery.ProtoReflect.Descriptor instead. +func (*SmallQuery) Descriptor() ([]byte, []int) { + return file_grpcbench_proto_rawDescGZIP(), []int{0} +} + +func (x *SmallQuery) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SmallQuery) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *SmallQuery) GetName() []string { + if x != nil { + return x.Name + } + return nil +} + +type SmallResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Name []string `protobuf:"bytes,3,rep,name=name,proto3" json:"name,omitempty"` +} + +func (x *SmallResponse) Reset() { + *x = SmallResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_grpcbench_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SmallResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SmallResponse) ProtoMessage() {} + +func (x *SmallResponse) ProtoReflect() protoreflect.Message { + mi := &file_grpcbench_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SmallResponse.ProtoReflect.Descriptor instead. +func (*SmallResponse) Descriptor() ([]byte, []int) { + return file_grpcbench_proto_rawDescGZIP(), []int{1} +} + +func (x *SmallResponse) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SmallResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *SmallResponse) GetName() []string { + if x != nil { + return x.Name + } + return nil +} + +type Empty struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Empty) Reset() { + *x = Empty{} + if protoimpl.UnsafeEnabled { + mi := &file_grpcbench_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_grpcbench_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_grpcbench_proto_rawDescGZIP(), []int{2} +} + +type DefaultResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *DefaultResponse) Reset() { + *x = DefaultResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_grpcbench_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DefaultResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DefaultResponse) ProtoMessage() {} + +func (x *DefaultResponse) ProtoReflect() protoreflect.Message { + mi := &file_grpcbench_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DefaultResponse.ProtoReflect.Descriptor instead. +func (*DefaultResponse) Descriptor() ([]byte, []int) { + return file_grpcbench_proto_rawDescGZIP(), []int{3} +} + +func (x *DefaultResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_grpcbench_proto protoreflect.FileDescriptor + +var file_grpcbench_proto_rawDesc = []byte{ + 0x0a, 0x0f, 0x67, 0x72, 0x70, 0x63, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x17, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, + 0x2e, 0x67, 0x72, 0x70, 0x63, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x22, 0x4a, 0x0a, 0x0a, 0x53, 0x6d, + 0x61, 0x6c, 0x6c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x4d, 0x0a, 0x0d, 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x2b, + 0x0a, 0x0f, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xc5, 0x01, 0x0a, 0x10, + 0x42, 0x65, 0x6e, 0x63, 0x68, 0x6d, 0x61, 0x72, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x59, 0x0a, 0x08, 0x52, 0x70, 0x63, 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x12, 0x23, 0x2e, 0x6d, + 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x67, 0x72, 0x70, + 0x63, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x51, 0x75, 0x65, 0x72, + 0x79, 0x1a, 0x26, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, + 0x72, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x53, 0x6d, 0x61, 0x6c, + 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x56, 0x0a, 0x08, 0x52, + 0x70, 0x63, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x1e, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, + 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x62, 0x65, 0x6e, 0x63, + 0x68, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x28, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, + 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x62, 0x65, 0x6e, 0x63, + 0x68, 0x2e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x6f, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2d, 0x72, 0x70, 0x63, 0x2f, + 0x62, 0x65, 0x6e, 0x63, 0x68, 0x6d, 0x61, 0x72, 0x6b, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x62, 0x65, + 0x6e, 0x63, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_grpcbench_proto_rawDescOnce sync.Once + file_grpcbench_proto_rawDescData = file_grpcbench_proto_rawDesc +) + +func file_grpcbench_proto_rawDescGZIP() []byte { + file_grpcbench_proto_rawDescOnce.Do(func() { + file_grpcbench_proto_rawDescData = protoimpl.X.CompressGZIP(file_grpcbench_proto_rawDescData) + }) + return file_grpcbench_proto_rawDescData +} + +var file_grpcbench_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_grpcbench_proto_goTypes = []interface{}{ + (*SmallQuery)(nil), // 0: mondoo.ranger.grpcbench.SmallQuery + (*SmallResponse)(nil), // 1: mondoo.ranger.grpcbench.SmallResponse + (*Empty)(nil), // 2: mondoo.ranger.grpcbench.Empty + (*DefaultResponse)(nil), // 3: mondoo.ranger.grpcbench.DefaultResponse +} +var file_grpcbench_proto_depIdxs = []int32{ + 0, // 0: mondoo.ranger.grpcbench.BenchmarkService.RpcSmall:input_type -> mondoo.ranger.grpcbench.SmallQuery + 2, // 1: mondoo.ranger.grpcbench.BenchmarkService.RpcEmpty:input_type -> mondoo.ranger.grpcbench.Empty + 1, // 2: mondoo.ranger.grpcbench.BenchmarkService.RpcSmall:output_type -> mondoo.ranger.grpcbench.SmallResponse + 3, // 3: mondoo.ranger.grpcbench.BenchmarkService.RpcEmpty:output_type -> mondoo.ranger.grpcbench.DefaultResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_grpcbench_proto_init() } +func file_grpcbench_proto_init() { + if File_grpcbench_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_grpcbench_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SmallQuery); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpcbench_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SmallResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpcbench_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Empty); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpcbench_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DefaultResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_grpcbench_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_grpcbench_proto_goTypes, + DependencyIndexes: file_grpcbench_proto_depIdxs, + MessageInfos: file_grpcbench_proto_msgTypes, + }.Build() + File_grpcbench_proto = out.File + file_grpcbench_proto_rawDesc = nil + file_grpcbench_proto_goTypes = nil + file_grpcbench_proto_depIdxs = nil +} diff --git a/benchmark/grpcbench/grpcbench.proto b/benchmark/grpcbench/grpcbench.proto new file mode 100644 index 0000000..a0dc82b --- /dev/null +++ b/benchmark/grpcbench/grpcbench.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package mondoo.ranger.grpcbench; +option go_package = "go.mondoo.com/ranger-rpc/benchmark/grpcbench"; + +service BenchmarkService { + rpc RpcSmall(SmallQuery) returns (SmallResponse) {} + rpc RpcEmpty(Empty) returns (DefaultResponse) {} +} + +message SmallQuery { + int64 id = 1; + string message = 2; + repeated string name = 3; +} + +message SmallResponse { + int64 id = 1; + string message = 2; + repeated string name = 3; +} + +message Empty {} + +message DefaultResponse { + string message = 1; +} \ No newline at end of file diff --git a/benchmark/grpcbench/grpcbench_grpc.pb.go b/benchmark/grpcbench/grpcbench_grpc.pb.go new file mode 100644 index 0000000..5f0a669 --- /dev/null +++ b/benchmark/grpcbench/grpcbench_grpc.pb.go @@ -0,0 +1,141 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.1 +// source: grpcbench.proto + +package grpcbench + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// BenchmarkServiceClient is the client API for BenchmarkService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type BenchmarkServiceClient interface { + RpcSmall(ctx context.Context, in *SmallQuery, opts ...grpc.CallOption) (*SmallResponse, error) + RpcEmpty(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*DefaultResponse, error) +} + +type benchmarkServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewBenchmarkServiceClient(cc grpc.ClientConnInterface) BenchmarkServiceClient { + return &benchmarkServiceClient{cc} +} + +func (c *benchmarkServiceClient) RpcSmall(ctx context.Context, in *SmallQuery, opts ...grpc.CallOption) (*SmallResponse, error) { + out := new(SmallResponse) + err := c.cc.Invoke(ctx, "/mondoo.ranger.grpcbench.BenchmarkService/RpcSmall", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *benchmarkServiceClient) RpcEmpty(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*DefaultResponse, error) { + out := new(DefaultResponse) + err := c.cc.Invoke(ctx, "/mondoo.ranger.grpcbench.BenchmarkService/RpcEmpty", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BenchmarkServiceServer is the server API for BenchmarkService service. +// All implementations must embed UnimplementedBenchmarkServiceServer +// for forward compatibility +type BenchmarkServiceServer interface { + RpcSmall(context.Context, *SmallQuery) (*SmallResponse, error) + RpcEmpty(context.Context, *Empty) (*DefaultResponse, error) + mustEmbedUnimplementedBenchmarkServiceServer() +} + +// UnimplementedBenchmarkServiceServer must be embedded to have forward compatible implementations. +type UnimplementedBenchmarkServiceServer struct { +} + +func (UnimplementedBenchmarkServiceServer) RpcSmall(context.Context, *SmallQuery) (*SmallResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RpcSmall not implemented") +} +func (UnimplementedBenchmarkServiceServer) RpcEmpty(context.Context, *Empty) (*DefaultResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RpcEmpty not implemented") +} +func (UnimplementedBenchmarkServiceServer) mustEmbedUnimplementedBenchmarkServiceServer() {} + +// UnsafeBenchmarkServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BenchmarkServiceServer will +// result in compilation errors. +type UnsafeBenchmarkServiceServer interface { + mustEmbedUnimplementedBenchmarkServiceServer() +} + +func RegisterBenchmarkServiceServer(s grpc.ServiceRegistrar, srv BenchmarkServiceServer) { + s.RegisterService(&BenchmarkService_ServiceDesc, srv) +} + +func _BenchmarkService_RpcSmall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SmallQuery) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BenchmarkServiceServer).RpcSmall(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/mondoo.ranger.grpcbench.BenchmarkService/RpcSmall", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BenchmarkServiceServer).RpcSmall(ctx, req.(*SmallQuery)) + } + return interceptor(ctx, in, info, handler) +} + +func _BenchmarkService_RpcEmpty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BenchmarkServiceServer).RpcEmpty(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/mondoo.ranger.grpcbench.BenchmarkService/RpcEmpty", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BenchmarkServiceServer).RpcEmpty(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +// BenchmarkService_ServiceDesc is the grpc.ServiceDesc for BenchmarkService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var BenchmarkService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "mondoo.ranger.grpcbench.BenchmarkService", + HandlerType: (*BenchmarkServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RpcSmall", + Handler: _BenchmarkService_RpcSmall_Handler, + }, + { + MethodName: "RpcEmpty", + Handler: _BenchmarkService_RpcEmpty_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "grpcbench.proto", +} diff --git a/benchmark/rangerbench/rangerbench.go b/benchmark/rangerbench/rangerbench.go new file mode 100644 index 0000000..e07d41b --- /dev/null +++ b/benchmark/rangerbench/rangerbench.go @@ -0,0 +1,56 @@ +package rangerbench + +import ( + "context" + "crypto/tls" + "fmt" + "net" + "net/http" + + "go.mondoo.com/ranger-rpc/benchmark/sample" +) + +//go:generate protoc --go_out=. --go_opt=paths=source_relative --rangerrpc_out=. rangerbench.proto + +type BenchmarkServer struct{} + +func (b *BenchmarkServer) RpcSmall(ctx context.Context, in *SmallQuery) (*SmallResponse, error) { + return &SmallResponse{Id: in.Id, Message: in.Message, Name: in.Name}, nil +} +func (b *BenchmarkServer) RpcEmpty(ctx context.Context, in *Empty) (*DefaultResponse, error) { + return &DefaultResponse{Message: sample.Message}, nil +} + +func Serve(port int, ssl bool) int { + // init implementation + s := NewBenchmarkServiceServer(&BenchmarkServer{}) + + var lis net.Listener + var err error + if ssl == false { + lis, err = net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) + if err != nil { + panic(err) + } + } else { + cert, err := tls.X509KeyPair(sample.LocalhostCert, sample.LocalhostKey) + if err != nil { + panic(fmt.Sprintf("httptest: NewTLSServer: %v", err)) + } + config := &tls.Config{Certificates: []tls.Certificate{cert}} + + lis, err = tls.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port), config) + if err != nil { + panic(err) + } + } + + go func() { + err = http.Serve(lis, s) + if err != nil { + panic(err) + } + }() + + return lis.Addr().(*net.TCPAddr).Port +} diff --git a/benchmark/rangerbench/rangerbench.pb.go b/benchmark/rangerbench/rangerbench.pb.go new file mode 100644 index 0000000..793a4a6 --- /dev/null +++ b/benchmark/rangerbench/rangerbench.pb.go @@ -0,0 +1,376 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.19.1 +// source: rangerbench.proto + +package rangerbench + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type SmallQuery struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Name []string `protobuf:"bytes,3,rep,name=name,proto3" json:"name,omitempty"` +} + +func (x *SmallQuery) Reset() { + *x = SmallQuery{} + if protoimpl.UnsafeEnabled { + mi := &file_rangerbench_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SmallQuery) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SmallQuery) ProtoMessage() {} + +func (x *SmallQuery) ProtoReflect() protoreflect.Message { + mi := &file_rangerbench_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SmallQuery.ProtoReflect.Descriptor instead. +func (*SmallQuery) Descriptor() ([]byte, []int) { + return file_rangerbench_proto_rawDescGZIP(), []int{0} +} + +func (x *SmallQuery) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SmallQuery) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *SmallQuery) GetName() []string { + if x != nil { + return x.Name + } + return nil +} + +type SmallResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Name []string `protobuf:"bytes,3,rep,name=name,proto3" json:"name,omitempty"` +} + +func (x *SmallResponse) Reset() { + *x = SmallResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_rangerbench_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SmallResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SmallResponse) ProtoMessage() {} + +func (x *SmallResponse) ProtoReflect() protoreflect.Message { + mi := &file_rangerbench_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SmallResponse.ProtoReflect.Descriptor instead. +func (*SmallResponse) Descriptor() ([]byte, []int) { + return file_rangerbench_proto_rawDescGZIP(), []int{1} +} + +func (x *SmallResponse) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SmallResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *SmallResponse) GetName() []string { + if x != nil { + return x.Name + } + return nil +} + +type Empty struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Empty) Reset() { + *x = Empty{} + if protoimpl.UnsafeEnabled { + mi := &file_rangerbench_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_rangerbench_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_rangerbench_proto_rawDescGZIP(), []int{2} +} + +type DefaultResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *DefaultResponse) Reset() { + *x = DefaultResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_rangerbench_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DefaultResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DefaultResponse) ProtoMessage() {} + +func (x *DefaultResponse) ProtoReflect() protoreflect.Message { + mi := &file_rangerbench_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DefaultResponse.ProtoReflect.Descriptor instead. +func (*DefaultResponse) Descriptor() ([]byte, []int) { + return file_rangerbench_proto_rawDescGZIP(), []int{3} +} + +func (x *DefaultResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_rangerbench_proto protoreflect.FileDescriptor + +var file_rangerbench_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x19, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, + 0x65, 0x72, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x22, 0x4a, + 0x0a, 0x0a, 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x4d, 0x0a, 0x0d, 0x53, 0x6d, + 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x22, 0x2b, 0x0a, 0x0f, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, + 0xcd, 0x01, 0x0a, 0x10, 0x42, 0x65, 0x6e, 0x63, 0x68, 0x6d, 0x61, 0x72, 0x6b, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x5d, 0x0a, 0x08, 0x52, 0x70, 0x63, 0x53, 0x6d, 0x61, 0x6c, 0x6c, + 0x12, 0x25, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, + 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x53, 0x6d, 0x61, + 0x6c, 0x6c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x1a, 0x28, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, + 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x62, 0x65, + 0x6e, 0x63, 0x68, 0x2e, 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x12, 0x5a, 0x0a, 0x08, 0x52, 0x70, 0x63, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, + 0x20, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2e, + 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x1a, 0x2a, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, + 0x72, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x44, 0x65, + 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, + 0x30, 0x5a, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2d, 0x72, 0x70, 0x63, 0x2f, 0x62, 0x65, 0x6e, 0x63, + 0x68, 0x6d, 0x61, 0x72, 0x6b, 0x2f, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x62, 0x65, 0x6e, 0x63, + 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_rangerbench_proto_rawDescOnce sync.Once + file_rangerbench_proto_rawDescData = file_rangerbench_proto_rawDesc +) + +func file_rangerbench_proto_rawDescGZIP() []byte { + file_rangerbench_proto_rawDescOnce.Do(func() { + file_rangerbench_proto_rawDescData = protoimpl.X.CompressGZIP(file_rangerbench_proto_rawDescData) + }) + return file_rangerbench_proto_rawDescData +} + +var file_rangerbench_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_rangerbench_proto_goTypes = []interface{}{ + (*SmallQuery)(nil), // 0: mondoo.ranger.rangerbench.SmallQuery + (*SmallResponse)(nil), // 1: mondoo.ranger.rangerbench.SmallResponse + (*Empty)(nil), // 2: mondoo.ranger.rangerbench.Empty + (*DefaultResponse)(nil), // 3: mondoo.ranger.rangerbench.DefaultResponse +} +var file_rangerbench_proto_depIdxs = []int32{ + 0, // 0: mondoo.ranger.rangerbench.BenchmarkService.RpcSmall:input_type -> mondoo.ranger.rangerbench.SmallQuery + 2, // 1: mondoo.ranger.rangerbench.BenchmarkService.RpcEmpty:input_type -> mondoo.ranger.rangerbench.Empty + 1, // 2: mondoo.ranger.rangerbench.BenchmarkService.RpcSmall:output_type -> mondoo.ranger.rangerbench.SmallResponse + 3, // 3: mondoo.ranger.rangerbench.BenchmarkService.RpcEmpty:output_type -> mondoo.ranger.rangerbench.DefaultResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_rangerbench_proto_init() } +func file_rangerbench_proto_init() { + if File_rangerbench_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_rangerbench_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SmallQuery); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_rangerbench_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SmallResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_rangerbench_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Empty); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_rangerbench_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DefaultResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_rangerbench_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_rangerbench_proto_goTypes, + DependencyIndexes: file_rangerbench_proto_depIdxs, + MessageInfos: file_rangerbench_proto_msgTypes, + }.Build() + File_rangerbench_proto = out.File + file_rangerbench_proto_rawDesc = nil + file_rangerbench_proto_goTypes = nil + file_rangerbench_proto_depIdxs = nil +} diff --git a/benchmark/rangerbench/rangerbench.proto b/benchmark/rangerbench/rangerbench.proto new file mode 100644 index 0000000..35d7fc4 --- /dev/null +++ b/benchmark/rangerbench/rangerbench.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package mondoo.ranger.rangerbench; +option go_package = "go.mondoo.com/ranger-rpc/benchmark/rangerbench"; + +service BenchmarkService { + rpc RpcSmall(SmallQuery) returns (SmallResponse) {} + rpc RpcEmpty(Empty) returns (DefaultResponse) {} +} + +message SmallQuery { + int64 id = 1; + string message = 2; + repeated string name = 3; +} + +message SmallResponse { + int64 id = 1; + string message = 2; + repeated string name = 3; +} + +message Empty {} + +message DefaultResponse { + string message = 1; +} \ No newline at end of file diff --git a/benchmark/rangerbench/rangerbench.ranger.go b/benchmark/rangerbench/rangerbench.ranger.go new file mode 100644 index 0000000..bf4c0b0 --- /dev/null +++ b/benchmark/rangerbench/rangerbench.ranger.go @@ -0,0 +1,142 @@ +// Code generated by protoc-gen-rangerrpc version DO NOT EDIT. +// source: rangerbench.proto + +package rangerbench + +import ( + "context" + "errors" + "net/http" + "net/url" + "strings" + + ranger "go.mondoo.com/ranger-rpc" + "go.mondoo.com/ranger-rpc/metadata" + jsonpb "google.golang.org/protobuf/encoding/protojson" + pb "google.golang.org/protobuf/proto" +) + +// service interface definition + +type BenchmarkService interface { + RpcSmall(context.Context, *SmallQuery) (*SmallResponse, error) + RpcEmpty(context.Context, *Empty) (*DefaultResponse, error) +} + +// client implementation + +type BenchmarkServiceClient struct { + ranger.Client + httpclient ranger.HTTPClient + prefix string +} + +func NewBenchmarkServiceClient(addr string, client ranger.HTTPClient) (*BenchmarkServiceClient, error) { + base, err := url.Parse(ranger.SanitizeUrl(addr)) + if err != nil { + return nil, err + } + + u, err := url.Parse("./BenchmarkService") + if err != nil { + return nil, err + } + + return &BenchmarkServiceClient{ + httpclient: client, + prefix: base.ResolveReference(u).String(), + }, nil +} +func (c *BenchmarkServiceClient) RpcSmall(ctx context.Context, in *SmallQuery) (*SmallResponse, error) { + out := new(SmallResponse) + err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/RpcSmall"}, ""), in, out) + return out, err +} +func (c *BenchmarkServiceClient) RpcEmpty(ctx context.Context, in *Empty) (*DefaultResponse, error) { + out := new(DefaultResponse) + err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/RpcEmpty"}, ""), in, out) + return out, err +} + +// server implementation + +type BenchmarkServiceServerOption func(s *BenchmarkServiceServer) + +func WithUnknownFieldsForBenchmarkServiceServer() BenchmarkServiceServerOption { + return func(s *BenchmarkServiceServer) { + s.allowUnknownFields = true + } +} + +func NewBenchmarkServiceServer(handler BenchmarkService, opts ...BenchmarkServiceServerOption) http.Handler { + srv := &BenchmarkServiceServer{ + handler: handler, + } + + for i := range opts { + opts[i](srv) + } + + service := ranger.Service{ + Name: "BenchmarkService", + Methods: map[string]ranger.Method{ + "RpcSmall": srv.RpcSmall, + "RpcEmpty": srv.RpcEmpty, + }, + } + return ranger.NewRPCServer(&service) +} + +type BenchmarkServiceServer struct { + handler BenchmarkService + allowUnknownFields bool +} + +func (p *BenchmarkServiceServer) RpcSmall(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { + var req SmallQuery + var err error + + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + return nil, errors.New("could not access header") + } + + switch md.First("Content-Type") { + case "application/protobuf", "application/octet-stream", "application/grpc+proto": + err = pb.Unmarshal(*reqBytes, &req) + default: + // handle case of empty object + if len(*reqBytes) > 0 { + err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) + } + } + + if err != nil { + return nil, err + } + return p.handler.RpcSmall(ctx, &req) +} +func (p *BenchmarkServiceServer) RpcEmpty(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { + var req Empty + var err error + + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + return nil, errors.New("could not access header") + } + + switch md.First("Content-Type") { + case "application/protobuf", "application/octet-stream", "application/grpc+proto": + err = pb.Unmarshal(*reqBytes, &req) + default: + // handle case of empty object + if len(*reqBytes) > 0 { + err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) + } + } + + if err != nil { + return nil, err + } + return p.handler.RpcEmpty(ctx, &req) +} diff --git a/benchmark/request_time_test.go b/benchmark/request_time_test.go new file mode 100644 index 0000000..c84cc94 --- /dev/null +++ b/benchmark/request_time_test.go @@ -0,0 +1,85 @@ +package benchmark + +import ( + "fmt" + "net/http" + "os" + "os/signal" + "testing" + + "github.com/rakyll/hey/requester" + "go.mondoo.com/ranger-rpc/benchmark/rangerbench" + "go.mondoo.com/ranger-rpc/benchmark/sample" + twirpbench "go.mondoo.com/ranger-rpc/benchmark/twirpbench" + "google.golang.org/protobuf/proto" +) + +var payload []byte + +func init() { + var err error + sr := &rangerbench.SmallQuery{Id: sample.Id, Name: sample.Name, Message: sample.Message} + payload, err = proto.Marshal(sr) + if err != nil { + panic(err) + } +} + +func doHeyReq(req *http.Request, body []byte) { + w := &requester.Work{ + Request: req, + RequestBody: body, + N: 200, + C: 50, + QPS: 0, + Timeout: 20, + DisableCompression: false, + DisableKeepAlives: false, + DisableRedirects: false, + H2: false, + ProxyAddr: nil, + Output: "", + } + w.Init() + + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt) + go func() { + <-c + w.Stop() + }() + w.Run() +} + +func TestLoad(t *testing.T) { + + benchmarks := []struct { + name string + port int + clienturl string + contentType string + payload []byte + }{ + {"twrip http protobuf", twirpbench.Serve(0, false), "http://localhost:%d/twirp/twirp.BenchmarkService/RpcEmpty", "application/protobuf", []byte{}}, + {"twirp http json", twirpbench.Serve(0, false), "http://localhost:%d/twirp/twirp.BenchmarkService/RpcEmpty", "application/json", []byte("{}")}, + {"ranger http protobuf", rangerbench.Serve(0, false), "http://localhost:%d/BenchmarkService/RpcEmpty", "application/protobuf", []byte{}}, + } + + for _, bm := range benchmarks { + t.Run(bm.name+" roundtrip", func(t *testing.T) { + serverAddr := fmt.Sprintf(bm.clienturl, bm.port) + + body := bm.payload + req, err := http.NewRequest("POST", serverAddr, nil) + if err != nil { + t.Fatalf("could not create http method") + } + + header := make(http.Header) + header.Set("Content-Type", bm.contentType) + req.Header = header + req.ContentLength = int64(len(body)) + doHeyReq(req, body) + }) + } +} diff --git a/benchmark/sample/cert.go b/benchmark/sample/cert.go new file mode 100644 index 0000000..cfc89a9 --- /dev/null +++ b/benchmark/sample/cert.go @@ -0,0 +1,51 @@ +package sample + +// openssl genrsa -out server.key 2048 +// openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650 +// TODO: regenerate!!! + +var LocalhostCert = []byte(`-----BEGIN CERTIFICATE----- +MIICvjCCAaYCCQClVNOARrZ/XDANBgkqhkiG9w0BAQsFADAhMQswCQYDVQQGEwJV +UzESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTE4MDcyMzE5MDAwNFoXDTI4MDcyMDE5 +MDAwNFowITELMAkGA1UEBhMCVVMxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJ +KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbSFS6JhnbEpM0xh/JfqZ8SxQ5yDkKE +JBSgUi/x3+iwW093loKZhYzBHR90Oy9whOwavbpFacRI/Qy1j25vYDqJ9nVCze7n +GoZtH/ucRXR2ugdhtfhWZawZ1KA9+SDtQC5hfIvqczID/d6lruY8h6bjBvZJB71W +aS5EKJITNRQJPFhAu7TwnuP/uvpaTcs/3BvGcB1XHHSZolnHgp5ONepzhfScex12 +mgfO26vecplHE35OduAqrb88gtdcPQBDt11sQiAJ234AfQwMvniVUD4vtx3XPIKg +CjazUMtrbhjpY4FyONSRfCMvEqGXXZ1+2UfztsG8VQUZt161g0oIZJECAwEAATAN +BgkqhkiG9w0BAQsFAAOCAQEAv9OYlWmMzQNvG2htkrxgeymRHVLZX0V7Krsfttqc +Uik5Zvd+VtO9vlxMGb7Qno5xH6ZHbAhODKagFCSqZVsyZIjWv12KG8aKeMGY8ltC +zJKAkRXbSfYk8wU28nAXjliZ80ItuzfwgXZs77WTGdrSJ+w9v+umxYERP+X1X6ad +JKZbkbNTFR+ScNbZ//bTUegHtZN1h3qqQrjQ7JzZqfIvHaNDvGeILYJeg3GsrcpR +sENqM4ofD4TXVt6LhW9FKjQyd7IEkFP61yVPGt8akJ22LUBYYcE43ReGSfO4IR2x +BKfIZsBVfazmsugT8EemEsBl7srtkMq5vdHMnBJCPgkKmg== +-----END CERTIFICATE-----`) + +var LocalhostKey = []byte(`-----BEGIN RSA PRIVATE KEY----- +MIIEogIBAAKCAQEAxtIVLomGdsSkzTGH8l+pnxLFDnIOQoQkFKBSL/Hf6LBbT3eW +gpmFjMEdH3Q7L3CE7Bq9ukVpxEj9DLWPbm9gOon2dULN7ucahm0f+5xFdHa6B2G1 ++FZlrBnUoD35IO1ALmF8i+pzMgP93qWu5jyHpuMG9kkHvVZpLkQokhM1FAk8WEC7 +tPCe4/+6+lpNyz/cG8ZwHVccdJmiWceCnk416nOF9Jx7HXaaB87bq95ymUcTfk52 +4CqtvzyC11w9AEO3XWxCIAnbfgB9DAy+eJVQPi+3Hdc8gqAKNrNQy2tuGOljgXI4 +1JF8Iy8SoZddnX7ZR/O2wbxVBRm3XrWDSghkkQIDAQABAoIBAG6goqycVTdsv451 +SwGv/P/IP+GD0S9tu23GrzSCT2Z4CrazAgp1RfxFz+CamfwRjcSaNIua5/kR68vQ +kpiOXGr2LS6eF1whN38o5SzpjTP6hBRraAdge35BeTAYi7Cokpe8IsLvl11zHyVt +512wvII9vLf5dtcBZ9EYl8J/8X7NkbC/+x87cpPRkhkABYMMCKWfdL3SsvJ/3qLk +8WMy3Lgj02lG1EluQFg/h7hGrOBWiw8CzfQC1sjEVGixA4U18OTRJVw5ZIp1aMxj +KLBACCoIMYuRwiyPnqc/WY+9kENM6LaaJacZ0ZXYjX7sj0xm6SaW2zBF7E/Dyerz +8up43CkCgYEA5NPyLnRBBHOugq7KadJIq0KQ+6SePcMm8EaLS1MyvlMiQXAAyN5F +K8eg5VpCUQ5378xFZnUe/y4D+YC25LbZ1QdLG5hTDhKcW35+poSa33CWllUMGbZd +QpFlu1OMN0J40VFMVRKG8y0HpbPSxempQ9MDs3uw6Ach/EZ/317fICMCgYEA3m30 +6xOgRbzZ0f4EBAT5L8w/rIMdtAQHQ5I7+a7K/NszBxGzAawH9OjOeR8Ih4oG5f2d +wpJwCaL1ztFOukmn9NKKuDfx4R6MRys3QnxcxvgVBjF/izb0tM+0jRB75+j6ne3p +vQ28sJYLxTgOQutZUJBNaV4260Y4IwC/s4O9mbsCgYA0FX3pTvLBlach/bD61y9N +M/CWJokSG8pQJG5uLbi+E2QXquuyzMzHwz9/FMVFd9qazU76nCv6/zlOYBrBAlGg +qHFTDZ/R8zB9rtQbCNHLi+/qtd70N0sQ7NFQCxs+NLYVRsDuGDJ5RUWZVM3j2GR7 +mJseDkhc98qnhlBywkBdKwKBgBq6NbrlodWfasEb99mPy22d6mzNWI1gCotpEAHh +qgyWPlx0GQFzbYVVUDIns3ut70RFpGZT+FiAF29hoUcrQJ5fikG2nz8Az7RhkgNQ +NEnIV6Zl3kCZOvBbIQPuXiUwzqSZiQOpmenSLdnl8XjDFPlkTZkCtDCzQF2cYmys +wOSvAoGAe96Lu278OUia0orkoX/Zg8PxQxt2NlpjiGdEvUdNVamWm3yGa6meezFT +fd5FFKSciIHDiqKQ1IakGypW8XeRLScxISaFYeCoAxLBKTsCGhsxCaBZRPKrzk1D +NZNW6nmd1ItvUwupVPiaABfgbh0YJ2MJYZSqWBkVye+1JzezfHk= +-----END RSA PRIVATE KEY-----`) diff --git a/benchmark/sample/sample.go b/benchmark/sample/sample.go new file mode 100644 index 0000000..5328d61 --- /dev/null +++ b/benchmark/sample/sample.go @@ -0,0 +1,22 @@ +package sample + +import ( + "encoding/base64" + "math/rand" + "time" +) + +var Id int64 +var Message string +var Name []string + +func init() { + rand.Seed(time.Now().UTC().UnixNano()) + Id = rand.Int63() * 5 + + token := make([]byte, 2000000) + rand.Read(token) + + Message = base64.StdEncoding.EncodeToString(token) + Name = []string{"abc", "dev", "blub"} +} diff --git a/benchmark/twirpbench/twirpbench.go b/benchmark/twirpbench/twirpbench.go new file mode 100644 index 0000000..d0b8b46 --- /dev/null +++ b/benchmark/twirpbench/twirpbench.go @@ -0,0 +1,56 @@ +package twirpbench + +import ( + context "context" + "crypto/tls" + "fmt" + "net" + "net/http" + + "go.mondoo.com/ranger-rpc/benchmark/sample" +) + +//go:generate protoc --go_out=. --go_opt=paths=source_relative --twirp_out=paths=source_relative:. twirpbench.proto + +type BenchmarkServer struct{} + +func (b *BenchmarkServer) RpcSmall(ctx context.Context, in *SmallQuery) (*SmallResponse, error) { + return &SmallResponse{Id: in.Id, Message: in.Message, Name: in.Name}, nil +} +func (b *BenchmarkServer) RpcEmpty(ctx context.Context, in *Empty) (*DefaultResponse, error) { + return &DefaultResponse{Message: sample.Message}, nil +} + +func Serve(port int, ssl bool) int { + // init implementation + s := NewBenchmarkServiceServer(&BenchmarkServer{}, nil) + + var lis net.Listener + var err error + if ssl == false { + lis, err = net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) + if err != nil { + panic(err) + } + } else { + cert, err := tls.X509KeyPair(sample.LocalhostCert, sample.LocalhostKey) + if err != nil { + panic(fmt.Sprintf("httptest: NewTLSServer: %v", err)) + } + config := &tls.Config{Certificates: []tls.Certificate{cert}} + + lis, err = tls.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port), config) + if err != nil { + panic(err) + } + } + + go func() { + err = http.Serve(lis, s) + if err != nil { + panic(err) + } + }() + + return lis.Addr().(*net.TCPAddr).Port +} diff --git a/benchmark/twirpbench/twirpbench.pb.go b/benchmark/twirpbench/twirpbench.pb.go new file mode 100644 index 0000000..7bc5a86 --- /dev/null +++ b/benchmark/twirpbench/twirpbench.pb.go @@ -0,0 +1,376 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.19.1 +// source: twirpbench.proto + +package twirpbench + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type SmallQuery struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Name []string `protobuf:"bytes,3,rep,name=name,proto3" json:"name,omitempty"` +} + +func (x *SmallQuery) Reset() { + *x = SmallQuery{} + if protoimpl.UnsafeEnabled { + mi := &file_twirpbench_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SmallQuery) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SmallQuery) ProtoMessage() {} + +func (x *SmallQuery) ProtoReflect() protoreflect.Message { + mi := &file_twirpbench_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SmallQuery.ProtoReflect.Descriptor instead. +func (*SmallQuery) Descriptor() ([]byte, []int) { + return file_twirpbench_proto_rawDescGZIP(), []int{0} +} + +func (x *SmallQuery) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SmallQuery) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *SmallQuery) GetName() []string { + if x != nil { + return x.Name + } + return nil +} + +type SmallResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Name []string `protobuf:"bytes,3,rep,name=name,proto3" json:"name,omitempty"` +} + +func (x *SmallResponse) Reset() { + *x = SmallResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_twirpbench_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SmallResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SmallResponse) ProtoMessage() {} + +func (x *SmallResponse) ProtoReflect() protoreflect.Message { + mi := &file_twirpbench_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SmallResponse.ProtoReflect.Descriptor instead. +func (*SmallResponse) Descriptor() ([]byte, []int) { + return file_twirpbench_proto_rawDescGZIP(), []int{1} +} + +func (x *SmallResponse) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *SmallResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *SmallResponse) GetName() []string { + if x != nil { + return x.Name + } + return nil +} + +type Empty struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Empty) Reset() { + *x = Empty{} + if protoimpl.UnsafeEnabled { + mi := &file_twirpbench_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_twirpbench_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_twirpbench_proto_rawDescGZIP(), []int{2} +} + +type DefaultResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *DefaultResponse) Reset() { + *x = DefaultResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_twirpbench_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DefaultResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DefaultResponse) ProtoMessage() {} + +func (x *DefaultResponse) ProtoReflect() protoreflect.Message { + mi := &file_twirpbench_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DefaultResponse.ProtoReflect.Descriptor instead. +func (*DefaultResponse) Descriptor() ([]byte, []int) { + return file_twirpbench_proto_rawDescGZIP(), []int{3} +} + +func (x *DefaultResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_twirpbench_proto protoreflect.FileDescriptor + +var file_twirpbench_proto_rawDesc = []byte{ + 0x0a, 0x10, 0x74, 0x77, 0x69, 0x72, 0x70, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x18, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, + 0x72, 0x2e, 0x74, 0x77, 0x69, 0x72, 0x70, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x22, 0x4a, 0x0a, 0x0a, + 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x4d, 0x0a, 0x0d, 0x53, 0x6d, 0x61, 0x6c, + 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x22, 0x2b, 0x0a, 0x0f, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xc9, 0x01, + 0x0a, 0x10, 0x42, 0x65, 0x6e, 0x63, 0x68, 0x6d, 0x61, 0x72, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x12, 0x5b, 0x0a, 0x08, 0x52, 0x70, 0x63, 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x12, 0x24, + 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x74, + 0x77, 0x69, 0x72, 0x70, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x51, + 0x75, 0x65, 0x72, 0x79, 0x1a, 0x27, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, + 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x74, 0x77, 0x69, 0x72, 0x70, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, + 0x53, 0x6d, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x58, 0x0a, 0x08, 0x52, 0x70, 0x63, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x1f, 0x2e, 0x6d, 0x6f, + 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x74, 0x77, 0x69, 0x72, + 0x70, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x29, 0x2e, 0x6d, + 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x2e, 0x74, 0x77, 0x69, + 0x72, 0x70, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x2e, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x6f, 0x2e, + 0x6d, 0x6f, 0x6e, 0x64, 0x6f, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x61, 0x6e, 0x67, 0x65, + 0x72, 0x2d, 0x72, 0x70, 0x63, 0x2f, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x6d, 0x61, 0x72, 0x6b, 0x2f, + 0x74, 0x77, 0x69, 0x72, 0x70, 0x62, 0x65, 0x6e, 0x63, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +} + +var ( + file_twirpbench_proto_rawDescOnce sync.Once + file_twirpbench_proto_rawDescData = file_twirpbench_proto_rawDesc +) + +func file_twirpbench_proto_rawDescGZIP() []byte { + file_twirpbench_proto_rawDescOnce.Do(func() { + file_twirpbench_proto_rawDescData = protoimpl.X.CompressGZIP(file_twirpbench_proto_rawDescData) + }) + return file_twirpbench_proto_rawDescData +} + +var file_twirpbench_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_twirpbench_proto_goTypes = []interface{}{ + (*SmallQuery)(nil), // 0: mondoo.ranger.twirpbench.SmallQuery + (*SmallResponse)(nil), // 1: mondoo.ranger.twirpbench.SmallResponse + (*Empty)(nil), // 2: mondoo.ranger.twirpbench.Empty + (*DefaultResponse)(nil), // 3: mondoo.ranger.twirpbench.DefaultResponse +} +var file_twirpbench_proto_depIdxs = []int32{ + 0, // 0: mondoo.ranger.twirpbench.BenchmarkService.RpcSmall:input_type -> mondoo.ranger.twirpbench.SmallQuery + 2, // 1: mondoo.ranger.twirpbench.BenchmarkService.RpcEmpty:input_type -> mondoo.ranger.twirpbench.Empty + 1, // 2: mondoo.ranger.twirpbench.BenchmarkService.RpcSmall:output_type -> mondoo.ranger.twirpbench.SmallResponse + 3, // 3: mondoo.ranger.twirpbench.BenchmarkService.RpcEmpty:output_type -> mondoo.ranger.twirpbench.DefaultResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_twirpbench_proto_init() } +func file_twirpbench_proto_init() { + if File_twirpbench_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_twirpbench_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SmallQuery); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_twirpbench_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SmallResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_twirpbench_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Empty); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_twirpbench_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DefaultResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_twirpbench_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_twirpbench_proto_goTypes, + DependencyIndexes: file_twirpbench_proto_depIdxs, + MessageInfos: file_twirpbench_proto_msgTypes, + }.Build() + File_twirpbench_proto = out.File + file_twirpbench_proto_rawDesc = nil + file_twirpbench_proto_goTypes = nil + file_twirpbench_proto_depIdxs = nil +} diff --git a/benchmark/twirpbench/twirpbench.proto b/benchmark/twirpbench/twirpbench.proto new file mode 100644 index 0000000..6cdbb04 --- /dev/null +++ b/benchmark/twirpbench/twirpbench.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package mondoo.ranger.twirpbench; +option go_package = "go.mondoo.com/ranger-rpc/benchmark/twirpbench"; + +service BenchmarkService { + rpc RpcSmall(SmallQuery) returns (SmallResponse) {} + rpc RpcEmpty(Empty) returns (DefaultResponse) {} +} + +message SmallQuery { + int64 id = 1; + string message = 2; + repeated string name = 3; +} + +message SmallResponse { + int64 id = 1; + string message = 2; + repeated string name = 3; +} + +message Empty {} + +message DefaultResponse { + string message = 1; +} \ No newline at end of file diff --git a/benchmark/twirpbench/twirpbench.twirp.go b/benchmark/twirpbench/twirpbench.twirp.go new file mode 100644 index 0000000..312fba9 --- /dev/null +++ b/benchmark/twirpbench/twirpbench.twirp.go @@ -0,0 +1,1385 @@ +// Code generated by protoc-gen-twirp v8.1.2, DO NOT EDIT. +// source: twirpbench.proto + +package twirpbench + +import context "context" +import fmt "fmt" +import http "net/http" +import ioutil "io/ioutil" +import json "encoding/json" +import strconv "strconv" +import strings "strings" + +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" +import twirp "github.com/twitchtv/twirp" +import ctxsetters "github.com/twitchtv/twirp/ctxsetters" + +import bytes "bytes" +import errors "errors" +import io "io" +import path "path" +import url "net/url" + +// Version compatibility assertion. +// If the constant is not defined in the package, that likely means +// the package needs to be updated to work with this generated code. +// See https://twitchtv.github.io/twirp/docs/version_matrix.html +const _ = twirp.TwirpPackageMinVersion_8_1_0 + +// ========================== +// BenchmarkService Interface +// ========================== + +type BenchmarkService interface { + RpcSmall(context.Context, *SmallQuery) (*SmallResponse, error) + + RpcEmpty(context.Context, *Empty) (*DefaultResponse, error) +} + +// ================================ +// BenchmarkService Protobuf Client +// ================================ + +type benchmarkServiceProtobufClient struct { + client HTTPClient + urls [2]string + interceptor twirp.Interceptor + opts twirp.ClientOptions +} + +// NewBenchmarkServiceProtobufClient creates a Protobuf client that implements the BenchmarkService interface. +// It communicates using Protobuf and can be configured with a custom HTTPClient. +func NewBenchmarkServiceProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) BenchmarkService { + if c, ok := client.(*http.Client); ok { + client = withoutRedirects(c) + } + + clientOpts := twirp.ClientOptions{} + for _, o := range opts { + o(&clientOpts) + } + + // Using ReadOpt allows backwards and forwads compatibility with new options in the future + literalURLs := false + _ = clientOpts.ReadOpt("literalURLs", &literalURLs) + var pathPrefix string + if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + // Build method URLs: []/./ + serviceURL := sanitizeBaseURL(baseURL) + serviceURL += baseServicePath(pathPrefix, "mondoo.ranger.twirpbench", "BenchmarkService") + urls := [2]string{ + serviceURL + "RpcSmall", + serviceURL + "RpcEmpty", + } + + return &benchmarkServiceProtobufClient{ + client: client, + urls: urls, + interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...), + opts: clientOpts, + } +} + +func (c *benchmarkServiceProtobufClient) RpcSmall(ctx context.Context, in *SmallQuery) (*SmallResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "mondoo.ranger.twirpbench") + ctx = ctxsetters.WithServiceName(ctx, "BenchmarkService") + ctx = ctxsetters.WithMethodName(ctx, "RpcSmall") + caller := c.callRpcSmall + if c.interceptor != nil { + caller = func(ctx context.Context, req *SmallQuery) (*SmallResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*SmallQuery) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*SmallQuery) when calling interceptor") + } + return c.callRpcSmall(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*SmallResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*SmallResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *benchmarkServiceProtobufClient) callRpcSmall(ctx context.Context, in *SmallQuery) (*SmallResponse, error) { + out := new(SmallResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *benchmarkServiceProtobufClient) RpcEmpty(ctx context.Context, in *Empty) (*DefaultResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "mondoo.ranger.twirpbench") + ctx = ctxsetters.WithServiceName(ctx, "BenchmarkService") + ctx = ctxsetters.WithMethodName(ctx, "RpcEmpty") + caller := c.callRpcEmpty + if c.interceptor != nil { + caller = func(ctx context.Context, req *Empty) (*DefaultResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*Empty) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*Empty) when calling interceptor") + } + return c.callRpcEmpty(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*DefaultResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*DefaultResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *benchmarkServiceProtobufClient) callRpcEmpty(ctx context.Context, in *Empty) (*DefaultResponse, error) { + out := new(DefaultResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +// ============================ +// BenchmarkService JSON Client +// ============================ + +type benchmarkServiceJSONClient struct { + client HTTPClient + urls [2]string + interceptor twirp.Interceptor + opts twirp.ClientOptions +} + +// NewBenchmarkServiceJSONClient creates a JSON client that implements the BenchmarkService interface. +// It communicates using JSON and can be configured with a custom HTTPClient. +func NewBenchmarkServiceJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) BenchmarkService { + if c, ok := client.(*http.Client); ok { + client = withoutRedirects(c) + } + + clientOpts := twirp.ClientOptions{} + for _, o := range opts { + o(&clientOpts) + } + + // Using ReadOpt allows backwards and forwads compatibility with new options in the future + literalURLs := false + _ = clientOpts.ReadOpt("literalURLs", &literalURLs) + var pathPrefix string + if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + // Build method URLs: []/./ + serviceURL := sanitizeBaseURL(baseURL) + serviceURL += baseServicePath(pathPrefix, "mondoo.ranger.twirpbench", "BenchmarkService") + urls := [2]string{ + serviceURL + "RpcSmall", + serviceURL + "RpcEmpty", + } + + return &benchmarkServiceJSONClient{ + client: client, + urls: urls, + interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...), + opts: clientOpts, + } +} + +func (c *benchmarkServiceJSONClient) RpcSmall(ctx context.Context, in *SmallQuery) (*SmallResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "mondoo.ranger.twirpbench") + ctx = ctxsetters.WithServiceName(ctx, "BenchmarkService") + ctx = ctxsetters.WithMethodName(ctx, "RpcSmall") + caller := c.callRpcSmall + if c.interceptor != nil { + caller = func(ctx context.Context, req *SmallQuery) (*SmallResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*SmallQuery) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*SmallQuery) when calling interceptor") + } + return c.callRpcSmall(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*SmallResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*SmallResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *benchmarkServiceJSONClient) callRpcSmall(ctx context.Context, in *SmallQuery) (*SmallResponse, error) { + out := new(SmallResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *benchmarkServiceJSONClient) RpcEmpty(ctx context.Context, in *Empty) (*DefaultResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "mondoo.ranger.twirpbench") + ctx = ctxsetters.WithServiceName(ctx, "BenchmarkService") + ctx = ctxsetters.WithMethodName(ctx, "RpcEmpty") + caller := c.callRpcEmpty + if c.interceptor != nil { + caller = func(ctx context.Context, req *Empty) (*DefaultResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*Empty) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*Empty) when calling interceptor") + } + return c.callRpcEmpty(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*DefaultResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*DefaultResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *benchmarkServiceJSONClient) callRpcEmpty(ctx context.Context, in *Empty) (*DefaultResponse, error) { + out := new(DefaultResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +// =============================== +// BenchmarkService Server Handler +// =============================== + +type benchmarkServiceServer struct { + BenchmarkService + interceptor twirp.Interceptor + hooks *twirp.ServerHooks + pathPrefix string // prefix for routing + jsonSkipDefaults bool // do not include unpopulated fields (default values) in the response + jsonCamelCase bool // JSON fields are serialized as lowerCamelCase rather than keeping the original proto names +} + +// NewBenchmarkServiceServer builds a TwirpServer that can be used as an http.Handler to handle +// HTTP requests that are routed to the right method in the provided svc implementation. +// The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks). +func NewBenchmarkServiceServer(svc BenchmarkService, opts ...interface{}) TwirpServer { + serverOpts := newServerOpts(opts) + + // Using ReadOpt allows backwards and forwads compatibility with new options in the future + jsonSkipDefaults := false + _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) + jsonCamelCase := false + _ = serverOpts.ReadOpt("jsonCamelCase", &jsonCamelCase) + var pathPrefix string + if ok := serverOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + return &benchmarkServiceServer{ + BenchmarkService: svc, + hooks: serverOpts.Hooks, + interceptor: twirp.ChainInterceptors(serverOpts.Interceptors...), + pathPrefix: pathPrefix, + jsonSkipDefaults: jsonSkipDefaults, + jsonCamelCase: jsonCamelCase, + } +} + +// writeError writes an HTTP response with a valid Twirp error format, and triggers hooks. +// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err) +func (s *benchmarkServiceServer) writeError(ctx context.Context, resp http.ResponseWriter, err error) { + writeError(ctx, resp, err, s.hooks) +} + +// handleRequestBodyError is used to handle error when the twirp server cannot read request +func (s *benchmarkServiceServer) handleRequestBodyError(ctx context.Context, resp http.ResponseWriter, msg string, err error) { + if context.Canceled == ctx.Err() { + s.writeError(ctx, resp, twirp.NewError(twirp.Canceled, "failed to read request: context canceled")) + return + } + if context.DeadlineExceeded == ctx.Err() { + s.writeError(ctx, resp, twirp.NewError(twirp.DeadlineExceeded, "failed to read request: deadline exceeded")) + return + } + s.writeError(ctx, resp, twirp.WrapError(malformedRequestError(msg), err)) +} + +// BenchmarkServicePathPrefix is a convenience constant that may identify URL paths. +// Should be used with caution, it only matches routes generated by Twirp Go clients, +// with the default "/twirp" prefix and default CamelCase service and method names. +// More info: https://twitchtv.github.io/twirp/docs/routing.html +const BenchmarkServicePathPrefix = "/twirp/mondoo.ranger.twirpbench.BenchmarkService/" + +func (s *benchmarkServiceServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) { + ctx := req.Context() + ctx = ctxsetters.WithPackageName(ctx, "mondoo.ranger.twirpbench") + ctx = ctxsetters.WithServiceName(ctx, "BenchmarkService") + ctx = ctxsetters.WithResponseWriter(ctx, resp) + + var err error + ctx, err = callRequestReceived(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + if req.Method != "POST" { + msg := fmt.Sprintf("unsupported method %q (only POST is allowed)", req.Method) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + + // Verify path format: []/./ + prefix, pkgService, method := parseTwirpPath(req.URL.Path) + if pkgService != "mondoo.ranger.twirpbench.BenchmarkService" { + msg := fmt.Sprintf("no handler for path %q", req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + if prefix != s.pathPrefix { + msg := fmt.Sprintf("invalid path prefix %q, expected %q, on path %q", prefix, s.pathPrefix, req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + + switch method { + case "RpcSmall": + s.serveRpcSmall(ctx, resp, req) + return + case "RpcEmpty": + s.serveRpcEmpty(ctx, resp, req) + return + default: + msg := fmt.Sprintf("no handler for path %q", req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } +} + +func (s *benchmarkServiceServer) serveRpcSmall(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveRpcSmallJSON(ctx, resp, req) + case "application/protobuf": + s.serveRpcSmallProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *benchmarkServiceServer) serveRpcSmallJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "RpcSmall") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(SmallQuery) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.BenchmarkService.RpcSmall + if s.interceptor != nil { + handler = func(ctx context.Context, req *SmallQuery) (*SmallResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*SmallQuery) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*SmallQuery) when calling interceptor") + } + return s.BenchmarkService.RpcSmall(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*SmallResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*SmallResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *SmallResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *SmallResponse and nil error while calling RpcSmall. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *benchmarkServiceServer) serveRpcSmallProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "RpcSmall") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := ioutil.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(SmallQuery) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.BenchmarkService.RpcSmall + if s.interceptor != nil { + handler = func(ctx context.Context, req *SmallQuery) (*SmallResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*SmallQuery) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*SmallQuery) when calling interceptor") + } + return s.BenchmarkService.RpcSmall(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*SmallResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*SmallResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *SmallResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *SmallResponse and nil error while calling RpcSmall. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *benchmarkServiceServer) serveRpcEmpty(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveRpcEmptyJSON(ctx, resp, req) + case "application/protobuf": + s.serveRpcEmptyProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *benchmarkServiceServer) serveRpcEmptyJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "RpcEmpty") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(Empty) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.BenchmarkService.RpcEmpty + if s.interceptor != nil { + handler = func(ctx context.Context, req *Empty) (*DefaultResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*Empty) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*Empty) when calling interceptor") + } + return s.BenchmarkService.RpcEmpty(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*DefaultResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*DefaultResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *DefaultResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *DefaultResponse and nil error while calling RpcEmpty. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *benchmarkServiceServer) serveRpcEmptyProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "RpcEmpty") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := ioutil.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(Empty) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.BenchmarkService.RpcEmpty + if s.interceptor != nil { + handler = func(ctx context.Context, req *Empty) (*DefaultResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*Empty) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*Empty) when calling interceptor") + } + return s.BenchmarkService.RpcEmpty(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*DefaultResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*DefaultResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *DefaultResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *DefaultResponse and nil error while calling RpcEmpty. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *benchmarkServiceServer) ServiceDescriptor() ([]byte, int) { + return twirpFileDescriptor0, 0 +} + +func (s *benchmarkServiceServer) ProtocGenTwirpVersion() string { + return "v8.1.2" +} + +// PathPrefix returns the base service path, in the form: "//./" +// that is everything in a Twirp route except for the . This can be used for routing, +// for example to identify the requests that are targeted to this service in a mux. +func (s *benchmarkServiceServer) PathPrefix() string { + return baseServicePath(s.pathPrefix, "mondoo.ranger.twirpbench", "BenchmarkService") +} + +// ===== +// Utils +// ===== + +// HTTPClient is the interface used by generated clients to send HTTP requests. +// It is fulfilled by *(net/http).Client, which is sufficient for most users. +// Users can provide their own implementation for special retry policies. +// +// HTTPClient implementations should not follow redirects. Redirects are +// automatically disabled if *(net/http).Client is passed to client +// constructors. See the withoutRedirects function in this file for more +// details. +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + +// TwirpServer is the interface generated server structs will support: they're +// HTTP handlers with additional methods for accessing metadata about the +// service. Those accessors are a low-level API for building reflection tools. +// Most people can think of TwirpServers as just http.Handlers. +type TwirpServer interface { + http.Handler + + // ServiceDescriptor returns gzipped bytes describing the .proto file that + // this service was generated from. Once unzipped, the bytes can be + // unmarshalled as a + // google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto. + // + // The returned integer is the index of this particular service within that + // FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a + // low-level field, expected to be used for reflection. + ServiceDescriptor() ([]byte, int) + + // ProtocGenTwirpVersion is the semantic version string of the version of + // twirp used to generate this file. + ProtocGenTwirpVersion() string + + // PathPrefix returns the HTTP URL path prefix for all methods handled by this + // service. This can be used with an HTTP mux to route Twirp requests. + // The path prefix is in the form: "//./" + // that is, everything in a Twirp route except for the at the end. + PathPrefix() string +} + +func newServerOpts(opts []interface{}) *twirp.ServerOptions { + serverOpts := &twirp.ServerOptions{} + for _, opt := range opts { + switch o := opt.(type) { + case twirp.ServerOption: + o(serverOpts) + case *twirp.ServerHooks: // backwards compatibility, allow to specify hooks as an argument + twirp.WithServerHooks(o)(serverOpts) + case nil: // backwards compatibility, allow nil value for the argument + continue + default: + panic(fmt.Sprintf("Invalid option type %T, please use a twirp.ServerOption", o)) + } + } + return serverOpts +} + +// WriteError writes an HTTP response with a valid Twirp error format (code, msg, meta). +// Useful outside of the Twirp server (e.g. http middleware), but does not trigger hooks. +// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err) +func WriteError(resp http.ResponseWriter, err error) { + writeError(context.Background(), resp, err, nil) +} + +// writeError writes Twirp errors in the response and triggers hooks. +func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks *twirp.ServerHooks) { + // Convert to a twirp.Error. Non-twirp errors are converted to internal errors. + var twerr twirp.Error + if !errors.As(err, &twerr) { + twerr = twirp.InternalErrorWith(err) + } + + statusCode := twirp.ServerHTTPStatusFromErrorCode(twerr.Code()) + ctx = ctxsetters.WithStatusCode(ctx, statusCode) + ctx = callError(ctx, hooks, twerr) + + respBody := marshalErrorToJSON(twerr) + + resp.Header().Set("Content-Type", "application/json") // Error responses are always JSON + resp.Header().Set("Content-Length", strconv.Itoa(len(respBody))) + resp.WriteHeader(statusCode) // set HTTP status code and send response + + _, writeErr := resp.Write(respBody) + if writeErr != nil { + // We have three options here. We could log the error, call the Error + // hook, or just silently ignore the error. + // + // Logging is unacceptable because we don't have a user-controlled + // logger; writing out to stderr without permission is too rude. + // + // Calling the Error hook would confuse users: it would mean the Error + // hook got called twice for one request, which is likely to lead to + // duplicated log messages and metrics, no matter how well we document + // the behavior. + // + // Silently ignoring the error is our least-bad option. It's highly + // likely that the connection is broken and the original 'err' says + // so anyway. + _ = writeErr + } + + callResponseSent(ctx, hooks) +} + +// sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. +// If the URL is unparsable, the baseURL is returned unchaged. +func sanitizeBaseURL(baseURL string) string { + u, err := url.Parse(baseURL) + if err != nil { + return baseURL // invalid URL will fail later when making requests + } + if u.Scheme == "" { + u.Scheme = "http" + } + return u.String() +} + +// baseServicePath composes the path prefix for the service (without ). +// e.g.: baseServicePath("/twirp", "my.pkg", "MyService") +// returns => "/twirp/my.pkg.MyService/" +// e.g.: baseServicePath("", "", "MyService") +// returns => "/MyService/" +func baseServicePath(prefix, pkg, service string) string { + fullServiceName := service + if pkg != "" { + fullServiceName = pkg + "." + service + } + return path.Join("/", prefix, fullServiceName) + "/" +} + +// parseTwirpPath extracts path components form a valid Twirp route. +// Expected format: "[]/./" +// e.g.: prefix, pkgService, method := parseTwirpPath("/twirp/pkg.Svc/MakeHat") +func parseTwirpPath(path string) (string, string, string) { + parts := strings.Split(path, "/") + if len(parts) < 2 { + return "", "", "" + } + method := parts[len(parts)-1] + pkgService := parts[len(parts)-2] + prefix := strings.Join(parts[0:len(parts)-2], "/") + return prefix, pkgService, method +} + +// getCustomHTTPReqHeaders retrieves a copy of any headers that are set in +// a context through the twirp.WithHTTPRequestHeaders function. +// If there are no headers set, or if they have the wrong type, nil is returned. +func getCustomHTTPReqHeaders(ctx context.Context) http.Header { + header, ok := twirp.HTTPRequestHeaders(ctx) + if !ok || header == nil { + return nil + } + copied := make(http.Header) + for k, vv := range header { + if vv == nil { + copied[k] = nil + continue + } + copied[k] = make([]string, len(vv)) + copy(copied[k], vv) + } + return copied +} + +// newRequest makes an http.Request from a client, adding common headers. +func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType string) (*http.Request, error) { + req, err := http.NewRequest("POST", url, reqBody) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if customHeader := getCustomHTTPReqHeaders(ctx); customHeader != nil { + req.Header = customHeader + } + req.Header.Set("Accept", contentType) + req.Header.Set("Content-Type", contentType) + req.Header.Set("Twirp-Version", "v8.1.2") + return req, nil +} + +// JSON serialization for errors +type twerrJSON struct { + Code string `json:"code"` + Msg string `json:"msg"` + Meta map[string]string `json:"meta,omitempty"` +} + +// marshalErrorToJSON returns JSON from a twirp.Error, that can be used as HTTP error response body. +// If serialization fails, it will use a descriptive Internal error instead. +func marshalErrorToJSON(twerr twirp.Error) []byte { + // make sure that msg is not too large + msg := twerr.Msg() + if len(msg) > 1e6 { + msg = msg[:1e6] + } + + tj := twerrJSON{ + Code: string(twerr.Code()), + Msg: msg, + Meta: twerr.MetaMap(), + } + + buf, err := json.Marshal(&tj) + if err != nil { + buf = []byte("{\"type\": \"" + twirp.Internal + "\", \"msg\": \"There was an error but it could not be serialized into JSON\"}") // fallback + } + + return buf +} + +// errorFromResponse builds a twirp.Error from a non-200 HTTP response. +// If the response has a valid serialized Twirp error, then it's returned. +// If not, the response status code is used to generate a similar twirp +// error. See twirpErrorFromIntermediary for more info on intermediary errors. +func errorFromResponse(resp *http.Response) twirp.Error { + statusCode := resp.StatusCode + statusText := http.StatusText(statusCode) + + if isHTTPRedirect(statusCode) { + // Unexpected redirect: it must be an error from an intermediary. + // Twirp clients don't follow redirects automatically, Twirp only handles + // POST requests, redirects should only happen on GET and HEAD requests. + location := resp.Header.Get("Location") + msg := fmt.Sprintf("unexpected HTTP status code %d %q received, Location=%q", statusCode, statusText, location) + return twirpErrorFromIntermediary(statusCode, msg, location) + } + + respBodyBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + return wrapInternal(err, "failed to read server error response body") + } + + var tj twerrJSON + dec := json.NewDecoder(bytes.NewReader(respBodyBytes)) + dec.DisallowUnknownFields() + if err := dec.Decode(&tj); err != nil || tj.Code == "" { + // Invalid JSON response; it must be an error from an intermediary. + msg := fmt.Sprintf("Error from intermediary with HTTP status code %d %q", statusCode, statusText) + return twirpErrorFromIntermediary(statusCode, msg, string(respBodyBytes)) + } + + errorCode := twirp.ErrorCode(tj.Code) + if !twirp.IsValidErrorCode(errorCode) { + msg := "invalid type returned from server error response: " + tj.Code + return twirp.InternalError(msg).WithMeta("body", string(respBodyBytes)) + } + + twerr := twirp.NewError(errorCode, tj.Msg) + for k, v := range tj.Meta { + twerr = twerr.WithMeta(k, v) + } + return twerr +} + +// twirpErrorFromIntermediary maps HTTP errors from non-twirp sources to twirp errors. +// The mapping is similar to gRPC: https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md. +// Returned twirp Errors have some additional metadata for inspection. +func twirpErrorFromIntermediary(status int, msg string, bodyOrLocation string) twirp.Error { + var code twirp.ErrorCode + if isHTTPRedirect(status) { // 3xx + code = twirp.Internal + } else { + switch status { + case 400: // Bad Request + code = twirp.Internal + case 401: // Unauthorized + code = twirp.Unauthenticated + case 403: // Forbidden + code = twirp.PermissionDenied + case 404: // Not Found + code = twirp.BadRoute + case 429: // Too Many Requests + code = twirp.ResourceExhausted + case 502, 503, 504: // Bad Gateway, Service Unavailable, Gateway Timeout + code = twirp.Unavailable + default: // All other codes + code = twirp.Unknown + } + } + + twerr := twirp.NewError(code, msg) + twerr = twerr.WithMeta("http_error_from_intermediary", "true") // to easily know if this error was from intermediary + twerr = twerr.WithMeta("status_code", strconv.Itoa(status)) + if isHTTPRedirect(status) { + twerr = twerr.WithMeta("location", bodyOrLocation) + } else { + twerr = twerr.WithMeta("body", bodyOrLocation) + } + return twerr +} + +func isHTTPRedirect(status int) bool { + return status >= 300 && status <= 399 +} + +// wrapInternal wraps an error with a prefix as an Internal error. +// The original error cause is accessible by github.com/pkg/errors.Cause. +func wrapInternal(err error, prefix string) twirp.Error { + return twirp.InternalErrorWith(&wrappedError{prefix: prefix, cause: err}) +} + +type wrappedError struct { + prefix string + cause error +} + +func (e *wrappedError) Error() string { return e.prefix + ": " + e.cause.Error() } +func (e *wrappedError) Unwrap() error { return e.cause } // for go1.13 + errors.Is/As +func (e *wrappedError) Cause() error { return e.cause } // for github.com/pkg/errors + +// ensurePanicResponses makes sure that rpc methods causing a panic still result in a Twirp Internal +// error response (status 500), and error hooks are properly called with the panic wrapped as an error. +// The panic is re-raised so it can be handled normally with middleware. +func ensurePanicResponses(ctx context.Context, resp http.ResponseWriter, hooks *twirp.ServerHooks) { + if r := recover(); r != nil { + // Wrap the panic as an error so it can be passed to error hooks. + // The original error is accessible from error hooks, but not visible in the response. + err := errFromPanic(r) + twerr := &internalWithCause{msg: "Internal service panic", cause: err} + // Actually write the error + writeError(ctx, resp, twerr, hooks) + // If possible, flush the error to the wire. + f, ok := resp.(http.Flusher) + if ok { + f.Flush() + } + + panic(r) + } +} + +// errFromPanic returns the typed error if the recovered panic is an error, otherwise formats as error. +func errFromPanic(p interface{}) error { + if err, ok := p.(error); ok { + return err + } + return fmt.Errorf("panic: %v", p) +} + +// internalWithCause is a Twirp Internal error wrapping an original error cause, +// but the original error message is not exposed on Msg(). The original error +// can be checked with go1.13+ errors.Is/As, and also by (github.com/pkg/errors).Unwrap +type internalWithCause struct { + msg string + cause error +} + +func (e *internalWithCause) Unwrap() error { return e.cause } // for go1.13 + errors.Is/As +func (e *internalWithCause) Cause() error { return e.cause } // for github.com/pkg/errors +func (e *internalWithCause) Error() string { return e.msg + ": " + e.cause.Error() } +func (e *internalWithCause) Code() twirp.ErrorCode { return twirp.Internal } +func (e *internalWithCause) Msg() string { return e.msg } +func (e *internalWithCause) Meta(key string) string { return "" } +func (e *internalWithCause) MetaMap() map[string]string { return nil } +func (e *internalWithCause) WithMeta(key string, val string) twirp.Error { return e } + +// malformedRequestError is used when the twirp server cannot unmarshal a request +func malformedRequestError(msg string) twirp.Error { + return twirp.NewError(twirp.Malformed, msg) +} + +// badRouteError is used when the twirp server cannot route a request +func badRouteError(msg string, method, url string) twirp.Error { + err := twirp.NewError(twirp.BadRoute, msg) + err = err.WithMeta("twirp_invalid_route", method+" "+url) + return err +} + +// withoutRedirects makes sure that the POST request can not be redirected. +// The standard library will, by default, redirect requests (including POSTs) if it gets a 302 or +// 303 response, and also 301s in go1.8. It redirects by making a second request, changing the +// method to GET and removing the body. This produces very confusing error messages, so instead we +// set a redirect policy that always errors. This stops Go from executing the redirect. +// +// We have to be a little careful in case the user-provided http.Client has its own CheckRedirect +// policy - if so, we'll run through that policy first. +// +// Because this requires modifying the http.Client, we make a new copy of the client and return it. +func withoutRedirects(in *http.Client) *http.Client { + copy := *in + copy.CheckRedirect = func(req *http.Request, via []*http.Request) error { + if in.CheckRedirect != nil { + // Run the input's redirect if it exists, in case it has side effects, but ignore any error it + // returns, since we want to use ErrUseLastResponse. + err := in.CheckRedirect(req, via) + _ = err // Silly, but this makes sure generated code passes errcheck -blank, which some people use. + } + return http.ErrUseLastResponse + } + return © +} + +// doProtobufRequest makes a Protobuf request to the remote Twirp service. +func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { + reqBodyBytes, err := proto.Marshal(in) + if err != nil { + return ctx, wrapInternal(err, "failed to marshal proto request") + } + reqBody := bytes.NewBuffer(reqBodyBytes) + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + req, err := newRequest(ctx, url, reqBody, "application/protobuf") + if err != nil { + return ctx, wrapInternal(err, "could not build request") + } + ctx, err = callClientRequestPrepared(ctx, hooks, req) + if err != nil { + return ctx, err + } + + req = req.WithContext(ctx) + resp, err := client.Do(req) + if err != nil { + return ctx, wrapInternal(err, "failed to do request") + } + defer func() { _ = resp.Body.Close() }() + + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if resp.StatusCode != 200 { + return ctx, errorFromResponse(resp) + } + + respBodyBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + return ctx, wrapInternal(err, "failed to read response body") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if err = proto.Unmarshal(respBodyBytes, out); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal proto response") + } + return ctx, nil +} + +// doJSONRequest makes a JSON request to the remote Twirp service. +func doJSONRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { + marshaler := &protojson.MarshalOptions{UseProtoNames: true} + reqBytes, err := marshaler.Marshal(in) + if err != nil { + return ctx, wrapInternal(err, "failed to marshal json request") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + req, err := newRequest(ctx, url, bytes.NewReader(reqBytes), "application/json") + if err != nil { + return ctx, wrapInternal(err, "could not build request") + } + ctx, err = callClientRequestPrepared(ctx, hooks, req) + if err != nil { + return ctx, err + } + + req = req.WithContext(ctx) + resp, err := client.Do(req) + if err != nil { + return ctx, wrapInternal(err, "failed to do request") + } + + defer func() { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = wrapInternal(cerr, "failed to close response body") + } + }() + + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if resp.StatusCode != 200 { + return ctx, errorFromResponse(resp) + } + + d := json.NewDecoder(resp.Body) + rawRespBody := json.RawMessage{} + if err := d.Decode(&rawRespBody); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawRespBody, out); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + return ctx, nil +} + +// Call twirp.ServerHooks.RequestReceived if the hook is available +func callRequestReceived(ctx context.Context, h *twirp.ServerHooks) (context.Context, error) { + if h == nil || h.RequestReceived == nil { + return ctx, nil + } + return h.RequestReceived(ctx) +} + +// Call twirp.ServerHooks.RequestRouted if the hook is available +func callRequestRouted(ctx context.Context, h *twirp.ServerHooks) (context.Context, error) { + if h == nil || h.RequestRouted == nil { + return ctx, nil + } + return h.RequestRouted(ctx) +} + +// Call twirp.ServerHooks.ResponsePrepared if the hook is available +func callResponsePrepared(ctx context.Context, h *twirp.ServerHooks) context.Context { + if h == nil || h.ResponsePrepared == nil { + return ctx + } + return h.ResponsePrepared(ctx) +} + +// Call twirp.ServerHooks.ResponseSent if the hook is available +func callResponseSent(ctx context.Context, h *twirp.ServerHooks) { + if h == nil || h.ResponseSent == nil { + return + } + h.ResponseSent(ctx) +} + +// Call twirp.ServerHooks.Error if the hook is available +func callError(ctx context.Context, h *twirp.ServerHooks, err twirp.Error) context.Context { + if h == nil || h.Error == nil { + return ctx + } + return h.Error(ctx, err) +} + +func callClientResponseReceived(ctx context.Context, h *twirp.ClientHooks) { + if h == nil || h.ResponseReceived == nil { + return + } + h.ResponseReceived(ctx) +} + +func callClientRequestPrepared(ctx context.Context, h *twirp.ClientHooks, req *http.Request) (context.Context, error) { + if h == nil || h.RequestPrepared == nil { + return ctx, nil + } + return h.RequestPrepared(ctx, req) +} + +func callClientError(ctx context.Context, h *twirp.ClientHooks, err twirp.Error) { + if h == nil || h.Error == nil { + return + } + h.Error(ctx, err) +} + +var twirpFileDescriptor0 = []byte{ + // 266 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x91, 0x4f, 0x4b, 0xf4, 0x30, + 0x18, 0xc4, 0xb7, 0xed, 0xfb, 0xba, 0xee, 0x03, 0xea, 0x92, 0x53, 0xd8, 0x8b, 0x25, 0x08, 0x56, + 0x64, 0x53, 0xd0, 0x6f, 0xb0, 0xe8, 0x45, 0xf0, 0x60, 0xf6, 0x22, 0x7a, 0x4a, 0xd3, 0xc7, 0x5a, + 0x6c, 0xfe, 0x90, 0x76, 0x95, 0xfd, 0x88, 0x7e, 0x2b, 0x31, 0x52, 0xab, 0x42, 0xf1, 0xe0, 0x2d, + 0x21, 0x33, 0x3f, 0x66, 0x26, 0x30, 0xef, 0x5e, 0x6a, 0xef, 0x0a, 0x34, 0xea, 0x91, 0x3b, 0x6f, + 0x3b, 0x4b, 0xa8, 0xb6, 0xa6, 0xb4, 0x96, 0x7b, 0x69, 0x2a, 0xf4, 0x7c, 0x78, 0x67, 0x57, 0x00, + 0x6b, 0x2d, 0x9b, 0xe6, 0x66, 0x83, 0x7e, 0x4b, 0xf6, 0x21, 0xae, 0x4b, 0x1a, 0xa5, 0x51, 0x96, + 0x88, 0xb8, 0x2e, 0x09, 0x85, 0xa9, 0xc6, 0xb6, 0x95, 0x15, 0xd2, 0x38, 0x8d, 0xb2, 0x99, 0xe8, + 0xaf, 0x84, 0xc0, 0x3f, 0x23, 0x35, 0xd2, 0x24, 0x4d, 0xb2, 0x99, 0x08, 0x67, 0x76, 0x0d, 0x7b, + 0x81, 0x25, 0xb0, 0x75, 0xd6, 0xb4, 0xf8, 0x47, 0xdc, 0x14, 0xfe, 0x5f, 0x6a, 0xd7, 0x6d, 0xd9, + 0x29, 0x1c, 0x5c, 0xe0, 0x83, 0xdc, 0x34, 0xdd, 0x27, 0xf9, 0x0b, 0x29, 0xfa, 0x46, 0x3a, 0x7b, + 0x8d, 0x60, 0xbe, 0x7a, 0xaf, 0xa6, 0xa5, 0x7f, 0x5a, 0xa3, 0x7f, 0xae, 0x15, 0x92, 0x7b, 0xd8, + 0x15, 0x4e, 0x85, 0x70, 0xe4, 0x88, 0x8f, 0x8d, 0xc1, 0x87, 0x25, 0x16, 0xc7, 0xbf, 0xa8, 0xfa, + 0x24, 0x6c, 0x42, 0x6e, 0x03, 0x3c, 0x44, 0x25, 0x87, 0xe3, 0xb6, 0x20, 0x58, 0x9c, 0x8c, 0x0b, + 0x7e, 0x74, 0x64, 0x93, 0x55, 0x7e, 0xb7, 0xac, 0x6c, 0x6f, 0x50, 0x56, 0xe7, 0x1f, 0xa6, 0xa5, + 0x77, 0x2a, 0x2f, 0xfa, 0x8e, 0xf9, 0x80, 0x28, 0x76, 0xc2, 0x77, 0x9f, 0xbf, 0x05, 0x00, 0x00, + 0xff, 0xff, 0x1b, 0x52, 0xe4, 0x0a, 0x02, 0x02, 0x00, 0x00, +} diff --git a/client.go b/client.go index 7ff02ca..89a3b9c 100644 --- a/client.go +++ b/client.go @@ -39,7 +39,6 @@ func (c *Client) DoClientRequest(ctx context.Context, client HTTPClient, url str header.Set("Accept", "application/protobuf") header.Set("Content-Type", "application/protobuf") - log.Debug().Str("url", url).Msg("call service") reader := bytes.NewReader(reqBodyBytes) req, err := http.NewRequest("POST", url, reader) if err != nil {