Align origin/main with upstream/main (GitHub). The two branches diverged due to pre-rebase vs post-rebase merge commits for the k8s-amd64-dockerfiles feature. Includes: multi-stage Go compilation Dockerfiles, pan-bolt inventory features, CRM relations, Excel import tooling, proto/gRPC updates, migration scripts, and tools/ directory. Excludes deploy/bin/ pre-compiled binaries (arm64, not needed for amd64 K3s cluster; builds use multi-stage Dockerfiles now).
33 lines
709 B
Go
33 lines
709 B
Go
package metrics
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func UnaryServerInterceptor() grpc.UnaryServerInterceptor {
|
|
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
|
|
start := time.Now()
|
|
resp, err := handler(ctx, req)
|
|
elapsed := time.Since(start).Seconds()
|
|
|
|
code := "OK"
|
|
if err != nil {
|
|
if st, ok := status.FromError(err); ok {
|
|
code = strconv.Itoa(int(st.Code()))
|
|
} else {
|
|
code = "Unknown"
|
|
}
|
|
}
|
|
|
|
RPCDurationSeconds.WithLabelValues(info.FullMethod).Observe(elapsed)
|
|
RPCRequestsTotal.WithLabelValues(info.FullMethod, code).Inc()
|
|
|
|
return resp, err
|
|
}
|
|
}
|