Skip to content

Commit

Permalink
Client side metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroPatti committed Jul 30, 2023
1 parent 9ff2ab6 commit 6481feb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ go_library(
"//cache/s3proxy:go_default_library",
"@com_github_azure_azure_sdk_for_go_sdk_azcore//:go_default_library",
"@com_github_azure_azure_sdk_for_go_sdk_azidentity//:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library",
"@com_github_minio_minio_go_v7//:go_default_library",
"@com_github_minio_minio_go_v7//pkg/credentials:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@in_gopkg_yaml_v3//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
Expand Down
12 changes: 12 additions & 0 deletions config/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
prom "github.com/prometheus/client_golang/prometheus"
)

func (c *Config) setProxy() error {
Expand Down Expand Up @@ -49,6 +52,15 @@ func (c *Config) setProxy() error {
} else {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
metrics := grpc_prometheus.NewClientMetrics(func(o *prom.CounterOpts) { o.Namespace = "proxy" })
metrics.EnableClientHandlingTimeHistogram(func(o *prom.HistogramOpts) { o.Namespace = "proxy" })
err := prom.Register(metrics)
if err != nil {
return err
}
opts = append(opts, grpc.WithChainStreamInterceptor(metrics.StreamClientInterceptor()))
opts = append(opts, grpc.WithChainUnaryInterceptor(metrics.UnaryClientInterceptor()))

conn, err := grpc.Dial(c.GRPCBackend.BaseUrl, opts...)
if err != nil {
return err
Expand Down

0 comments on commit 6481feb

Please sign in to comment.