Skip to content

Commit 8a47c4d

Browse files
committed
expose grpc metrics in prometheus
1 parent 991c90c commit 8a47c4d

File tree

187 files changed

+13061
-7261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+13061
-7261
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ The Octopus exposes a number of metrics via an HTTP endpoint ready to be scraped
3434
* `octopus_connector_load_time` - Time it took to fetch data (milliseconds) (broken out by label `connector`)
3535
* `octopus_connector_update_error_count` - The number of time the refresh of connector data has failed (broken out by label `connector`)
3636

37+
Other than those, Octopus is exposing gRPC-related metrics that comes from [go-grpc-middleware](https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/providers/prometheus).
38+
3739
# Querying data
3840

3941
The Octopus exposes a gRPC API to query the enriched topology data.

go.mod

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ go 1.19
55
require (
66
github.com/bio-routing/bio-rd v0.1.9
77
github.com/go-pg/pg v8.0.7+incompatible
8-
github.com/prometheus/client_golang v1.11.1
8+
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
9+
github.com/prometheus/client_golang v1.14.0
910
github.com/sirupsen/logrus v1.9.0
10-
github.com/stretchr/testify v1.8.2
11-
google.golang.org/grpc v1.56.3
11+
github.com/stretchr/testify v1.8.4
12+
google.golang.org/grpc v1.63.2
1213
google.golang.org/protobuf v1.33.0
1314
)
1415

@@ -17,20 +18,21 @@ require (
1718
github.com/bio-routing/tflow2 v0.0.0-20181230153523-2e308a4a3c3a // indirect
1819
github.com/cespare/xxhash/v2 v2.2.0 // indirect
1920
github.com/davecgh/go-spew v1.1.1 // indirect
20-
github.com/golang/protobuf v1.5.3 // indirect
21+
github.com/golang/protobuf v1.5.4 // indirect
22+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
2123
github.com/jinzhu/inflection v1.0.0 // indirect
2224
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
2325
github.com/onsi/ginkgo v1.16.5 // indirect
2426
github.com/onsi/gomega v1.27.6 // indirect
2527
github.com/pmezard/go-difflib v1.0.0 // indirect
2628
github.com/prometheus/client_model v0.3.0 // indirect
27-
github.com/prometheus/common v0.26.0 // indirect
29+
github.com/prometheus/common v0.37.0 // indirect
2830
github.com/prometheus/procfs v0.9.0 // indirect
29-
golang.org/x/crypto v0.21.0 // indirect
30-
golang.org/x/net v0.23.0 // indirect
31-
golang.org/x/sys v0.18.0 // indirect
31+
golang.org/x/crypto v0.22.0 // indirect
32+
golang.org/x/net v0.24.0 // indirect
33+
golang.org/x/sys v0.19.0 // indirect
3234
golang.org/x/text v0.14.0 // indirect
33-
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
35+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
3436
gopkg.in/yaml.v3 v3.0.1 // indirect
3537
mellium.im/sasl v0.3.1 // indirect
3638
)

go.sum

+345-22
Large diffs are not rendered by default.

pkg/octopus/octopus.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/cloudflare/octopus/pkg/connector"
1818
"github.com/cloudflare/octopus/pkg/model"
1919
octopuspb "github.com/cloudflare/octopus/proto/octopus"
20+
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
21+
"github.com/prometheus/client_golang/prometheus"
2022

2123
"google.golang.org/grpc"
2224
"google.golang.org/grpc/reflection"
@@ -131,9 +133,18 @@ func (o *Octopus) serveGrpc() {
131133
log.Infof("Starting gRPC API server at %s", portStr)
132134

133135
os := newOctopusServer(o)
134-
s := grpc.NewServer()
136+
137+
srvMetrics := grpcprom.NewServerMetrics()
138+
s := grpc.NewServer(
139+
grpc.UnaryInterceptor(srvMetrics.UnaryServerInterceptor()),
140+
grpc.StreamInterceptor(srvMetrics.StreamServerInterceptor()),
141+
)
135142
s.RegisterService(&octopuspb.OctopusService_ServiceDesc, os)
136143

144+
// Register Prometheus metrics
145+
srvMetrics.InitializeMetrics(s)
146+
prometheus.MustRegister(srvMetrics)
147+
137148
// Allow client to retrieve proto definition
138149
reflection.Register(s)
139150

0 commit comments

Comments
 (0)