Skip to content

Commit 1f8e297

Browse files
authored
Update gRPC metrics to match v2 and spec (#572)
1 parent d09526d commit 1f8e297

File tree

6 files changed

+11
-3
lines changed

6 files changed

+11
-3
lines changed

grpcbp/client_middlewares.go

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func PrometheusUnaryClientInterceptor(serverSlug string) grpc.UnaryClientInterce
142142
activeRequestLabels := prometheus.Labels{
143143
serviceLabel: serviceName,
144144
methodLabel: method,
145+
typeLabel: unary,
145146
clientNameLabel: serverSlug,
146147
}
147148
clientActiveRequests.With(activeRequestLabels).Inc()

grpcbp/prometheus.go

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var (
5555
serverActiveRequestsLabels = []string{
5656
serviceLabel,
5757
methodLabel,
58+
typeLabel,
5859
}
5960

6061
serverActiveRequests = promauto.With(prometheusbpint.GlobalRegistry).NewGaugeVec(prometheus.GaugeOpts{
@@ -95,6 +96,7 @@ var (
9596
clientActiveRequestsLabels = []string{
9697
serviceLabel,
9798
methodLabel,
99+
typeLabel,
98100
clientNameLabel,
99101
}
100102

grpcbp/server_middlewares.go

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"google.golang.org/grpc/status"
1111

1212
"github.com/prometheus/client_golang/prometheus"
13+
1314
"github.com/reddit/baseplate.go/ecinterface"
1415
"github.com/reddit/baseplate.go/log"
1516
"github.com/reddit/baseplate.go/prometheusbp"
@@ -174,6 +175,7 @@ func InjectPrometheusUnaryServerInterceptor() grpc.UnaryServerInterceptor {
174175

175176
activeRequestLabels := prometheus.Labels{
176177
serviceLabel: serviceName,
178+
typeLabel: unary,
177179
methodLabel: method,
178180
}
179181
serverActiveRequests.With(activeRequestLabels).Inc()

grpcbp/server_middlewares_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ func TestInjectPrometheusUnaryServerClientInterceptor(t *testing.T) {
254254

255255
serverActiveRequestLabels := prometheus.Labels{
256256
serviceLabel: serviceName,
257+
typeLabel: unary,
257258
methodLabel: tt.method,
258259
}
259260

@@ -277,6 +278,7 @@ func TestInjectPrometheusUnaryServerClientInterceptor(t *testing.T) {
277278
clientActiveRequestLabels := prometheus.Labels{
278279
serviceLabel: serviceName,
279280
methodLabel: tt.method,
281+
typeLabel: unary,
280282
clientNameLabel: serverSlug,
281283
}
282284

internal/prometheusbpint/spectest/spec.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ func thriftSpecificLabels(name string) []string {
216216
// - "service"
217217
// - "method"
218218
func grpcSpecificLabels(name string) []string {
219-
labelSuffixes := []string{"service", "method"}
219+
labelSuffixes := []string{"service", "method", "type"}
220220
switch {
221221
case strings.HasSuffix(name, "_latency_seconds"):
222-
labelSuffixes = append(labelSuffixes, "type", "success")
222+
labelSuffixes = append(labelSuffixes, "success")
223223
case strings.HasSuffix(name, "_requests_total"):
224-
labelSuffixes = append(labelSuffixes, "type", "success", "code")
224+
labelSuffixes = append(labelSuffixes, "success", "code")
225225
case strings.HasSuffix(name, "_active_requests"):
226226
// no op
227227
default:

internal/prometheusbpint/spectest/spec_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ func TestBuildLabelsGPRC(t *testing.T) {
418418
want: map[string]struct{}{
419419
"grpc_method": {},
420420
"grpc_service": {},
421+
"grpc_type": {},
421422
},
422423
},
423424
{

0 commit comments

Comments
 (0)