Skip to content

Commit

Permalink
fix: downgrade related package to make it build again
Browse files Browse the repository at this point in the history
  • Loading branch information
liufuyang committed Feb 15, 2023
1 parent a193c46 commit 89c052d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 33 deletions.
27 changes: 21 additions & 6 deletions cloudmonitoring/metricmiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.opentelemetry.io/otel/metric/unit"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
"google.golang.org/grpc"
Expand All @@ -20,6 +21,7 @@ import (
// See:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics
const (
serverRequestDurationMetricName = "rpc.server.duration"
clientRequestDurationMetricName = "rpc.client.duration"

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

serverRequestCount, err := meter.Int64Counter(
serverRequestCount, err := meter.SyncInt64().Counter(
serverRequestCountMetricName,
instrument.WithUnit(unit.Dimensionless),
instrument.WithDescription("Count of RPCs received by a gRPC server."),
)
if err != nil {
return MetricMiddleware{}, fmt.Errorf("create server request count counter: %w", err)
}
clientRequestCount, err := meter.Int64Counter(
serverRequestDuration, err := meter.SyncInt64().Histogram(
serverRequestDurationMetricName,
instrument.WithUnit(unit.Milliseconds),
instrument.WithDescription("Duration of RPCs received by a gRPC server."),
)
if err != nil {
return MetricMiddleware{}, fmt.Errorf("create server request duration histogram: %w", err)
}
clientRequestCount, err := meter.SyncInt64().Counter(
clientRequestCountMetricName,
instrument.WithUnit(unit.Dimensionless),
instrument.WithDescription("Count of RPCs sent by a gRPC client."),
)
if err != nil {
return MetricMiddleware{}, fmt.Errorf("create client request count counter: %w", err)
}
clientRequestDuration, err := meter.Int64Histogram(
clientRequestDuration, err := meter.SyncInt64().Histogram(
clientRequestDurationMetricName,
instrument.WithUnit(unit.Milliseconds),
instrument.WithDescription("Duration of RPCs sent by a gRPC client."),
Expand All @@ -56,15 +66,17 @@ func NewMetricMiddleware() (MetricMiddleware, error) {
}
return MetricMiddleware{
serverRequestCount: serverRequestCount,
serverRequestDuration: serverRequestDuration,
clientRequestCount: clientRequestCount,
clientRequestDuration: clientRequestDuration,
}, nil
}

type MetricMiddleware struct {
serverRequestCount instrument.Int64Counter
clientRequestCount instrument.Int64Counter
clientRequestDuration instrument.Int64Histogram
serverRequestCount syncint64.Counter
serverRequestDuration syncint64.Histogram
clientRequestCount syncint64.Counter
clientRequestDuration syncint64.Histogram
}

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

attrs := rpcAttrs(info.FullMethod, code)
m.serverRequestCount.Add(ctx, 1, attrs...)
m.serverRequestDuration.Record(ctx, duration.Milliseconds(), attrs...)
return response, err
}

Expand Down
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ require (
github.com/soheilhy/cmux v0.1.5
go.einride.tech/protobuf-sensitive v0.3.0
go.opencensus.io v0.24.0
go.opentelemetry.io/contrib/detectors/gcp v1.14.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.38.0
go.opentelemetry.io/contrib/instrumentation/host v0.38.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.38.0
go.opentelemetry.io/contrib/detectors/gcp v1.11.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.4
go.opentelemetry.io/contrib/instrumentation/host v0.36.4
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4
go.opentelemetry.io/contrib/instrumentation/runtime v0.36.4
go.opentelemetry.io/otel v1.13.0
go.opentelemetry.io/otel/bridge/opencensus v0.35.0
go.opentelemetry.io/otel/metric v0.36.0
go.opentelemetry.io/otel/sdk v1.13.0
go.opentelemetry.io/otel/sdk/metric v0.35.0
go.opentelemetry.io/otel/bridge/opencensus v0.33.0
go.opentelemetry.io/otel/metric v0.33.0
go.opentelemetry.io/otel/sdk v1.11.1
go.opentelemetry.io/otel/sdk/metric v0.33.0
go.uber.org/zap v1.24.0
golang.org/x/oauth2 v0.4.0
golang.org/x/sync v0.1.0
Expand Down
36 changes: 18 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,26 @@ go.einride.tech/protobuf-sensitive v0.3.0 h1:CRIEF833SXINoCaZp7V8GqB+65bLgNGzVH+
go.einride.tech/protobuf-sensitive v0.3.0/go.mod h1:nwu0o4M/iWVo24hAn+3PDs6Ja2Mw3g8oDgyy7Rzw8k0=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/detectors/gcp v1.14.0 h1:o2NurqCUGl7GaHH5vQjzYnjijlX2zrKneN7qsgia138=
go.opentelemetry.io/contrib/detectors/gcp v1.14.0/go.mod h1:UJf0kFmOn9CIuLs1SgvqAMF8Pwna1cLHOKHqqTGSlK4=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.38.0 h1:g/BAN5o90Pr6D8xMRezjzGOHBpc15U+4oE53nZLiae4=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.38.0/go.mod h1:+F41JBSkye7aYJELRvIMF0Z66reIwIOL0St75ZVwSJs=
go.opentelemetry.io/contrib/instrumentation/host v0.38.0 h1:UAL4VwsGD8I87v0PUnlNvNoDK9biur6BavY6hZyHRtE=
go.opentelemetry.io/contrib/instrumentation/host v0.38.0/go.mod h1:tVaeBxRJPU0PrChJnlb4kWolV8jgzNLonwFoa1j8JAM=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0 h1:vFEBG7SieZJzvnRWQ81jxpuEqe6J8Ex+hgc9CqOTzHc=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0/go.mod h1:9rgTcOKdIhDOC0IcAu8a+R+FChqSUBihKpM1lVNi6T0=
go.opentelemetry.io/contrib/instrumentation/runtime v0.38.0 h1:uTd4XAyfZ51V5w+ZOCFPiNgzVN2Yp3ibNYKvZ7hWViM=
go.opentelemetry.io/contrib/instrumentation/runtime v0.38.0/go.mod h1:LYI0Tb+eGfyp/IRpjSSERc3rv/3FT/IjqUeNNTZdJRQ=
go.opentelemetry.io/contrib/detectors/gcp v1.11.1 h1:y6EXzhjnuYY6EV12OYW3eITeZ+lHtxsXCR3KpCJCfUY=
go.opentelemetry.io/contrib/detectors/gcp v1.11.1/go.mod h1:AuTCkYDcf6pXtddWv8aWdz+ohbDg4RsjVYUHGMWM4fE=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.4 h1:PRXhsszxTt5bbPriTjmaweWUsAnJYeWBhUMLRetUgBU=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.4/go.mod h1:05eWWy6ZWzmpeImD3UowLTB3VjDMU1yxQ+ENuVWDM3c=
go.opentelemetry.io/contrib/instrumentation/host v0.36.4 h1:2D0q/69KewnkCkOI9I9uXgi1XQXvwQIfMebMcPft0no=
go.opentelemetry.io/contrib/instrumentation/host v0.36.4/go.mod h1:IQdse+GFHec/g2M4wtj6cE4uA5PJGQjjXP/602LjHBQ=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 h1:aUEBEdCa6iamGzg6fuYxDA8ThxvOG240mAvWDU+XLio=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4/go.mod h1:l2MdsbKTocpPS5nQZscqTR9jd8u96VYZdcpF8Sye7mA=
go.opentelemetry.io/contrib/instrumentation/runtime v0.36.4 h1:7AY5NdRzyU5s1ek3E4VK3FBnPtQ6La1i7sIn9hNgjsk=
go.opentelemetry.io/contrib/instrumentation/runtime v0.36.4/go.mod h1:yFSLOnffweT7Es+IzY1DF5KP0xa2Wl15SJfKqAyDXq8=
go.opentelemetry.io/otel v1.13.0 h1:1ZAKnNQKwBBxFtww/GwxNUyTf0AxkZzrukO8MeXqe4Y=
go.opentelemetry.io/otel v1.13.0/go.mod h1:FH3RtdZCzRkJYFTCsAKDy9l/XYjMdNv6QrkFFB8DvVg=
go.opentelemetry.io/otel/bridge/opencensus v0.35.0 h1:gJcAy/4dZwYXCIRoa+ejf4PaFXj7ZxryI4cT5gMe7FE=
go.opentelemetry.io/otel/bridge/opencensus v0.35.0/go.mod h1:0leuyf/I8Dh9vGTBwxDu5MriDfowE9hczSiQ6SoM/JQ=
go.opentelemetry.io/otel/metric v0.36.0 h1:t0lgGI+L68QWt3QtOIlqM9gXoxqxWLhZ3R/e5oOAY0Q=
go.opentelemetry.io/otel/metric v0.36.0/go.mod h1:wKVw57sd2HdSZAzyfOM9gTqqE8v7CbqWsYL6AyrH9qk=
go.opentelemetry.io/otel/sdk v1.13.0 h1:BHib5g8MvdqS65yo2vV1s6Le42Hm6rrw08qU6yz5JaM=
go.opentelemetry.io/otel/sdk v1.13.0/go.mod h1:YLKPx5+6Vx/o1TCUYYs+bpymtkmazOMT6zoRrC7AQ7I=
go.opentelemetry.io/otel/sdk/metric v0.35.0 h1:gryV4W5GzpOhKK48/lZb8ldyWIs3DRugSVlQZmCwELA=
go.opentelemetry.io/otel/sdk/metric v0.35.0/go.mod h1:eDyp1GxSiwV98kr7w4pzrszQh/eze9MqBqPd2bCPmyE=
go.opentelemetry.io/otel/bridge/opencensus v0.33.0 h1:DnSFYr/VxUVwkHL0UoaMcxx74Jugb1HO0B08cYBmi0c=
go.opentelemetry.io/otel/bridge/opencensus v0.33.0/go.mod h1:gylOY4P2e7kPYc6T9M8XfQ5+RK4+evGorTOOy+gO4Nc=
go.opentelemetry.io/otel/metric v0.33.0 h1:xQAyl7uGEYvrLAiV/09iTJlp1pZnQ9Wl793qbVvED1E=
go.opentelemetry.io/otel/metric v0.33.0/go.mod h1:QlTYc+EnYNq/M2mNk1qDDMRLpqCOj2f/r5c7Fd5FYaI=
go.opentelemetry.io/otel/sdk v1.11.1 h1:F7KmQgoHljhUuJyA+9BiU+EkJfyX5nVVF4wyzWZpKxs=
go.opentelemetry.io/otel/sdk v1.11.1/go.mod h1:/l3FE4SupHJ12TduVjUkZtlfFqDCQJlOlithYrdktys=
go.opentelemetry.io/otel/sdk/metric v0.33.0 h1:oTqyWfksgKoJmbrs2q7O7ahkJzt+Ipekihf8vhpa9qo=
go.opentelemetry.io/otel/sdk/metric v0.33.0/go.mod h1:xdypMeA21JBOvjjzDUtD0kzIcHO/SPez+a8HOzJPGp0=
go.opentelemetry.io/otel/trace v1.13.0 h1:CBgRZ6ntv+Amuj1jDsMhZtlAPT6gbyIRdaIzFhfBSdY=
go.opentelemetry.io/otel/trace v1.13.0/go.mod h1:muCvmmO9KKpvuXSf3KKAXXB2ygNYHQ+ZfI5X08d3tds=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
Expand Down

0 comments on commit 89c052d

Please sign in to comment.