From c724ecd2ee4f1be1496a364749a9fb4e73a2a37c Mon Sep 17 00:00:00 2001 From: Yuxuan 'fishy' Wang Date: Mon, 8 Apr 2024 09:51:00 -0700 Subject: [PATCH] Update thrift to v0.20.0 Also add a test for 00f31e521d4e1975074a187f1851354d0532146d. --- go.mod | 2 +- go.sum | 4 +- .../reddit/baseplate/GoUnusedProtection__.go | 2 +- .../reddit/baseplate/baseplate-consts.go | 12 +- internal/gen-go/reddit/baseplate/baseplate.go | 104 ++++++++++++++++-- internal/thriftint/baseplate_error_test.go | 44 ++++++++ 6 files changed, 147 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 57eec2adf..f32af4eb1 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/Shopify/sarama v1.29.1 github.com/alicebob/miniredis/v2 v2.14.3 - github.com/apache/thrift v0.19.0 + github.com/apache/thrift v0.20.0 github.com/avast/retry-go v3.0.0+incompatible github.com/fsnotify/fsnotify v1.5.4 github.com/getsentry/sentry-go v0.11.0 diff --git a/go.sum b/go.sum index e64b94881..bd966d1e0 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZp github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= github.com/alicebob/miniredis/v2 v2.14.3 h1:QWoo2wchYmLgOB6ctlTt2dewQ1Vu6phl+iQbwT8SYGo= github.com/alicebob/miniredis/v2 v2.14.3/go.mod h1:gquAfGbzn92jvtrSC69+6zZnwSODVXVpYDRaGhWaL6I= -github.com/apache/thrift v0.19.0 h1:sOqkWPzMj7w6XaYbJQG7m4sGqVolaW/0D28Ln7yPzMk= -github.com/apache/thrift v0.19.0/go.mod h1:SUALL216IiaOw2Oy+5Vs9lboJ/t9g40C+G07Dc0QC1I= +github.com/apache/thrift v0.20.0 h1:631+KvYbsBZxmuJjYwhezVsrfc/TbqtZV4QcxOX1fOI= +github.com/apache/thrift v0.20.0/go.mod h1:hOk1BQqcp2OLzGsyVXdfMk7YFlMxK3aoEVhjD06QhB8= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0= github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= diff --git a/internal/gen-go/reddit/baseplate/GoUnusedProtection__.go b/internal/gen-go/reddit/baseplate/GoUnusedProtection__.go index ea1c598df..169ab3019 100644 --- a/internal/gen-go/reddit/baseplate/GoUnusedProtection__.go +++ b/internal/gen-go/reddit/baseplate/GoUnusedProtection__.go @@ -1,4 +1,4 @@ -// Code generated by Thrift Compiler (0.19.0). DO NOT EDIT. +// Code generated by Thrift Compiler (0.20.0). DO NOT EDIT. package baseplate diff --git a/internal/gen-go/reddit/baseplate/baseplate-consts.go b/internal/gen-go/reddit/baseplate/baseplate-consts.go index e879ea8b7..1724c9b6a 100644 --- a/internal/gen-go/reddit/baseplate/baseplate-consts.go +++ b/internal/gen-go/reddit/baseplate/baseplate-consts.go @@ -1,4 +1,4 @@ -// Code generated by Thrift Compiler (0.19.0). DO NOT EDIT. +// Code generated by Thrift Compiler (0.20.0). DO NOT EDIT. package baseplate @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "log/slog" "time" thrift "github.com/apache/thrift/lib/go/thrift" "strings" @@ -14,12 +15,13 @@ import ( ) // (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = errors.New +var _ = bytes.Equal var _ = context.Background +var _ = errors.New +var _ = fmt.Printf +var _ = slog.Log var _ = time.Now -var _ = bytes.Equal +var _ = thrift.ZERO // (needed by validator.) var _ = strings.Contains var _ = regexp.MatchString diff --git a/internal/gen-go/reddit/baseplate/baseplate.go b/internal/gen-go/reddit/baseplate/baseplate.go index 2b0afc7d0..46fa9af5e 100644 --- a/internal/gen-go/reddit/baseplate/baseplate.go +++ b/internal/gen-go/reddit/baseplate/baseplate.go @@ -1,4 +1,4 @@ -// Code generated by Thrift Compiler (0.19.0). DO NOT EDIT. +// Code generated by Thrift Compiler (0.20.0). DO NOT EDIT. package baseplate @@ -8,6 +8,7 @@ import ( "database/sql/driver" "errors" "fmt" + "log/slog" "time" thrift "github.com/apache/thrift/lib/go/thrift" "strings" @@ -15,12 +16,13 @@ import ( ) // (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = errors.New +var _ = bytes.Equal var _ = context.Background +var _ = errors.New +var _ = fmt.Printf +var _ = slog.Log var _ = time.Now -var _ = bytes.Equal +var _ = thrift.ZERO // (needed by validator.) var _ = strings.Contains var _ = regexp.MatchString @@ -247,7 +249,7 @@ func (p *IsHealthyRequest) GetProbe() IsHealthyProbe { if !p.IsSetProbe() { return IsHealthyRequest_Probe_DEFAULT } -return *p.Probe + return *p.Probe } func (p *IsHealthyRequest) IsSetProbe() bool { return p.Probe != nil @@ -348,6 +350,19 @@ func (p *IsHealthyRequest) String() string { return fmt.Sprintf("IsHealthyRequest(%+v)", *p) } +func (p *IsHealthyRequest) LogValue() slog.Value { + if p == nil { + return slog.AnyValue(nil) + } + v := thrift.SlogTStructWrapper{ + Type: "*baseplate.IsHealthyRequest", + Value: p, + } + return slog.AnyValue(v) +} + +var _ slog.LogValuer = (*IsHealthyRequest)(nil) + func (p *IsHealthyRequest) Validate() error { return nil } @@ -391,14 +406,14 @@ func (p *Error) GetCode() int32 { if !p.IsSetCode() { return Error_Code_DEFAULT } -return *p.Code + return *p.Code } var Error_Message_DEFAULT string func (p *Error) GetMessage() string { if !p.IsSetMessage() { return Error_Message_DEFAULT } -return *p.Message + return *p.Message } var Error_Details_DEFAULT map[string]string @@ -410,7 +425,7 @@ func (p *Error) GetRetryable() bool { if !p.IsSetRetryable() { return Error_Retryable_DEFAULT } -return *p.Retryable + return *p.Retryable } func (p *Error) IsSetCode() bool { return p.Code != nil @@ -674,6 +689,19 @@ func (Error) TExceptionType() thrift.TExceptionType { var _ thrift.TException = (*Error)(nil) +func (p *Error) LogValue() slog.Value { + if p == nil { + return slog.AnyValue(nil) + } + v := thrift.SlogTStructWrapper{ + Type: "*baseplate.Error", + Value: p, + } + return slog.AnyValue(v) +} + +var _ slog.LogValuer = (*Error)(nil) + func (p *Error) Validate() error { return nil } @@ -949,6 +977,19 @@ func (p *BaseplateServiceIsHealthyArgs) String() string { return fmt.Sprintf("BaseplateServiceIsHealthyArgs(%+v)", *p) } +func (p *BaseplateServiceIsHealthyArgs) LogValue() slog.Value { + if p == nil { + return slog.AnyValue(nil) + } + v := thrift.SlogTStructWrapper{ + Type: "*baseplate.BaseplateServiceIsHealthyArgs", + Value: p, + } + return slog.AnyValue(v) +} + +var _ slog.LogValuer = (*BaseplateServiceIsHealthyArgs)(nil) + // Attributes: // - Success type BaseplateServiceIsHealthyResult struct { @@ -964,7 +1005,7 @@ func (p *BaseplateServiceIsHealthyResult) GetSuccess() bool { if !p.IsSetSuccess() { return BaseplateServiceIsHealthyResult_Success_DEFAULT } -return *p.Success + return *p.Success } func (p *BaseplateServiceIsHealthyResult) IsSetSuccess() bool { return p.Success != nil @@ -1049,6 +1090,19 @@ func (p *BaseplateServiceIsHealthyResult) String() string { return fmt.Sprintf("BaseplateServiceIsHealthyResult(%+v)", *p) } +func (p *BaseplateServiceIsHealthyResult) LogValue() slog.Value { + if p == nil { + return slog.AnyValue(nil) + } + v := thrift.SlogTStructWrapper{ + Type: "*baseplate.BaseplateServiceIsHealthyResult", + Value: p, + } + return slog.AnyValue(v) +} + +var _ slog.LogValuer = (*BaseplateServiceIsHealthyResult)(nil) + type BaseplateServiceV2 interface { //The base for any baseplate-based service. // @@ -1289,7 +1343,7 @@ func (p *BaseplateServiceV2IsHealthyArgs) GetRequest() *IsHealthyRequest { if !p.IsSetRequest() { return BaseplateServiceV2IsHealthyArgs_Request_DEFAULT } -return p.Request + return p.Request } func (p *BaseplateServiceV2IsHealthyArgs) IsSetRequest() bool { return p.Request != nil @@ -1372,6 +1426,19 @@ func (p *BaseplateServiceV2IsHealthyArgs) String() string { return fmt.Sprintf("BaseplateServiceV2IsHealthyArgs(%+v)", *p) } +func (p *BaseplateServiceV2IsHealthyArgs) LogValue() slog.Value { + if p == nil { + return slog.AnyValue(nil) + } + v := thrift.SlogTStructWrapper{ + Type: "*baseplate.BaseplateServiceV2IsHealthyArgs", + Value: p, + } + return slog.AnyValue(v) +} + +var _ slog.LogValuer = (*BaseplateServiceV2IsHealthyArgs)(nil) + // Attributes: // - Success type BaseplateServiceV2IsHealthyResult struct { @@ -1387,7 +1454,7 @@ func (p *BaseplateServiceV2IsHealthyResult) GetSuccess() bool { if !p.IsSetSuccess() { return BaseplateServiceV2IsHealthyResult_Success_DEFAULT } -return *p.Success + return *p.Success } func (p *BaseplateServiceV2IsHealthyResult) IsSetSuccess() bool { return p.Success != nil @@ -1472,4 +1539,17 @@ func (p *BaseplateServiceV2IsHealthyResult) String() string { return fmt.Sprintf("BaseplateServiceV2IsHealthyResult(%+v)", *p) } +func (p *BaseplateServiceV2IsHealthyResult) LogValue() slog.Value { + if p == nil { + return slog.AnyValue(nil) + } + v := thrift.SlogTStructWrapper{ + Type: "*baseplate.BaseplateServiceV2IsHealthyResult", + Value: p, + } + return slog.AnyValue(v) +} + +var _ slog.LogValuer = (*BaseplateServiceV2IsHealthyResult)(nil) + diff --git a/internal/thriftint/baseplate_error_test.go b/internal/thriftint/baseplate_error_test.go index a48f38ea0..abe2b6f4e 100644 --- a/internal/thriftint/baseplate_error_test.go +++ b/internal/thriftint/baseplate_error_test.go @@ -3,6 +3,9 @@ package thriftint_test import ( "errors" "fmt" + "io" + "log/slog" + "strings" "testing" "github.com/apache/thrift/lib/go/thrift" @@ -138,3 +141,44 @@ func TestWrapBaseplateError(t *testing.T) { } }) } + +func TestSlogErrorValue(t *testing.T) { + err := &baseplatethrift.Error{ + Message: thrift.StringPtr("message"), + Code: thrift.Int32Ptr(1), + Retryable: thrift.BoolPtr(true), + Details: map[string]string{ + "foo": "bar", + }, + } + opts := &slog.HandlerOptions{ + AddSource: false, + ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { + // drop time + if len(groups) == 0 && a.Key == slog.TimeKey { + return slog.Attr{} + } + return a + }, + } + + for label, base := range map[string]func(w io.Writer) slog.Handler{ + "json": func(w io.Writer) slog.Handler { + return slog.NewJSONHandler(w, opts) + }, + "text": func(w io.Writer) slog.Handler { + return slog.NewTextHandler(w, opts) + }, + } { + t.Run(label, func(t *testing.T) { + // When using thrift 0.20.0+, make sure that slog logs the same before and + // after thriftint.WrapBaseplateError. + var gotWriter, wantWriter strings.Builder + slog.New(base(&gotWriter)).Info("foo", "err", thriftint.WrapBaseplateError(err)) + slog.New(base(&wantWriter)).Info("foo", "err", err) + if got, want := gotWriter.String(), wantWriter.String(); got != want { + t.Errorf("got %q want %q", got, want) + } + }) + } +}