Skip to content

Commit

Permalink
Merge pull request #13 from cloudflare/mgouel/grpc-prom
Browse files Browse the repository at this point in the history
Expose grpc metrics in prometheus
  • Loading branch information
matthieugouel authored Nov 4, 2024
2 parents 991c90c + 8a47c4d commit 293632c
Show file tree
Hide file tree
Showing 187 changed files with 13,061 additions and 7,261 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ The Octopus exposes a number of metrics via an HTTP endpoint ready to be scraped
* `octopus_connector_load_time` - Time it took to fetch data (milliseconds) (broken out by label `connector`)
* `octopus_connector_update_error_count` - The number of time the refresh of connector data has failed (broken out by label `connector`)

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).

# Querying data

The Octopus exposes a gRPC API to query the enriched topology data.
Expand Down
20 changes: 11 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ go 1.19
require (
github.com/bio-routing/bio-rd v0.1.9
github.com/go-pg/pg v8.0.7+incompatible
github.com/prometheus/client_golang v1.11.1
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
github.com/prometheus/client_golang v1.14.0
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.2
google.golang.org/grpc v1.56.3
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
)

Expand All @@ -17,20 +18,21 @@ require (
github.com/bio-routing/tflow2 v0.0.0-20181230153523-2e308a4a3c3a // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mellium.im/sasl v0.3.1 // indirect
)
367 changes: 345 additions & 22 deletions go.sum

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion pkg/octopus/octopus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/cloudflare/octopus/pkg/connector"
"github.com/cloudflare/octopus/pkg/model"
octopuspb "github.com/cloudflare/octopus/proto/octopus"
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
"github.com/prometheus/client_golang/prometheus"

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

os := newOctopusServer(o)
s := grpc.NewServer()

srvMetrics := grpcprom.NewServerMetrics()
s := grpc.NewServer(
grpc.UnaryInterceptor(srvMetrics.UnaryServerInterceptor()),
grpc.StreamInterceptor(srvMetrics.StreamServerInterceptor()),
)
s.RegisterService(&octopuspb.OctopusService_ServiceDesc, os)

// Register Prometheus metrics
srvMetrics.InitializeMetrics(s)
prometheus.MustRegister(srvMetrics)

// Allow client to retrieve proto definition
reflection.Register(s)

Expand Down
Loading

0 comments on commit 293632c

Please sign in to comment.