Skip to content

Commit

Permalink
Fix context import; add legacy proto messagev1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kralicky committed Mar 16, 2023
1 parent d6ce8ad commit 35be186
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 111 deletions.
28 changes: 25 additions & 3 deletions clientconn.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package totem

import (
"context"
"fmt"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/protoadapt"
)

type ClientConn struct {
Expand Down Expand Up @@ -77,7 +78,7 @@ func (cc *ClientConn) invoke(
if req.Metadata != nil {
md = metadata.Join(md, req.Metadata.ToMD())
}
case proto.Message:
case protoadapt.MessageV2:
lg.With(
zap.String("method", method),
).Debug("invoking method")
Expand All @@ -86,6 +87,16 @@ func (cc *ClientConn) invoke(
if err != nil {
return err
}
case protoadapt.MessageV1:
reqv2 := protoadapt.MessageV2Of(req)
lg.With(
zap.String("method", method),
).Debug("invoking method")
var err error
reqMsg, err = proto.Marshal(reqv2)
if err != nil {
return err
}
default:
panic(fmt.Sprintf("[totem] unsupported request type: %T", req))
}
Expand Down Expand Up @@ -143,14 +154,25 @@ func (cc *ClientConn) invoke(
reply.Content = &RPC_Response{
Response: resp,
}
case proto.Message:
case protoadapt.MessageV2:
if err := proto.Unmarshal(resp.GetResponse(), reply); err != nil {
cc.logger.With(
zap.Uint64("tag", rpc.Tag),
zap.String("method", method),
zap.Error(err),
).Error("received malformed response message")

return fmt.Errorf("[totem] malformed response: %w", err)
}
case protoadapt.MessageV1:
replyv2 := protoadapt.MessageV2Of(reply)
if err := proto.Unmarshal(resp.GetResponse(), replyv2); err != nil {
cc.logger.With(
zap.Uint64("tag", rpc.Tag),
zap.String("method", method),
zap.Error(err),
).Error("received malformed response message")

return fmt.Errorf("[totem] malformed response: %w", err)
}
default:
Expand Down
3 changes: 2 additions & 1 deletion discovery.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package totem

import (
"context"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
"golang.org/x/net/context"
"google.golang.org/protobuf/proto"
)

Expand Down
67 changes: 36 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,60 @@ module github.com/kralicky/totem
go 1.18

require (
github.com/charmbracelet/lipgloss v0.6.0
github.com/charmbracelet/lipgloss v0.7.1
github.com/google/uuid v1.3.0
github.com/jhump/protoreflect v1.14.1
github.com/kralicky/gpkg v0.0.0-20220311205216-0d8ea9557555
github.com/kralicky/ragu v1.0.0-rc4
github.com/kralicky/ragu v1.0.0-rc7
github.com/magefile/mage v1.14.0
github.com/onsi/ginkgo/v2 v2.8.0
github.com/onsi/gomega v1.26.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.38.0
go.opentelemetry.io/contrib/propagators/autoprop v0.38.0
go.opentelemetry.io/otel v1.13.0
go.opentelemetry.io/otel/exporters/jaeger v1.13.0
go.opentelemetry.io/otel/sdk v1.13.0
go.opentelemetry.io/otel/trace v1.13.0
github.com/onsi/ginkgo/v2 v2.9.1
github.com/onsi/gomega v1.27.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.40.0
go.opentelemetry.io/contrib/propagators/autoprop v0.40.0
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/exporters/jaeger v1.14.0
go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/trace v1.14.0
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/net v0.5.0
google.golang.org/genproto v0.0.0-20230202175211-008b39050e57
google.golang.org/grpc v1.52.3
google.golang.org/protobuf v1.28.1
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.30.0
)

require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/flosch/pongo2/v6 v6.0.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kralicky/grpc-gateway/v2 v2.11.3 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 // indirect
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/samber/lo v1.28.2 // indirect
go.opentelemetry.io/contrib/propagators/aws v1.13.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.13.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.13.0 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.13.0 // indirect
go.opentelemetry.io/otel/metric v0.35.0 // indirect
github.com/samber/lo v1.37.0 // indirect
go.opentelemetry.io/contrib/propagators/aws v1.15.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.15.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.15.0 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.15.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/tools v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 35be186

Please sign in to comment.