mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-24 21:48:23 +02:00
telemetry: Refactor GRPC Server Handler (#756)
* Refactor GRPC server stats handler location
This commit is contained in:
parent
e2a7149c36
commit
ca5f68e371
7 changed files with 106 additions and 21 deletions
37
internal/telemetry/grpc_test.go
Normal file
37
internal/telemetry/grpc_test.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package telemetry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.opencensus.io/plugin/ocgrpc"
|
||||
grpcstats "google.golang.org/grpc/stats"
|
||||
)
|
||||
|
||||
type mockTagHandler struct {
|
||||
called bool
|
||||
}
|
||||
|
||||
type mockCtxTag string
|
||||
|
||||
func (m *mockTagHandler) TagRPC(ctx context.Context, tagInfo *grpcstats.RPCTagInfo) context.Context {
|
||||
m.called = true
|
||||
return context.WithValue(ctx, mockCtxTag("added"), "true")
|
||||
}
|
||||
|
||||
func Test_GRPCServerStatsHandler(t *testing.T) {
|
||||
|
||||
metricsHandler := &mockTagHandler{}
|
||||
h := &GRPCServerStatsHandler{
|
||||
metricsHandler: metricsHandler,
|
||||
Handler: &ocgrpc.ServerHandler{},
|
||||
}
|
||||
|
||||
ctx := context.WithValue(context.Background(), mockCtxTag("original"), "true")
|
||||
ctx = h.TagRPC(ctx, &grpcstats.RPCTagInfo{})
|
||||
|
||||
assert.True(t, metricsHandler.called)
|
||||
assert.Equal(t, ctx.Value(mockCtxTag("added")), "true")
|
||||
assert.Equal(t, ctx.Value(mockCtxTag("original")), "true")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue