Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instrumentation/otelgrpc: rename Typ to Type #2688

Merged
merged 5 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed

- Rename the `Typ` field of `"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc".InterceptorInfo` to `Type`. (#2688)
- Use Go 1.19 as the default version for CI testing/linting. (#2675)

## [1.9.0/0.34.0/0.4.0] - 2022-08-02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type gRPCPath struct {
// If name is not FullMethod, returned gRPCPath has empty service field.
func splitFullMethod(i *otelgrpc.InterceptorInfo) gRPCPath {
var name string
switch i.Typ {
switch i.Type {
case otelgrpc.UnaryServer:
name = i.UnaryServerInfo.FullMethod
case otelgrpc.StreamServer:
Expand Down Expand Up @@ -118,7 +118,7 @@ func MethodPrefix(pre string) otelgrpc.Filter {
func FullMethodName(n string) otelgrpc.Filter {
return func(i *otelgrpc.InterceptorInfo) bool {
var fm string
switch i.Typ {
switch i.Type {
case otelgrpc.UnaryClient, otelgrpc.StreamClient:
fm = i.Method
case otelgrpc.UnaryServer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,31 @@ func TestMethodName(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: MethodName("Hello"),
want: true,
},
{
name: "stream client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient},
f: MethodName("Hello"),
want: true,
},
{
name: "unary server interceptor",
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer},
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer},
f: MethodName("Hello"),
want: true,
},
{
name: "stream server interceptor",
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer},
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer},
f: MethodName("Hello"),
want: true,
},
{
name: "unary client interceptor fail",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: MethodName("Goodbye"),
want: false,
},
Expand All @@ -89,31 +89,31 @@ func TestMethodPrefix(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: MethodPrefix("Foobar"),
want: true,
},
{
name: "stream client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient},
f: MethodPrefix("Foobar"),
want: true,
},
{
name: "unary server interceptor",
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer},
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer},
f: MethodPrefix("Foobar"),
want: true,
},
{
name: "stream server interceptor",
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer},
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer},
f: MethodPrefix("Foobar"),
want: true,
},
{
name: "unary client interceptor fail",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: MethodPrefix("Barfoo"),
want: false,
},
Expand All @@ -131,31 +131,31 @@ func TestFullMethodName(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: FullMethodName(dummyFullMethodName),
want: true,
},
{
name: "stream client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient},
f: FullMethodName(dummyFullMethodName),
want: true,
},
{
name: "unary server interceptor",
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer},
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer},
f: FullMethodName(dummyFullMethodName),
want: true,
},
{
name: "stream server interceptor",
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer},
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer},
f: FullMethodName(dummyFullMethodName),
want: true,
},
{
name: "unary client interceptor fail",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: FullMethodName("/example.HelloService/Goodbye"),
want: false,
},
Expand All @@ -175,31 +175,31 @@ func TestServiceName(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: ServiceName("example.HelloService"),
want: true,
},
{
name: "stream client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient},
f: ServiceName("example.HelloService"),
want: true,
},
{
name: "unary server interceptor",
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer},
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer},
f: ServiceName("example.HelloService"),
want: true,
},
{
name: "stream server interceptor",
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer},
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer},
f: ServiceName("example.HelloService"),
want: true,
},
{
name: "unary client interceptor fail",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: ServiceName("opentelemetry.HelloService"),
want: false,
},
Expand All @@ -218,31 +218,31 @@ func TestServicePrefix(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: ServicePrefix("example"),
want: true,
},
{
name: "stream client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.StreamClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient},
f: ServicePrefix("example"),
want: true,
},
{
name: "unary server interceptor",
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer},
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer},
f: ServicePrefix("example"),
want: true,
},
{
name: "stream server interceptor",
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Typ: otelgrpc.StreamServer},
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer},
f: ServicePrefix("example"),
want: true,
},
{
name: "unary client interceptor fail",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: ServicePrefix("opentelemetry"),
want: false,
},
Expand All @@ -260,19 +260,19 @@ func TestAny(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor true && true",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: Any(MethodName("FoobarHello"), MethodPrefix("Foobar")),
want: true,
},
{
name: "unary client interceptor false && true",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: Any(MethodName("Hello"), MethodPrefix("Foobar")),
want: true,
},
{
name: "unary client interceptor false && false",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: Any(MethodName("Goodbye"), MethodPrefix("Barfoo")),
want: false,
},
Expand All @@ -290,19 +290,19 @@ func TestAll(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor true && true",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: All(MethodName("FoobarHello"), MethodPrefix("Foobar")),
want: true,
},
{
name: "unary client interceptor true && false",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: All(MethodName("FoobarHello"), MethodPrefix("Barfoo")),
want: false,
},
{
name: "unary client interceptor false && false",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: All(MethodName("FoobarGoodbye"), MethodPrefix("Barfoo")),
want: false,
},
Expand All @@ -320,19 +320,19 @@ func TestNone(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor true && true",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: None(MethodName("FoobarHello"), MethodPrefix("Foobar")),
want: false,
},
{
name: "unary client interceptor true && false",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: None(MethodName("FoobarHello"), MethodPrefix("Barfoo")),
want: false,
},
{
name: "unary client interceptor false && false",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: None(MethodName("FoobarGoodbye"), MethodPrefix("Barfoo")),
want: true,
},
Expand All @@ -350,19 +350,19 @@ func TestNot(t *testing.T) {
tcs := []testCase{
{
name: "methodname not",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: Not(MethodName("FoobarHello")),
want: false,
},
{
name: "method prefix not",
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Typ: otelgrpc.UnaryServer},
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer},
f: Not(MethodPrefix("FoobarHello")),
want: false,
},
{
name: "unary client interceptor not all(true && true)",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient},
f: Not(All(MethodName("FoobarHello"), MethodPrefix("Foobar"))),
want: false,
},
Expand All @@ -384,49 +384,49 @@ func TestHealthCheck(t *testing.T) {
tcs := []testCase{
{
name: "unary client interceptor healthcheck",
i: &otelgrpc.InterceptorInfo{Method: healthCheck, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: healthCheck, Type: otelgrpc.UnaryClient},
f: HealthCheck(),
want: true,
},
{
name: "stream client interceptor healthcheck",
i: &otelgrpc.InterceptorInfo{Method: healthCheck, Typ: otelgrpc.StreamClient},
i: &otelgrpc.InterceptorInfo{Method: healthCheck, Type: otelgrpc.StreamClient},
f: HealthCheck(),
want: true,
},
{
name: "unary server interceptor healthcheck",
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(healthCheck), Typ: otelgrpc.UnaryServer},
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(healthCheck), Type: otelgrpc.UnaryServer},
f: HealthCheck(),
want: true,
},
{
name: "stream server interceptor healthcheck",
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(healthCheck), Typ: otelgrpc.StreamServer},
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(healthCheck), Type: otelgrpc.StreamServer},
f: HealthCheck(),
want: true,
},
{
name: "unary client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Typ: otelgrpc.UnaryClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Type: otelgrpc.UnaryClient},
f: HealthCheck(),
want: false,
},
{
name: "stream client interceptor",
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Typ: otelgrpc.StreamClient},
i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Type: otelgrpc.StreamClient},
f: HealthCheck(),
want: false,
},
{
name: "unary server interceptor",
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethod), Typ: otelgrpc.UnaryServer},
i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethod), Type: otelgrpc.UnaryServer},
f: HealthCheck(),
want: false,
},
{
name: "stream server interceptor",
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethod), Typ: otelgrpc.StreamServer},
i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethod), Type: otelgrpc.StreamServer},
f: HealthCheck(),
want: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor {
cfg := newConfig(opts)
i := &InterceptorInfo{
Method: method,
Typ: UnaryClient,
Type: UnaryClient,
}
if cfg.Filter != nil && !cfg.Filter(i) {
return invoker(ctx, method, req, reply, cc, callOpts...)
Expand Down Expand Up @@ -255,7 +255,7 @@ func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor {
cfg := newConfig(opts)
i := &InterceptorInfo{
Method: method,
Typ: StreamClient,
Type: StreamClient,
}
if cfg.Filter != nil && !cfg.Filter(i) {
return streamer(ctx, desc, cc, method, callOpts...)
Expand Down Expand Up @@ -321,7 +321,7 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {
cfg := newConfig(opts)
i := &InterceptorInfo{
UnaryServerInfo: info,
Typ: UnaryServer,
Type: UnaryServer,
}
if cfg.Filter != nil && !cfg.Filter(i) {
return handler(ctx, req)
Expand Down Expand Up @@ -418,7 +418,7 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor {
cfg := newConfig(opts)
i := &InterceptorInfo{
StreamServerInfo: info,
Typ: StreamServer,
Type: StreamServer,
}
if cfg.Filter != nil && !cfg.Filter(i) {
return handler(srv, wrapServerStream(ctx, ss))
Expand Down
Loading