mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	v1.1.0 (which is what we currently use), does not expose metrics which makes it impossible to migrate.
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2016 Michal Witkowski. All Rights Reserved.
 | 
						|
// See LICENSE for licensing terms.
 | 
						|
 | 
						|
package grpc_prometheus
 | 
						|
 | 
						|
import (
 | 
						|
	"time"
 | 
						|
 | 
						|
	"google.golang.org/grpc/codes"
 | 
						|
)
 | 
						|
 | 
						|
type serverReporter struct {
 | 
						|
	metrics     *ServerMetrics
 | 
						|
	rpcType     grpcType
 | 
						|
	serviceName string
 | 
						|
	methodName  string
 | 
						|
	startTime   time.Time
 | 
						|
}
 | 
						|
 | 
						|
func newServerReporter(m *ServerMetrics, rpcType grpcType, fullMethod string) *serverReporter {
 | 
						|
	r := &serverReporter{
 | 
						|
		metrics: m,
 | 
						|
		rpcType: rpcType,
 | 
						|
	}
 | 
						|
	if r.metrics.serverHandledHistogramEnabled {
 | 
						|
		r.startTime = time.Now()
 | 
						|
	}
 | 
						|
	r.serviceName, r.methodName = splitMethodName(fullMethod)
 | 
						|
	r.metrics.serverStartedCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc()
 | 
						|
	return r
 | 
						|
}
 | 
						|
 | 
						|
func (r *serverReporter) ReceivedMessage() {
 | 
						|
	r.metrics.serverStreamMsgReceived.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc()
 | 
						|
}
 | 
						|
 | 
						|
func (r *serverReporter) SentMessage() {
 | 
						|
	r.metrics.serverStreamMsgSent.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc()
 | 
						|
}
 | 
						|
 | 
						|
func (r *serverReporter) Handled(code codes.Code) {
 | 
						|
	r.metrics.serverHandledCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName, code.String()).Inc()
 | 
						|
	if r.metrics.serverHandledHistogramEnabled {
 | 
						|
		r.metrics.serverHandledHistogram.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Observe(time.Since(r.startTime).Seconds())
 | 
						|
	}
 | 
						|
}
 |