Skip to content

[public-api] Export metrics with package label instead of service #14145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions components/public-api-server/pkg/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,44 @@ func NewConnectMetrics() *ConnectMetrics {
ServerRequestsStarted: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "connect_server_started_total",
Help: "Counter of server connect (gRPC/HTTP) requests started",
}, []string{"service", "call", "call_type"}),
}, []string{"package", "call", "call_type"}),
ServerRequestsHandled: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "connect_server_handled_seconds",
Help: "Histogram of server connect (gRPC/HTTP) requests completed",
}, []string{"service", "call", "call_type", "code"}),
}, []string{"package", "call", "call_type", "code"}),

ClientRequestsStarted: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "connect_client_started_total",
Help: "Counter of client connect (gRPC/HTTP) requests started",
}, []string{"service", "call", "call_type"}),
}, []string{"package", "call", "call_type"}),
ClientRequestsHandled: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "connect_client_handled_seconds",
Help: "Histogram of client connect (gRPC/HTTP) requests completed",
}, []string{"service", "call", "call_type", "code"}),
}, []string{"package", "call", "call_type", "code"}),
}
}

func NewMetricsInterceptor(metrics *ConnectMetrics) connect.UnaryInterceptorFunc {
interceptor := func(next connect.UnaryFunc) connect.UnaryFunc {
return connect.UnaryFunc(func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
now := time.Now()
service, call := splitServiceCall(req.Spec().Procedure)
callPackage, callName := splitServiceCall(req.Spec().Procedure)
callType := streamType(req.Spec().StreamType)
isClient := req.Spec().IsClient

if isClient {
metrics.ClientRequestsStarted.WithLabelValues(service, call, callType)
metrics.ClientRequestsStarted.WithLabelValues(callPackage, callName, callType)
} else {
metrics.ServerRequestsStarted.WithLabelValues(service, call, callType)
metrics.ServerRequestsStarted.WithLabelValues(callPackage, callName, callType)
}

resp, err := next(ctx, req)

code := codeOf(err)
if isClient {
metrics.ClientRequestsHandled.WithLabelValues(service, call, callType, code).Observe(time.Since(now).Seconds())
metrics.ClientRequestsHandled.WithLabelValues(callPackage, callName, callType, code).Observe(time.Since(now).Seconds())
} else {
metrics.ServerRequestsHandled.WithLabelValues(service, call, callType, code).Observe(time.Since(now).Seconds())
metrics.ServerRequestsHandled.WithLabelValues(callPackage, callName, callType, code).Observe(time.Since(now).Seconds())
}

return resp, err
Expand Down