Skip to content

Commit 897690f

Browse files
authored
Chore: Replace deprecated prometheus grpc middleware (#961)
* Chore: Replace deprecated prometheus grpc middleware * prometheus grpc middleware v1.0.1 and manually merge require blocks in go.mod * fix grafana comp. check to replace any existing sdk replace in go.mod * check grafana comp. with go 1.22
1 parent 3bbfa89 commit 897690f

File tree

4 files changed

+53
-125
lines changed

4 files changed

+53
-125
lines changed

.github/workflows/check-grafana-compatibility.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
- uses: actions/setup-go@v5
2626
with:
2727
cache: false
28+
go-version: '~1.22'
2829
check-latest: true
29-
go-version-file: 'grafana-plugin-sdk-go/go.mod'
3030

3131
- name: Check if branch exists in Grafana
3232
working-directory: './grafana'
@@ -42,7 +42,7 @@ jobs:
4242
4343
- name: Link sdk
4444
working-directory: './grafana'
45-
run: echo 'replace github.com/grafana/grafana-plugin-sdk-go => ../grafana-plugin-sdk-go' >> go.mod
45+
run: go mod edit -replace github.com/grafana/grafana-plugin-sdk-go=../grafana-plugin-sdk-go
4646

4747
- name: Automatic updates
4848
working-directory: './grafana'

backend/serve.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import (
1111
"syscall"
1212
"time"
1313

14-
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
15-
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
14+
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
1615
"github.com/prometheus/client_golang/prometheus"
1716
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
1817
"go.opentelemetry.io/otel"
@@ -85,7 +84,6 @@ func GRPCServeOpts(opts ServeOpts) grpcplugin.ServeOpts {
8584
// - otel grpc stats handler (see otelgrpc.NewServerHandler)
8685
func grpcServerOptions(serveOpts ServeOpts, customOpts ...grpc.ServerOption) []grpc.ServerOption {
8786
options := defaultGRPCMiddlewares(serveOpts)
88-
options = append(options, grpc.StatsHandler(otelgrpc.NewServerHandler()))
8987
options = append(options, customOpts...)
9088
return options
9189
}
@@ -94,14 +92,15 @@ func defaultGRPCMiddlewares(opts ServeOpts) []grpc.ServerOption {
9492
if opts.GRPCSettings.MaxReceiveMsgSize <= 0 {
9593
opts.GRPCSettings.MaxReceiveMsgSize = defaultServerMaxReceiveMessageSize
9694
}
95+
96+
srvMetrics := grpc_prometheus.NewServerMetrics(grpc_prometheus.WithServerHandlingTimeHistogram())
97+
prometheus.MustRegister(srvMetrics)
98+
9799
grpcMiddlewares := []grpc.ServerOption{
98100
grpc.MaxRecvMsgSize(opts.GRPCSettings.MaxReceiveMsgSize),
99-
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
100-
grpc_prometheus.StreamServerInterceptor,
101-
)),
102-
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
103-
grpc_prometheus.UnaryServerInterceptor,
104-
)),
101+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
102+
grpc.UnaryInterceptor(srvMetrics.UnaryServerInterceptor()),
103+
grpc.StreamInterceptor(srvMetrics.StreamServerInterceptor()),
105104
}
106105
if opts.GRPCSettings.MaxSendMsgSize > 0 {
107106
grpcMiddlewares = append([]grpc.ServerOption{grpc.MaxSendMsgSize(opts.GRPCSettings.MaxSendMsgSize)}, grpcMiddlewares...)
@@ -111,7 +110,6 @@ func defaultGRPCMiddlewares(opts ServeOpts) []grpc.ServerOption {
111110

112111
// Serve starts serving the plugin over gRPC.
113112
func Serve(opts ServeOpts) error {
114-
grpc_prometheus.EnableHandlingTimeHistogram()
115113
pluginOpts := GRPCServeOpts(opts)
116114
pluginOpts.GRPCServer = func(customOptions []grpc.ServerOption) *grpc.Server {
117115
return grpc.NewServer(grpcServerOptions(opts, customOptions...)...)

go.mod

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,25 @@ go 1.21
66
replace github.com/getkin/kin-openapi => github.com/getkin/kin-openapi v0.120.0
77

88
require (
9+
github.com/apache/arrow/go/v15 v15.0.2
910
github.com/cheekybits/genny v1.0.0
10-
github.com/golang/protobuf v1.5.4 // indirect
11+
github.com/chromedp/cdproto v0.0.0-20220208224320-6efb837e6bc2
12+
github.com/elazarl/goproxy v0.0.0-20230731152917-f99041a5c027
13+
github.com/getkin/kin-openapi v0.120.0
1114
github.com/google/go-cmp v0.6.0
12-
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
13-
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
15+
github.com/google/uuid v1.6.0
16+
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
1417
github.com/hashicorp/go-hclog v1.6.3
1518
github.com/hashicorp/go-plugin v1.6.0
16-
github.com/hashicorp/yamux v0.1.1 // indirect
1719
github.com/invopop/jsonschema v0.12.0 // for schema codgen+extraction
1820
github.com/json-iterator/go v1.1.12
1921
github.com/magefile/mage v1.15.0
2022
github.com/mattetti/filebuffer v1.0.1
21-
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
2223
github.com/mitchellh/reflectwalk v1.0.2
2324
github.com/olekukonko/tablewriter v0.0.5
24-
github.com/prometheus/client_golang v1.18.0
25-
github.com/prometheus/common v0.46.0
25+
github.com/prometheus/client_golang v1.19.0
26+
github.com/prometheus/common v0.53.0
2627
github.com/stretchr/testify v1.9.0
27-
golang.org/x/sys v0.18.0
28-
google.golang.org/grpc v1.63.2
29-
google.golang.org/protobuf v1.33.0
30-
gopkg.in/yaml.v3 v3.0.1 // indirect
31-
)
32-
33-
require (
34-
github.com/apache/arrow/go/v15 v15.0.2
35-
github.com/chromedp/cdproto v0.0.0-20220208224320-6efb837e6bc2
36-
github.com/elazarl/goproxy v0.0.0-20230731152917-f99041a5c027
37-
github.com/getkin/kin-openapi v0.120.0
38-
github.com/google/uuid v1.6.0
3928
github.com/unknwon/bra v0.0.0-20200517080246-1e3013ecaff8
4029
github.com/urfave/cli v1.22.14
4130
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0
@@ -48,9 +37,12 @@ require (
4837
go.opentelemetry.io/otel/sdk v1.24.0
4938
go.opentelemetry.io/otel/trace v1.24.0
5039
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
51-
golang.org/x/net v0.23.0
40+
golang.org/x/net v0.24.0
5241
golang.org/x/oauth2 v0.18.0
42+
golang.org/x/sys v0.19.0
5343
golang.org/x/text v0.14.0
44+
google.golang.org/grpc v1.63.2
45+
google.golang.org/protobuf v1.33.0
5446
k8s.io/kube-openapi v0.0.0-20240220201932-37d671a357a5 // @grafana/grafana-app-platform-squad
5547
)
5648

@@ -61,7 +53,7 @@ require (
6153
github.com/beorn7/perks v1.0.1 // indirect
6254
github.com/buger/jsonparser v1.1.1 // indirect
6355
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
64-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
56+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
6557
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
6658
github.com/davecgh/go-spew v1.1.1 // indirect
6759
github.com/elazarl/goproxy/ext v0.0.0-20220115173737-adb46da277ac // indirect
@@ -74,11 +66,14 @@ require (
7466
github.com/go-openapi/swag v0.22.4 // indirect
7567
github.com/goccy/go-json v0.10.2 // indirect
7668
github.com/gogo/protobuf v1.3.2 // indirect
69+
github.com/golang/protobuf v1.5.4 // indirect
7770
github.com/google/flatbuffers v23.5.26+incompatible // indirect
7871
github.com/google/gnostic-models v0.6.8 // indirect
7972
github.com/google/gofuzz v1.1.0 // indirect
8073
github.com/gorilla/mux v1.8.0 // indirect
74+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
8175
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
76+
github.com/hashicorp/yamux v0.1.1 // indirect
8277
github.com/invopop/yaml v0.2.0 // indirect
8378
github.com/josharian/intern v1.0.0 // indirect
8479
github.com/klauspost/compress v1.16.7 // indirect
@@ -87,15 +82,16 @@ require (
8782
github.com/mattn/go-colorable v0.1.13 // indirect
8883
github.com/mattn/go-isatty v0.0.19 // indirect
8984
github.com/mattn/go-runewidth v0.0.9 // indirect
85+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
9086
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
9187
github.com/modern-go/reflect2 v1.0.2 // indirect
9288
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
9389
github.com/oklog/run v1.1.0 // indirect
9490
github.com/perimeterx/marshmallow v1.1.5 // indirect
9591
github.com/pierrec/lz4/v4 v4.1.18 // indirect
9692
github.com/pmezard/go-difflib v1.0.0 // indirect
97-
github.com/prometheus/client_model v0.5.0 // indirect
98-
github.com/prometheus/procfs v0.12.0 // indirect
93+
github.com/prometheus/client_model v0.6.1 // indirect
94+
github.com/prometheus/procfs v0.14.0 // indirect
9995
github.com/rogpeppe/go-internal v1.11.0 // indirect
10096
github.com/russross/blackfriday/v2 v2.1.0 // indirect
10197
github.com/unknwon/com v1.0.1 // indirect
@@ -110,7 +106,8 @@ require (
110106
google.golang.org/appengine v1.6.8 // indirect
111107
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
112108
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
113-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
109+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
114110
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
111+
gopkg.in/yaml.v3 v3.0.1 // indirect
115112
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
116113
)

0 commit comments

Comments
 (0)