Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go')
-rw-r--r--vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go
new file mode 100644
index 00000000..cbf15322
--- /dev/null
+++ b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go
@@ -0,0 +1,46 @@
+// Copyright 2016 Michal Witkowski. All Rights Reserved.
+// See LICENSE for licensing terms.
+
+package grpc_prometheus
+
+import (
+ "time"
+
+ "google.golang.org/grpc/codes"
+)
+
+type clientReporter struct {
+ metrics *ClientMetrics
+ rpcType grpcType
+ serviceName string
+ methodName string
+ startTime time.Time
+}
+
+func newClientReporter(m *ClientMetrics, rpcType grpcType, fullMethod string) *clientReporter {
+ r := &clientReporter{
+ metrics: m,
+ rpcType: rpcType,
+ }
+ if r.metrics.clientHandledHistogramEnabled {
+ r.startTime = time.Now()
+ }
+ r.serviceName, r.methodName = splitMethodName(fullMethod)
+ r.metrics.clientStartedCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc()
+ return r
+}
+
+func (r *clientReporter) ReceivedMessage() {
+ r.metrics.clientStreamMsgReceived.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc()
+}
+
+func (r *clientReporter) SentMessage() {
+ r.metrics.clientStreamMsgSent.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc()
+}
+
+func (r *clientReporter) Handled(code codes.Code) {
+ r.metrics.clientHandledCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName, code.String()).Inc()
+ if r.metrics.clientHandledHistogramEnabled {
+ r.metrics.clientHandledHistogram.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Observe(time.Since(r.startTime).Seconds())
+ }
+}