Skip to content

Commit

Permalink
Added a new prometheus provider
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Sharma <[email protected]>
  • Loading branch information
yashrsharma44 committed Jan 15, 2021
1 parent a365913 commit 0434dfb
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 59 deletions.
47 changes: 0 additions & 47 deletions interceptors/metrics/metrics_interface.go

This file was deleted.

File renamed without changes.
24 changes: 24 additions & 0 deletions providers/prometheus/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package metrics

type grpcType string

const (
Unary grpcType = "unary"
ClientStream grpcType = "client_stream"
ServerStream grpcType = "server_stream"
BidiStream grpcType = "bidi_stream"
)

type Kind string

const (
KindClient Kind = "client"
KindServer Kind = "server"
)

type RPCMethod string

const (
Send RPCMethod = "send"
Receive RPCMethod = "recv"
)
9 changes: 9 additions & 0 deletions providers/prometheus/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus

go 1.15

require (
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2
github.com/prometheus/client_golang v1.9.0
google.golang.org/grpc v1.35.0
)
430 changes: 430 additions & 0 deletions providers/prometheus/go.sum

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func (r *reporter) StartTimeCall(startTime time.Time, callType string) intercept
switch r.kind {
case KindClient:
switch callType {
case "send":
case string(Send):
if r.clientMetrics.clientStreamSendHistogramEnabled {
hist := r.clientMetrics.clientStreamSendHistogram.WithLabelValues(string(r.typ), r.service, r.method)
return prometheus.NewTimer(hist)
}
case "recv":
case string(Receive):
if r.clientMetrics.clientStreamRecvHistogramEnabled {
hist := r.clientMetrics.clientStreamRecvHistogram.WithLabelValues(string(r.typ), r.service, r.method)
return prometheus.NewTimer(hist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ import (
"google.golang.org/grpc/status"
)

// Interface for Metrics
type Metrics interface{}

type Kind string

const (
KindClient Kind = "client"
KindServer Kind = "server"
)

// Helper methods
func FromError(err error) (s *status.Status, ok bool) {
return status.FromError(err)
Expand Down
File renamed without changes.

0 comments on commit 0434dfb

Please sign in to comment.