mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-27 16:39:38 -05:00
4842d29aff
* Deploy activation service on cluster init * Use base image with CA certificates for activation service * Improve KMS server Signed-off-by: Daniel Weiße <dw@edgeless.systems>
32 lines
911 B
Go
32 lines
911 B
Go
// grpc_klog provides a logging interceptor for the klog logger.
|
|
package grpc_klog
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/peer"
|
|
"k8s.io/klog/v2"
|
|
)
|
|
|
|
// LogGRPC writes a log with the name of every gRPC call or error it receives.
|
|
// Request parameters or responses are NOT logged.
|
|
func LogGRPC(level klog.Level) func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
|
|
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
|
|
// log the requests method name
|
|
var addr string
|
|
peer, ok := peer.FromContext(ctx)
|
|
if ok {
|
|
addr = peer.Addr.String()
|
|
}
|
|
klog.V(level).Infof("GRPC call from peer: %q: %s", addr, info.FullMethod)
|
|
|
|
// log errors, if any
|
|
resp, err := handler(ctx, req)
|
|
if err != nil {
|
|
klog.Errorf("GRPC error: %v", err)
|
|
}
|
|
return resp, err
|
|
}
|
|
}
|