MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Prometheus

Function Prometheus

app/controlplane/internal/usercontext/wrappers.go:32–55  ·  view source on GitHub ↗

This package contains a set of wrappers that take grpc.UnaryInterceptors and translate them into Kratos middlewares. The reason for having these kind of wrappers is so we can sort them in the context of the rest of middlewares. Otherwise, plain grpc interceptors will be added after the chain of midd

()

Source from the content-addressed store, hash-verified

30// Otherwise, plain grpc interceptors will be added after the chain of middlewares
31// https://github.com/go-kratos/kratos/blob/f8b97f675b32dfad02edae12d83053c720720b5b/transport/grpc/server.go#L166
32func Prometheus() middleware.Middleware {
33 var interceptor = grpc_prometheus.UnaryServerInterceptor
34 return func(handler middleware.Handler) middleware.Handler {
35 return func(ctx context.Context, req interface{}) (interface{}, error) {
36 // Extract gRPC metadata from the context
37 info, ok := transport.FromServerContext(ctx)
38 if !ok {
39 // If gRPC metadata is not available, fallback to default handler
40 return handler(ctx, req)
41 }
42
43 // Wrap the handler into a gRPC UnaryHandler
44 grpcHandler := func(ctx context.Context, req interface{}) (interface{}, error) {
45 return handler(ctx, req)
46 }
47
48 // Call the interceptor
49 return interceptor(ctx, req, &grpc.UnaryServerInfo{
50 Server: nil, // Kratos doesn't provide the server instance directly
51 FullMethod: info.Operation(),
52 }, grpcHandler)
53 }
54 }
55}

Callers 1

craftMiddlewareFunction · 0.92

Calls 1

OperationMethod · 0.45

Tested by

no test coverage detected