From 2fdbb250788b1d5f66b45eca0d2a0b62d2f886f0 Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Zaib Date: Wed, 2 Apr 2025 16:33:50 +0100 Subject: [PATCH 1/2] Remove deprecated package --- .../otelgrpc/filters/interceptor/filters.go | 171 ------- .../filters/interceptor/filters_test.go | 431 ------------------ 2 files changed, 602 deletions(-) delete mode 100644 instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor/filters.go delete mode 100644 instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor/filters_test.go diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor/filters.go b/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor/filters.go deleted file mode 100644 index ca9cc9a305d..00000000000 --- a/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor/filters.go +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -// Package interceptor provides a set of filters useful with the -// [otelgrpc.WithInterceptorFilter] option to control which inbound requests are instrumented. -// -// Deprecated: Use filters package and [otelgrpc.WithFilter] instead. -package interceptor // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor" - -import ( - "path" - "strings" - - "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" -) - -type gRPCPath struct { - service string - method string -} - -// splitFullMethod splits path defined in gRPC protocol -// and returns as gRPCPath object that has divided service and method names -// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md -// If name is not FullMethod, returned gRPCPath has empty service field. -func splitFullMethod(i *otelgrpc.InterceptorInfo) gRPCPath { - var name string - switch i.Type { - case otelgrpc.UnaryServer: - name = i.UnaryServerInfo.FullMethod - case otelgrpc.StreamServer: - name = i.StreamServerInfo.FullMethod - case otelgrpc.UnaryClient, otelgrpc.StreamClient: - name = i.Method - default: - name = i.Method - } - - s, m := path.Split(name) - if s != "" { - s = path.Clean(s) - s = strings.TrimLeft(s, "/") - } - - return gRPCPath{ - service: s, - method: m, - } -} - -// Any takes a list of Filters and returns a Filter that -// returns true if any Filter in the list returns true. -// -// Deprecated: Use stats handler instead. -func Any(fs ...otelgrpc.InterceptorFilter) otelgrpc.InterceptorFilter { - return func(i *otelgrpc.InterceptorInfo) bool { - for _, f := range fs { - if f(i) { - return true - } - } - return false - } -} - -// All takes a list of Filters and returns a Filter that -// returns true only if all Filters in the list return true. -// -// Deprecated: Use stats handler instead. -func All(fs ...otelgrpc.InterceptorFilter) otelgrpc.InterceptorFilter { - return func(i *otelgrpc.InterceptorInfo) bool { - for _, f := range fs { - if !f(i) { - return false - } - } - return true - } -} - -// None takes a list of Filters and returns a Filter that returns -// true only if none of the Filters in the list return true. -// -// Deprecated: Use stats handler instead. -func None(fs ...otelgrpc.InterceptorFilter) otelgrpc.InterceptorFilter { - return Not(Any(fs...)) -} - -// Not provides a convenience mechanism for inverting a Filter. -// -// Deprecated: Use stats handler instead. -func Not(f otelgrpc.InterceptorFilter) otelgrpc.InterceptorFilter { - return func(i *otelgrpc.InterceptorInfo) bool { - return !f(i) - } -} - -// MethodName returns a Filter that returns true if the request's -// method name matches the provided string n. -// -// Deprecated: Use stats handler instead. -func MethodName(n string) otelgrpc.InterceptorFilter { - return func(i *otelgrpc.InterceptorInfo) bool { - p := splitFullMethod(i) - return p.method == n - } -} - -// MethodPrefix returns a Filter that returns true if the request's -// method starts with the provided string pre. -// -// Deprecated: Use stats handler instead. -func MethodPrefix(pre string) otelgrpc.InterceptorFilter { - return func(i *otelgrpc.InterceptorInfo) bool { - p := splitFullMethod(i) - return strings.HasPrefix(p.method, pre) - } -} - -// FullMethodName returns a Filter that returns true if the request's -// full RPC method string, i.e. /package.service/method, starts with -// the provided string n. -// -// Deprecated: Use stats handler instead. -func FullMethodName(n string) otelgrpc.InterceptorFilter { - return func(i *otelgrpc.InterceptorInfo) bool { - var fm string - switch i.Type { - case otelgrpc.UnaryClient, otelgrpc.StreamClient: - fm = i.Method - case otelgrpc.UnaryServer: - fm = i.UnaryServerInfo.FullMethod - case otelgrpc.StreamServer: - fm = i.StreamServerInfo.FullMethod - default: - fm = i.Method - } - return fm == n - } -} - -// ServiceName returns a Filter that returns true if the request's -// service name, i.e. package.service, matches s. -// -// Deprecated: Use stats handler instead. -func ServiceName(s string) otelgrpc.InterceptorFilter { - return func(i *otelgrpc.InterceptorInfo) bool { - p := splitFullMethod(i) - return p.service == s - } -} - -// ServicePrefix returns a Filter that returns true if the request's -// service name, i.e. package.service, starts with the provided string pre. -// -// Deprecated: Use stats handler instead. -func ServicePrefix(pre string) otelgrpc.InterceptorFilter { - return func(i *otelgrpc.InterceptorInfo) bool { - p := splitFullMethod(i) - return strings.HasPrefix(p.service, pre) - } -} - -// HealthCheck returns a Filter that returns true if the request's -// service name is health check defined by gRPC Health Checking Protocol. -// https://github.com/grpc/grpc/blob/master/doc/health-checking.md -// -// Deprecated: Use stats handler instead. -func HealthCheck() otelgrpc.InterceptorFilter { - return ServicePrefix("grpc.health.v1.Health") -} diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor/filters_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor/filters_test.go deleted file mode 100644 index e2816cd7b64..00000000000 --- a/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor/filters_test.go +++ /dev/null @@ -1,431 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package interceptor // import "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor" - -import ( - "testing" - - "google.golang.org/grpc" - - "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" -) - -type testCase struct { - name string - i *otelgrpc.InterceptorInfo - //nolint:staticcheck // Interceptors are deprecated and will be removed in the next release. - f otelgrpc.InterceptorFilter - want bool -} - -func dummyUnaryServerInfo(n string) *grpc.UnaryServerInfo { - return &grpc.UnaryServerInfo{ - FullMethod: n, - } -} - -func dummyStreamServerInfo(n string) *grpc.StreamServerInfo { - return &grpc.StreamServerInfo{ - FullMethod: n, - } -} - -func TestMethodName(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/Hello" - tcs := []testCase{ - { - name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: MethodName("Hello"), - want: true, - }, - { - name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, - f: MethodName("Hello"), - want: true, - }, - { - name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, - f: MethodName("Hello"), - want: true, - }, - { - name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, - f: MethodName("Hello"), - want: true, - }, - { - name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: MethodName("Goodbye"), - want: false, - }, - } - - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestMethodPrefix(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/FoobarHello" - tcs := []testCase{ - { - name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: MethodPrefix("Foobar"), - want: true, - }, - { - name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, - f: MethodPrefix("Foobar"), - want: true, - }, - { - name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, - f: MethodPrefix("Foobar"), - want: true, - }, - { - name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, - f: MethodPrefix("Foobar"), - want: true, - }, - { - name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: MethodPrefix("Barfoo"), - want: false, - }, - } - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestFullMethodName(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/Hello" - tcs := []testCase{ - { - name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: FullMethodName(dummyFullMethodName), - want: true, - }, - { - name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, - f: FullMethodName(dummyFullMethodName), - want: true, - }, - { - name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, - f: FullMethodName(dummyFullMethodName), - want: true, - }, - { - name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, - f: FullMethodName(dummyFullMethodName), - want: true, - }, - { - name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: FullMethodName("/example.HelloService/Goodbye"), - want: false, - }, - } - - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestServiceName(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/Hello" - - tcs := []testCase{ - { - name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: ServiceName("example.HelloService"), - want: true, - }, - { - name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, - f: ServiceName("example.HelloService"), - want: true, - }, - { - name: "unary server interceptor", - 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), Type: otelgrpc.StreamServer}, - f: ServiceName("example.HelloService"), - want: true, - }, - { - name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: ServiceName("opentelemetry.HelloService"), - want: false, - }, - } - - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestServicePrefix(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/FoobarHello" - tcs := []testCase{ - { - name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: ServicePrefix("example"), - want: true, - }, - { - name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.StreamClient}, - f: ServicePrefix("example"), - want: true, - }, - { - name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethodName), Type: otelgrpc.UnaryServer}, - f: ServicePrefix("example"), - want: true, - }, - { - name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethodName), Type: otelgrpc.StreamServer}, - f: ServicePrefix("example"), - want: true, - }, - { - name: "unary client interceptor fail", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: ServicePrefix("opentelemetry"), - want: false, - }, - } - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestAny(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/FoobarHello" - tcs := []testCase{ - { - name: "unary client interceptor true && true", - 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, Type: otelgrpc.UnaryClient}, - f: Any(MethodName("Hello"), MethodPrefix("Foobar")), - want: true, - }, - { - name: "unary client interceptor false && false", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: Any(MethodName("Goodbye"), MethodPrefix("Barfoo")), - want: false, - }, - } - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestAll(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/FoobarHello" - tcs := []testCase{ - { - name: "unary client interceptor true && true", - 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, Type: otelgrpc.UnaryClient}, - f: All(MethodName("FoobarHello"), MethodPrefix("Barfoo")), - want: false, - }, - { - name: "unary client interceptor false && false", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: All(MethodName("FoobarGoodbye"), MethodPrefix("Barfoo")), - want: false, - }, - } - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestNone(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/FoobarHello" - tcs := []testCase{ - { - name: "unary client interceptor true && true", - 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, Type: otelgrpc.UnaryClient}, - f: None(MethodName("FoobarHello"), MethodPrefix("Barfoo")), - want: false, - }, - { - name: "unary client interceptor false && false", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: None(MethodName("FoobarGoodbye"), MethodPrefix("Barfoo")), - want: true, - }, - } - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestNot(t *testing.T) { - const dummyFullMethodName = "/example.HelloService/FoobarHello" - tcs := []testCase{ - { - name: "methodname not", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethodName, Type: otelgrpc.UnaryClient}, - f: Not(MethodName("FoobarHello")), - want: false, - }, - { - name: "method prefix not", - 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, Type: otelgrpc.UnaryClient}, - f: Not(All(MethodName("FoobarHello"), MethodPrefix("Foobar"))), - want: false, - }, - } - - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} - -func TestHealthCheck(t *testing.T) { - const ( - healthCheck = "/grpc.health.v1.Health/Check" - dummyFullMethod = "/example.HelloService/FoobarHello" - ) - tcs := []testCase{ - { - name: "unary client interceptor healthcheck", - i: &otelgrpc.InterceptorInfo{Method: healthCheck, Type: otelgrpc.UnaryClient}, - f: HealthCheck(), - want: true, - }, - { - name: "stream client interceptor healthcheck", - i: &otelgrpc.InterceptorInfo{Method: healthCheck, Type: otelgrpc.StreamClient}, - f: HealthCheck(), - want: true, - }, - { - name: "unary server interceptor healthcheck", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(healthCheck), Type: otelgrpc.UnaryServer}, - f: HealthCheck(), - want: true, - }, - { - name: "stream server interceptor healthcheck", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(healthCheck), Type: otelgrpc.StreamServer}, - f: HealthCheck(), - want: true, - }, - { - name: "unary client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Type: otelgrpc.UnaryClient}, - f: HealthCheck(), - want: false, - }, - { - name: "stream client interceptor", - i: &otelgrpc.InterceptorInfo{Method: dummyFullMethod, Type: otelgrpc.StreamClient}, - f: HealthCheck(), - want: false, - }, - { - name: "unary server interceptor", - i: &otelgrpc.InterceptorInfo{UnaryServerInfo: dummyUnaryServerInfo(dummyFullMethod), Type: otelgrpc.UnaryServer}, - f: HealthCheck(), - want: false, - }, - { - name: "stream server interceptor", - i: &otelgrpc.InterceptorInfo{StreamServerInfo: dummyStreamServerInfo(dummyFullMethod), Type: otelgrpc.StreamServer}, - f: HealthCheck(), - want: false, - }, - } - - for _, tc := range tcs { - out := tc.f(tc.i) - if tc.want != out { - t.Errorf("test case '%v' failed, wanted %v but obtained %v", tc.name, tc.want, out) - } - } -} From 54a7e8a1acb1a8eaf483b9086a460a11dc991fd6 Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Zaib Date: Wed, 2 Apr 2025 16:34:28 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b89474c4e23..66217161f74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The deprecated `SemVersion` function in `go.opentelemetry.io/contrib/samplers/probability/consistent` is removed, use `Version` instead. (#7072) - The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`, use `Version` function instead. (#7084) - The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`, use `Version` function instead. (#7085) +- The deprecated `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor` package is removed, use `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/filters` instead. (#7110)