Skip to content
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

Update gRPC metrics to match v2 and spec #572

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions grpcbp/client_middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func PrometheusUnaryClientInterceptor(serverSlug string) grpc.UnaryClientInterce
activeRequestLabels := prometheus.Labels{
serviceLabel: serviceName,
methodLabel: method,
typeLabel: unary,
clientNameLabel: serverSlug,
}
clientActiveRequests.With(activeRequestLabels).Inc()
Expand Down
2 changes: 2 additions & 0 deletions grpcbp/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
serverActiveRequestsLabels = []string{
serviceLabel,
methodLabel,
typeLabel,
Copy link
Member

@mterwill mterwill Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I don't actually see the type label in the spec for grpc_server_active_requests and grpc_client_active_requests, we should add it? (This does appear to match v2 though)

Just saw your other PR.

}

serverActiveRequests = promauto.With(prometheusbpint.GlobalRegistry).NewGaugeVec(prometheus.GaugeOpts{
Expand Down Expand Up @@ -95,6 +96,7 @@ var (
clientActiveRequestsLabels = []string{
serviceLabel,
methodLabel,
typeLabel,
clientNameLabel,
}

Expand Down
2 changes: 2 additions & 0 deletions grpcbp/server_middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"google.golang.org/grpc/status"

"github.com/prometheus/client_golang/prometheus"

"github.com/reddit/baseplate.go/ecinterface"
"github.com/reddit/baseplate.go/log"
"github.com/reddit/baseplate.go/prometheusbp"
Expand Down Expand Up @@ -174,6 +175,7 @@ func InjectPrometheusUnaryServerInterceptor() grpc.UnaryServerInterceptor {

activeRequestLabels := prometheus.Labels{
serviceLabel: serviceName,
typeLabel: unary,
methodLabel: method,
}
serverActiveRequests.With(activeRequestLabels).Inc()
Expand Down
2 changes: 2 additions & 0 deletions grpcbp/server_middlewares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ func TestInjectPrometheusUnaryServerClientInterceptor(t *testing.T) {

serverActiveRequestLabels := prometheus.Labels{
serviceLabel: serviceName,
typeLabel: unary,
methodLabel: tt.method,
}

Expand All @@ -277,6 +278,7 @@ func TestInjectPrometheusUnaryServerClientInterceptor(t *testing.T) {
clientActiveRequestLabels := prometheus.Labels{
serviceLabel: serviceName,
methodLabel: tt.method,
typeLabel: unary,
clientNameLabel: serverSlug,
}

Expand Down
6 changes: 3 additions & 3 deletions internal/prometheusbpint/spectest/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ func thriftSpecificLabels(name string) []string {
// - "service"
// - "method"
func grpcSpecificLabels(name string) []string {
labelSuffixes := []string{"service", "method"}
labelSuffixes := []string{"service", "method", "type"}
switch {
case strings.HasSuffix(name, "_latency_seconds"):
labelSuffixes = append(labelSuffixes, "type", "success")
labelSuffixes = append(labelSuffixes, "success")
case strings.HasSuffix(name, "_requests_total"):
labelSuffixes = append(labelSuffixes, "type", "success", "code")
labelSuffixes = append(labelSuffixes, "success", "code")
case strings.HasSuffix(name, "_active_requests"):
// no op
default:
Expand Down
1 change: 1 addition & 0 deletions internal/prometheusbpint/spectest/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ func TestBuildLabelsGPRC(t *testing.T) {
want: map[string]struct{}{
"grpc_method": {},
"grpc_service": {},
"grpc_type": {},
},
},
{
Expand Down