Skip to content

Expose grpc metrics in prometheus #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading