-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
otel: update usage of otelgrpc interceptors to use stat handlers
The otelgrpc interceptors were deprecated. This updates the areas where these were used to use the stat handlers instead of the interceptors. This helps with creating a single method for both unary and stream rpcs and also ensures we aren't using a deprecated function for the future. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
- Loading branch information
1 parent
5e0fe27
commit b0183dd
Showing
5 changed files
with
104 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package grpcutil | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc/stats" | ||
) | ||
|
||
type contextKey int | ||
|
||
const filterContextKey contextKey = iota | ||
|
||
type StatsFilterFunc func(info *stats.RPCTagInfo) bool | ||
|
||
func StatsFilter(h stats.Handler, fn StatsFilterFunc) stats.Handler { | ||
return &statsFilter{ | ||
inner: h, | ||
filter: fn, | ||
} | ||
} | ||
|
||
type statsFilter struct { | ||
inner stats.Handler | ||
filter func(info *stats.RPCTagInfo) bool | ||
} | ||
|
||
func (s *statsFilter) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context { | ||
if s.filter(info) { | ||
return context.WithValue(ctx, filterContextKey, struct{}{}) | ||
} | ||
return s.inner.TagRPC(ctx, info) | ||
} | ||
|
||
func (s *statsFilter) HandleRPC(ctx context.Context, rpcStats stats.RPCStats) { | ||
if ctx.Value(filterContextKey) != nil { | ||
return | ||
} | ||
s.inner.HandleRPC(ctx, rpcStats) | ||
} | ||
|
||
func (s *statsFilter) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context { | ||
return s.inner.TagConn(ctx, info) | ||
} | ||
|
||
func (s *statsFilter) HandleConn(ctx context.Context, connStats stats.ConnStats) { | ||
s.inner.HandleConn(ctx, connStats) | ||
} |