Skip to content

Commit 89c052d

Browse files
committed
fix: downgrade related package to make it build again
1 parent a193c46 commit 89c052d

File tree

3 files changed

+48
-33
lines changed

3 files changed

+48
-33
lines changed

cloudmonitoring/metricmiddleware.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"go.opentelemetry.io/otel/attribute"
1010
"go.opentelemetry.io/otel/metric/global"
1111
"go.opentelemetry.io/otel/metric/instrument"
12+
"go.opentelemetry.io/otel/metric/instrument/syncint64"
1213
"go.opentelemetry.io/otel/metric/unit"
1314
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
1415
"google.golang.org/grpc"
@@ -20,6 +21,7 @@ import (
2021
// See:
2122
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics
2223
const (
24+
serverRequestDurationMetricName = "rpc.server.duration"
2325
clientRequestDurationMetricName = "rpc.client.duration"
2426

2527
// there is no rpc_count equivalent int OTEL semantic conventions yet.
@@ -30,23 +32,31 @@ const (
3032
func NewMetricMiddleware() (MetricMiddleware, error) {
3133
meter := global.MeterProvider().Meter("cloudrunner-go/cloudmonitoring")
3234

33-
serverRequestCount, err := meter.Int64Counter(
35+
serverRequestCount, err := meter.SyncInt64().Counter(
3436
serverRequestCountMetricName,
3537
instrument.WithUnit(unit.Dimensionless),
3638
instrument.WithDescription("Count of RPCs received by a gRPC server."),
3739
)
3840
if err != nil {
3941
return MetricMiddleware{}, fmt.Errorf("create server request count counter: %w", err)
4042
}
41-
clientRequestCount, err := meter.Int64Counter(
43+
serverRequestDuration, err := meter.SyncInt64().Histogram(
44+
serverRequestDurationMetricName,
45+
instrument.WithUnit(unit.Milliseconds),
46+
instrument.WithDescription("Duration of RPCs received by a gRPC server."),
47+
)
48+
if err != nil {
49+
return MetricMiddleware{}, fmt.Errorf("create server request duration histogram: %w", err)
50+
}
51+
clientRequestCount, err := meter.SyncInt64().Counter(
4252
clientRequestCountMetricName,
4353
instrument.WithUnit(unit.Dimensionless),
4454
instrument.WithDescription("Count of RPCs sent by a gRPC client."),
4555
)
4656
if err != nil {
4757
return MetricMiddleware{}, fmt.Errorf("create client request count counter: %w", err)
4858
}
49-
clientRequestDuration, err := meter.Int64Histogram(
59+
clientRequestDuration, err := meter.SyncInt64().Histogram(
5060
clientRequestDurationMetricName,
5161
instrument.WithUnit(unit.Milliseconds),
5262
instrument.WithDescription("Duration of RPCs sent by a gRPC client."),
@@ -56,15 +66,17 @@ func NewMetricMiddleware() (MetricMiddleware, error) {
5666
}
5767
return MetricMiddleware{
5868
serverRequestCount: serverRequestCount,
69+
serverRequestDuration: serverRequestDuration,
5970
clientRequestCount: clientRequestCount,
6071
clientRequestDuration: clientRequestDuration,
6172
}, nil
6273
}
6374

6475
type MetricMiddleware struct {
65-
serverRequestCount instrument.Int64Counter
66-
clientRequestCount instrument.Int64Counter
67-
clientRequestDuration instrument.Int64Histogram
76+
serverRequestCount syncint64.Counter
77+
serverRequestDuration syncint64.Histogram
78+
clientRequestCount syncint64.Counter
79+
clientRequestDuration syncint64.Histogram
6880
}
6981

7082
// GRPCUnaryServerInterceptor implements grpc.UnaryServerInterceptor and
@@ -76,11 +88,14 @@ func (m *MetricMiddleware) GRPCUnaryServerInterceptor(
7688
info *grpc.UnaryServerInfo,
7789
handler grpc.UnaryHandler,
7890
) (resp interface{}, err error) {
91+
startTime := time.Now()
7992
response, err := handler(ctx, request)
93+
duration := time.Since(startTime)
8094
code := status.Code(err)
8195

8296
attrs := rpcAttrs(info.FullMethod, code)
8397
m.serverRequestCount.Add(ctx, 1, attrs...)
98+
m.serverRequestDuration.Record(ctx, duration.Milliseconds(), attrs...)
8499
return response, err
85100
}
86101

go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ require (
1313
github.com/soheilhy/cmux v0.1.5
1414
go.einride.tech/protobuf-sensitive v0.3.0
1515
go.opencensus.io v0.24.0
16-
go.opentelemetry.io/contrib/detectors/gcp v1.14.0
17-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.38.0
18-
go.opentelemetry.io/contrib/instrumentation/host v0.38.0
19-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0
20-
go.opentelemetry.io/contrib/instrumentation/runtime v0.38.0
16+
go.opentelemetry.io/contrib/detectors/gcp v1.11.1
17+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.4
18+
go.opentelemetry.io/contrib/instrumentation/host v0.36.4
19+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4
20+
go.opentelemetry.io/contrib/instrumentation/runtime v0.36.4
2121
go.opentelemetry.io/otel v1.13.0
22-
go.opentelemetry.io/otel/bridge/opencensus v0.35.0
23-
go.opentelemetry.io/otel/metric v0.36.0
24-
go.opentelemetry.io/otel/sdk v1.13.0
25-
go.opentelemetry.io/otel/sdk/metric v0.35.0
22+
go.opentelemetry.io/otel/bridge/opencensus v0.33.0
23+
go.opentelemetry.io/otel/metric v0.33.0
24+
go.opentelemetry.io/otel/sdk v1.11.1
25+
go.opentelemetry.io/otel/sdk/metric v0.33.0
2626
go.uber.org/zap v1.24.0
2727
golang.org/x/oauth2 v0.4.0
2828
golang.org/x/sync v0.1.0

go.sum

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,26 @@ go.einride.tech/protobuf-sensitive v0.3.0 h1:CRIEF833SXINoCaZp7V8GqB+65bLgNGzVH+
129129
go.einride.tech/protobuf-sensitive v0.3.0/go.mod h1:nwu0o4M/iWVo24hAn+3PDs6Ja2Mw3g8oDgyy7Rzw8k0=
130130
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
131131
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
132-
go.opentelemetry.io/contrib/detectors/gcp v1.14.0 h1:o2NurqCUGl7GaHH5vQjzYnjijlX2zrKneN7qsgia138=
133-
go.opentelemetry.io/contrib/detectors/gcp v1.14.0/go.mod h1:UJf0kFmOn9CIuLs1SgvqAMF8Pwna1cLHOKHqqTGSlK4=
134-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.38.0 h1:g/BAN5o90Pr6D8xMRezjzGOHBpc15U+4oE53nZLiae4=
135-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.38.0/go.mod h1:+F41JBSkye7aYJELRvIMF0Z66reIwIOL0St75ZVwSJs=
136-
go.opentelemetry.io/contrib/instrumentation/host v0.38.0 h1:UAL4VwsGD8I87v0PUnlNvNoDK9biur6BavY6hZyHRtE=
137-
go.opentelemetry.io/contrib/instrumentation/host v0.38.0/go.mod h1:tVaeBxRJPU0PrChJnlb4kWolV8jgzNLonwFoa1j8JAM=
138-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0 h1:vFEBG7SieZJzvnRWQ81jxpuEqe6J8Ex+hgc9CqOTzHc=
139-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0/go.mod h1:9rgTcOKdIhDOC0IcAu8a+R+FChqSUBihKpM1lVNi6T0=
140-
go.opentelemetry.io/contrib/instrumentation/runtime v0.38.0 h1:uTd4XAyfZ51V5w+ZOCFPiNgzVN2Yp3ibNYKvZ7hWViM=
141-
go.opentelemetry.io/contrib/instrumentation/runtime v0.38.0/go.mod h1:LYI0Tb+eGfyp/IRpjSSERc3rv/3FT/IjqUeNNTZdJRQ=
132+
go.opentelemetry.io/contrib/detectors/gcp v1.11.1 h1:y6EXzhjnuYY6EV12OYW3eITeZ+lHtxsXCR3KpCJCfUY=
133+
go.opentelemetry.io/contrib/detectors/gcp v1.11.1/go.mod h1:AuTCkYDcf6pXtddWv8aWdz+ohbDg4RsjVYUHGMWM4fE=
134+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.4 h1:PRXhsszxTt5bbPriTjmaweWUsAnJYeWBhUMLRetUgBU=
135+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.4/go.mod h1:05eWWy6ZWzmpeImD3UowLTB3VjDMU1yxQ+ENuVWDM3c=
136+
go.opentelemetry.io/contrib/instrumentation/host v0.36.4 h1:2D0q/69KewnkCkOI9I9uXgi1XQXvwQIfMebMcPft0no=
137+
go.opentelemetry.io/contrib/instrumentation/host v0.36.4/go.mod h1:IQdse+GFHec/g2M4wtj6cE4uA5PJGQjjXP/602LjHBQ=
138+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 h1:aUEBEdCa6iamGzg6fuYxDA8ThxvOG240mAvWDU+XLio=
139+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4/go.mod h1:l2MdsbKTocpPS5nQZscqTR9jd8u96VYZdcpF8Sye7mA=
140+
go.opentelemetry.io/contrib/instrumentation/runtime v0.36.4 h1:7AY5NdRzyU5s1ek3E4VK3FBnPtQ6La1i7sIn9hNgjsk=
141+
go.opentelemetry.io/contrib/instrumentation/runtime v0.36.4/go.mod h1:yFSLOnffweT7Es+IzY1DF5KP0xa2Wl15SJfKqAyDXq8=
142142
go.opentelemetry.io/otel v1.13.0 h1:1ZAKnNQKwBBxFtww/GwxNUyTf0AxkZzrukO8MeXqe4Y=
143143
go.opentelemetry.io/otel v1.13.0/go.mod h1:FH3RtdZCzRkJYFTCsAKDy9l/XYjMdNv6QrkFFB8DvVg=
144-
go.opentelemetry.io/otel/bridge/opencensus v0.35.0 h1:gJcAy/4dZwYXCIRoa+ejf4PaFXj7ZxryI4cT5gMe7FE=
145-
go.opentelemetry.io/otel/bridge/opencensus v0.35.0/go.mod h1:0leuyf/I8Dh9vGTBwxDu5MriDfowE9hczSiQ6SoM/JQ=
146-
go.opentelemetry.io/otel/metric v0.36.0 h1:t0lgGI+L68QWt3QtOIlqM9gXoxqxWLhZ3R/e5oOAY0Q=
147-
go.opentelemetry.io/otel/metric v0.36.0/go.mod h1:wKVw57sd2HdSZAzyfOM9gTqqE8v7CbqWsYL6AyrH9qk=
148-
go.opentelemetry.io/otel/sdk v1.13.0 h1:BHib5g8MvdqS65yo2vV1s6Le42Hm6rrw08qU6yz5JaM=
149-
go.opentelemetry.io/otel/sdk v1.13.0/go.mod h1:YLKPx5+6Vx/o1TCUYYs+bpymtkmazOMT6zoRrC7AQ7I=
150-
go.opentelemetry.io/otel/sdk/metric v0.35.0 h1:gryV4W5GzpOhKK48/lZb8ldyWIs3DRugSVlQZmCwELA=
151-
go.opentelemetry.io/otel/sdk/metric v0.35.0/go.mod h1:eDyp1GxSiwV98kr7w4pzrszQh/eze9MqBqPd2bCPmyE=
144+
go.opentelemetry.io/otel/bridge/opencensus v0.33.0 h1:DnSFYr/VxUVwkHL0UoaMcxx74Jugb1HO0B08cYBmi0c=
145+
go.opentelemetry.io/otel/bridge/opencensus v0.33.0/go.mod h1:gylOY4P2e7kPYc6T9M8XfQ5+RK4+evGorTOOy+gO4Nc=
146+
go.opentelemetry.io/otel/metric v0.33.0 h1:xQAyl7uGEYvrLAiV/09iTJlp1pZnQ9Wl793qbVvED1E=
147+
go.opentelemetry.io/otel/metric v0.33.0/go.mod h1:QlTYc+EnYNq/M2mNk1qDDMRLpqCOj2f/r5c7Fd5FYaI=
148+
go.opentelemetry.io/otel/sdk v1.11.1 h1:F7KmQgoHljhUuJyA+9BiU+EkJfyX5nVVF4wyzWZpKxs=
149+
go.opentelemetry.io/otel/sdk v1.11.1/go.mod h1:/l3FE4SupHJ12TduVjUkZtlfFqDCQJlOlithYrdktys=
150+
go.opentelemetry.io/otel/sdk/metric v0.33.0 h1:oTqyWfksgKoJmbrs2q7O7ahkJzt+Ipekihf8vhpa9qo=
151+
go.opentelemetry.io/otel/sdk/metric v0.33.0/go.mod h1:xdypMeA21JBOvjjzDUtD0kzIcHO/SPez+a8HOzJPGp0=
152152
go.opentelemetry.io/otel/trace v1.13.0 h1:CBgRZ6ntv+Amuj1jDsMhZtlAPT6gbyIRdaIzFhfBSdY=
153153
go.opentelemetry.io/otel/trace v1.13.0/go.mod h1:muCvmmO9KKpvuXSf3KKAXXB2ygNYHQ+ZfI5X08d3tds=
154154
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=

0 commit comments

Comments
 (0)