mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-04 03:42:49 +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
39
internal/telemetry/grpc.go
Normal file
39
internal/telemetry/grpc.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package telemetry
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opencensus.io/plugin/ocgrpc"
|
||||
grpcstats "google.golang.org/grpc/stats"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/telemetry/metrics"
|
||||
)
|
||||
|
||||
type tagRPCHandler interface {
|
||||
TagRPC(context.Context, *grpcstats.RPCTagInfo) context.Context
|
||||
}
|
||||
|
||||
// GRPCServerStatsHandler provides a grpc stats.Handler for metrics and tracing for a pomerium service
|
||||
type GRPCServerStatsHandler struct {
|
||||
service string
|
||||
metricsHandler tagRPCHandler
|
||||
grpcstats.Handler
|
||||
}
|
||||
|
||||
// TagRPC implements grpc.stats.Handler and adds metrics and tracing metadata to the context of a given RPC
|
||||
func (h *GRPCServerStatsHandler) TagRPC(ctx context.Context, tagInfo *grpcstats.RPCTagInfo) context.Context {
|
||||
|
||||
metricCtx := h.metricsHandler.TagRPC(ctx, tagInfo)
|
||||
handledCtx := h.Handler.TagRPC(metricCtx, tagInfo)
|
||||
|
||||
return handledCtx
|
||||
}
|
||||
|
||||
// NewGRPCServerStatsHandler creates a new GRPCServerStatsHandler for a pomerium service
|
||||
func NewGRPCServerStatsHandler(service string) grpcstats.Handler {
|
||||
return &GRPCServerStatsHandler{
|
||||
service: service,
|
||||
Handler: &ocgrpc.ServerHandler{},
|
||||
metricsHandler: metrics.NewGRPCServerMetricsHandler(service),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue