From a87a21154256d88a811080fe700d5d0b27fefc4c Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 11 May 2021 16:35:24 +0200 Subject: [PATCH] hack: call the cops I don't give a fuck Signed-off-by: Vicent Marti --- go.mod | 2 - go.sum | 19 ++++++++- go/hack/detrand.go | 41 +++++++++++++++++++ go/json2/marshal.go | 6 +++ go/vt/topo/events/shard_change_syslog_test.go | 6 +++ 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 go/hack/detrand.go diff --git a/go.mod b/go.mod index 0b7ac289c1..a1bf35d9cf 100644 --- a/go.mod +++ b/go.mod @@ -124,5 +124,3 @@ require ( ) replace github.com/skeema/tengo => github.com/planetscale/tengo v0.9.6-ps.v3 - -replace google.golang.org/protobuf => github.com/vmg/protobuf-go v1.26.1-0.20210505160851-6eface5a27ed diff --git a/go.sum b/go.sum index 539da681d6..9a23f041a8 100644 --- a/go.sum +++ b/go.sum @@ -303,6 +303,10 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +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= @@ -719,8 +723,6 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= -github.com/vmg/protobuf-go v1.26.1-0.20210505160851-6eface5a27ed h1:+oyd7hrL1v8bykB58/BRrso9cpznmMH2MP22xavGjiI= -github.com/vmg/protobuf-go v1.26.1-0.20210505160851-6eface5a27ed/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -1135,6 +1137,19 @@ google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQf google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/grpc/examples v0.0.0-20210430044426-28078834f35b h1:D/GTYPo6I1oEo08Bfpuj3xl5XE+UGHj7//5fVyKxhsQ= google.golang.org/grpc/examples v0.0.0-20210430044426-28078834f35b/go.mod h1:Ly7ZA/ARzg8fnPU9TyZIxoz33sEUuWX7txiqs8lPTgE= +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.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +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 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/DataDog/dd-trace-go.v1 v1.17.0 h1:j9vAp9Re9bbtA/QFehkJpNba/6W2IbJtNuXZophCa54= gopkg.in/DataDog/dd-trace-go.v1 v1.17.0/go.mod h1:DVp8HmDh8PuTu2Z0fVVlBsyWaC++fzwVCaGWylTe3tg= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= diff --git a/go/hack/detrand.go b/go/hack/detrand.go new file mode 100644 index 0000000000..1ea8a53ada --- /dev/null +++ b/go/hack/detrand.go @@ -0,0 +1,41 @@ +/* +Copyright 2021 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package hack + +import ( + _ "unsafe" +) + +// DisableProtoBufRandomness disables the random insertion of whitespace characters when +// serializing Protocol Buffers in textual form (both when serializing to JSON or to ProtoText) +// +// Since the introduction of the APIv2 for Protocol Buffers, the default serializers in the +// package insert random whitespace characters that don't change the meaning of the serialized +// code but make byte-wise comparison impossible. The rationale behind this decision is as follows: +// +// "The ProtoBuf authors believe that golden tests are Wrong" +// +// Fine. Unfortunately, Vitess makes extensive use of golden tests through its test suite, which +// expect byte-wise comparison to be stable between test runs. Using the new version of the +// package would require us to rewrite hundreds of tests, or alternatively, we could disable +// the randomness and call it a day. The method required to disable the randomness is not public, but +// that won't stop us because we're good at computers. +// +// Tracking issue: https://github.com/golang/protobuf/issues/1121 +// +//go:linkname DisableProtoBufRandomness google.golang.org/protobuf/internal/detrand.Disable +func DisableProtoBufRandomness() diff --git a/go/json2/marshal.go b/go/json2/marshal.go index a49322fcde..b260d7934d 100644 --- a/go/json2/marshal.go +++ b/go/json2/marshal.go @@ -19,8 +19,14 @@ package json2 import ( "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" + + "vitess.io/vitess/go/hack" ) +func init() { + hack.DisableProtoBufRandomness() +} + // MarshalPB marshals a proto. func MarshalPB(pb proto.Message) ([]byte, error) { return protojson.Marshal(pb) diff --git a/go/vt/topo/events/shard_change_syslog_test.go b/go/vt/topo/events/shard_change_syslog_test.go index c4054f6c1b..b31c07cded 100644 --- a/go/vt/topo/events/shard_change_syslog_test.go +++ b/go/vt/topo/events/shard_change_syslog_test.go @@ -20,9 +20,15 @@ import ( "log/syslog" "testing" + "vitess.io/vitess/go/hack" + topodatapb "vitess.io/vitess/go/vt/proto/topodata" ) +func init() { + hack.DisableProtoBufRandomness() +} + func TestShardChangeSyslog(t *testing.T) { wantSev, wantMsg := syslog.LOG_INFO, "keyspace-123/shard-123 [shard] status value: master_alias:{cell:\"test\" uid:123}" sc := &ShardChange{