promgrpc

package module
v4.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package promgrpc is an instrumentation package that allows capturing metrics of your gRPC based services, both the server and the client side. The main goal of version 4 was to make it modular without sacrificing the simplicity of use.

It is still possible to integrate the package in just a few lines. However, if necessary, metrics can be added, removed or modified freely.

Design

The package does not introduce any new concepts to an already complicated environment. Instead, it focuses on providing implementations of interfaces exported by gRPC and Prometheus libraries.

It causes no side effects nor has global state. Instead, it comes with handy one-liners to reduce integration overhead.

The package achieved high modularity by using Inversion of Control. We can define three layers of abstraction, where each is configurable or if necessary replaceable.

Collectors serve one purpose, storing metrics. These are types well known from Prometheus ecosystem, like counters, gauges, histograms or summaries. This package comes with a set of predefined functions that create a specific instances for each use case. For example:

func NewRequestsTotalCounterVec(Subsystem, ...CollectorOption) *prometheus.CounterVec

Level higher consist of stats handlers. This layer is responsible for metrics collection. It is aware of a collector and knows how to use it to record event occurrences. Each implementation satisfies stats.Handler and prometheus.Collector interface and knows how to monitor a single dimension, e.g. a total number of received/sent requests:

func NewClientRequestsTotalStatsHandler(*prometheus.GaugeVec, ...StatsHandlerOption) *ClientRequestsTotalStatsHandler
func NewServerRequestsTotalStatsHandler(*prometheus.GaugeVec, ...StatsHandlerOption) *ServerRequestsTotalStatsHandler

Above all, there is a coordinator. StatsHandler combines multiple stats handlers into a single instance.

Metrics

The package comes with eighteen predefined metrics — nine for server and nine for client side:

grpc_client_connections
grpc_client_message_received_size_histogram_bytes
grpc_client_message_sent_size_histogram_bytes
grpc_client_messages_received_total
grpc_client_messages_sent_total
grpc_client_request_duration_histogram_seconds
grpc_client_requests_in_flight
grpc_client_requests_sent_total
grpc_client_responses_received_total
grpc_server_connections
grpc_server_message_received_size_histogram_bytes
grpc_server_message_sent_size_histogram_bytes
grpc_server_messages_received_total
grpc_server_messages_sent_total
grpc_server_request_duration_histogram_seconds
grpc_server_requests_in_flight
grpc_server_requests_received_total
grpc_server_responses_sent_total

Configuration

The package does not require any configuration whatsoever but makes it possible. It is beneficial for different reasons.

Having all metrics enabled could not be desirable. Some, like histograms, can create significant overhead on the producer side. If performance is critical, it advisable to reduce the set of metrics. To do that, implement a custom version of coordinator constructor, ClientStatsHandler and/or ServerStatsHandler.

Another good reason to change default settings is backward compatibility. Migration of Grafana dashboards is not an easy nor quick task. If the discrepancy is small and, e.g. the only necessary adjustment is changing the namespace, it is achievable by passing CollectorWithNamespace to a collector constructor. It is the same very known pattern from the gRPC package, with some enhancements. What makes it different is that both StatsHandlerOption and CollectorOption have a shareable variant, called ShareableCollectorOption and ShareableStatsHandlerOption respectively. Thanks to that, it is possible to pass options related to stats handlers and collectors to coordinator constructors. Constructors take care of moving options to the correct receivers.

Mixing both strategies described above will give even greater freedom. However, if that is even not enough, it is possible to reimplement an entire stack for a given metric or metrics.

Example
reg := prometheus.NewRegistry()

ssh := promgrpc.ServerStatsHandler(
	promgrpc.CollectorWithNamespace("example"),
	promgrpc.CollectorWithConstLabels(prometheus.Labels{"service": "foo"}),
)
csh := promgrpc.ClientStatsHandler(
	promgrpc.CollectorWithConstLabels(prometheus.Labels{"service": "bar"}),
)

srv := grpc.NewServer(grpc.StatsHandler(ssh))
imp := newDemoServer()

test.RegisterTestServiceServer(srv, imp)
reg.MustRegister(ssh)
reg.MustRegister(csh)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientConnectionsGaugeVec

func NewClientConnectionsGaugeVec(opts ...CollectorOption) *prometheus.GaugeVec

NewClientConnectionsGaugeVec instantiates client-side GaugeVec suitable for use with NewClientConnectionsStatsHandler.

func NewClientMessageReceivedSizeHistogramVec

func NewClientMessageReceivedSizeHistogramVec(opts ...CollectorOption) *prometheus.HistogramVec

NewClientMessageReceivedSizeHistogramVec instantiates default client-side HistogramVec suitable for use with NewClientMessageReceivedSizeStatsHandler.

func NewClientMessageSentSizeHistogramVec

func NewClientMessageSentSizeHistogramVec(opts ...CollectorOption) *prometheus.HistogramVec

NewClientMessageSentSizeHistogramVec instantiates client-side HistogramVec suitable for use with NewClientMessageSentSizeStatsHandler.

func NewClientMessagesReceivedTotalCounterVec

func NewClientMessagesReceivedTotalCounterVec(opts ...CollectorOption) *prometheus.CounterVec

NewClientMessagesReceivedTotalCounterVec instantiates client-side CounterVec suitable for use with NewClientMessagesReceivedTotalStatsHandler.

func NewClientMessagesSentTotalCounterVec

func NewClientMessagesSentTotalCounterVec(opts ...CollectorOption) *prometheus.CounterVec

NewClientMessagesSentTotalCounterVec instantiates client-side CounterVec suitable for use with NewClientMessagesSentTotalStatsHandler.

func NewClientRequestDurationHistogramVec

func NewClientRequestDurationHistogramVec(opts ...CollectorOption) *prometheus.HistogramVec

NewClientRequestDurationHistogramVec instantiates client-side HistogramVec suitable for use with NewClientRequestDurationStatsHandler.

func NewClientRequestsInFlightGaugeVec

func NewClientRequestsInFlightGaugeVec(opts ...CollectorOption) *prometheus.GaugeVec

NewClientRequestsInFlightGaugeVec instantiates client-side GaugeVec suitable for use with NewClientRequestsInFlightStatsHandler.

func NewClientRequestsTotalCounterVec

func NewClientRequestsTotalCounterVec(opts ...CollectorOption) *prometheus.CounterVec

NewClientRequestsTotalCounterVec instantiates client-side CounterVec suitable for use with NewClientRequestsTotalStatsHandler.

func NewClientResponsesTotalCounterVec

func NewClientResponsesTotalCounterVec(opts ...CollectorOption) *prometheus.CounterVec

NewClientResponsesTotalCounterVec instantiates client-side CounterVec suitable for use with NewClientResponsesTotalStatsHandler.

func NewServerConnectionsGaugeVec

func NewServerConnectionsGaugeVec(opts ...CollectorOption) *prometheus.GaugeVec

NewServerConnectionsGaugeVec instantiates client-side GaugeVec suitable for use with NewServerConnectionsStatsHandler.

func NewServerMessageReceivedSizeHistogramVec

func NewServerMessageReceivedSizeHistogramVec(opts ...CollectorOption) *prometheus.HistogramVec

NewServerMessageReceivedSizeHistogramVec instantiates default server-side HistogramVec suitable for use with NewServerMessageReceivedSizeStatsHandler.

func NewServerMessageSentSizeHistogramVec

func NewServerMessageSentSizeHistogramVec(opts ...CollectorOption) *prometheus.HistogramVec

NewServerMessageSentSizeHistogramVec instantiates default server-side HistogramVec suitable for use with NewServerMessageSentSizeStatsHandler.

func NewServerMessagesReceivedTotalCounterVec

func NewServerMessagesReceivedTotalCounterVec(opts ...CollectorOption) *prometheus.CounterVec

NewServerMessagesReceivedTotalCounterVec instantiates default server-side CounterVec suitable for use with NewServerMessagesReceivedTotalStatsHandler.

func NewServerMessagesSentTotalCounterVec

func NewServerMessagesSentTotalCounterVec(opts ...CollectorOption) *prometheus.CounterVec

NewServerMessagesSentTotalCounterVec instantiates default server-side CounterVec suitable for use with NewServerMessagesSentTotalStatsHandler.

func NewServerRequestDurationHistogramVec

func NewServerRequestDurationHistogramVec(opts ...CollectorOption) *prometheus.HistogramVec

NewServerRequestDurationHistogramVec instantiates default server-side HistogramVec suitable for use with NewServerRequestDurationStatsHandler.

func NewServerRequestsInFlightGaugeVec

func NewServerRequestsInFlightGaugeVec(opts ...CollectorOption) *prometheus.GaugeVec

NewServerRequestsInFlightGaugeVec instantiates default server-side GaugeVec suitable for use with NewServerRequestsInFlightStatsHandler.

func NewServerRequestsTotalCounterVec

func NewServerRequestsTotalCounterVec(opts ...CollectorOption) *prometheus.CounterVec

NewServerRequestsTotalCounterVec instantiates default server-side CounterVec suitable for use with NewServerRequestsTotalStatsHandler.

func NewServerResponsesTotalCounterVec

func NewServerResponsesTotalCounterVec(opts ...CollectorOption) *prometheus.CounterVec

NewServerResponsesTotalCounterVec instantiates default server-side CounterVec suitable for use with NewServerResponsesTotalStatsHandler.

Types

type ClientConnectionsStatsHandler

type ClientConnectionsStatsHandler struct {
	// contains filtered or unexported fields
}

ClientConnectionsStatsHandler dedicated client-side StatsHandlerCollector that counts the number of outgoing connections.

func NewClientConnectionsStatsHandler

func NewClientConnectionsStatsHandler(vec *prometheus.GaugeVec) *ClientConnectionsStatsHandler

NewClientConnectionsStatsHandler instantiates ClientConnectionsStatsHandler based on given GaugeVec. The GaugeVec must have zero, one or two non-const non-curried labels. For those, the only allowed names are "grpc_remote_addr" and "grpc_local_addr".

func (*ClientConnectionsStatsHandler) Collect

func (h *ClientConnectionsStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientConnectionsStatsHandler) Describe

func (h *ClientConnectionsStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientConnectionsStatsHandler) HandleConn

func (h *ClientConnectionsStatsHandler) HandleConn(ctx context.Context, stat stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientConnectionsStatsHandler) HandleRPC

func (h *ClientConnectionsStatsHandler) HandleRPC(_ context.Context, _ stats.RPCStats)

HandleRPC implements stats Handler interface.

func (*ClientConnectionsStatsHandler) TagConn

func (h *ClientConnectionsStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientConnectionsStatsHandler) TagRPC

func (h *ClientConnectionsStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ClientMessageReceivedSizeStatsHandler

type ClientMessageReceivedSizeStatsHandler struct {
	// contains filtered or unexported fields
}

ClientMessageReceivedSizeStatsHandler dedicated client-side StatsHandlerCollector that counts individual observations of received message size.

func NewClientMessageReceivedSizeStatsHandler

func NewClientMessageReceivedSizeStatsHandler(vec prometheus.ObserverVec, opts ...StatsHandlerOption) *ClientMessageReceivedSizeStatsHandler

NewClientMessageReceivedSizeStatsHandler instantiates ClientMessageReceivedSizeStatsHandler based on given ObserverVec and options. The CounterVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed names are "grpc_is_fail_fast", "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ClientMessageReceivedSizeStatsHandler) Collect

func (h *ClientMessageReceivedSizeStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientMessageReceivedSizeStatsHandler) Describe

func (h *ClientMessageReceivedSizeStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientMessageReceivedSizeStatsHandler) HandleConn

func (h *ClientMessageReceivedSizeStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientMessageReceivedSizeStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ClientMessageReceivedSizeStatsHandler) TagConn

func (h *ClientMessageReceivedSizeStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientMessageReceivedSizeStatsHandler) TagRPC

func (h *ClientMessageReceivedSizeStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ClientMessageSentSizeStatsHandler

type ClientMessageSentSizeStatsHandler struct {
	// contains filtered or unexported fields
}

ClientMessageSentSizeStatsHandler dedicated client-side StatsHandlerCollector that counts individual observations of sent message size.

func NewClientMessageSentSizeStatsHandler

func NewClientMessageSentSizeStatsHandler(vec prometheus.ObserverVec, opts ...StatsHandlerOption) *ClientMessageSentSizeStatsHandler

NewClientMessageSentSizeStatsHandler instantiates ClientMessageSentSizeStatsHandler based on given ObserverVec and options. The ObserverVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed names are "grpc_is_fail_fast", "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ClientMessageSentSizeStatsHandler) Collect

func (h *ClientMessageSentSizeStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientMessageSentSizeStatsHandler) Describe

func (h *ClientMessageSentSizeStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientMessageSentSizeStatsHandler) HandleConn

func (h *ClientMessageSentSizeStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientMessageSentSizeStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ClientMessageSentSizeStatsHandler) TagConn

func (h *ClientMessageSentSizeStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientMessageSentSizeStatsHandler) TagRPC

func (h *ClientMessageSentSizeStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ClientMessagesReceivedTotalStatsHandler

type ClientMessagesReceivedTotalStatsHandler struct {
	// contains filtered or unexported fields
}

ClientMessagesReceivedTotalStatsHandler dedicated client-side StatsHandlerCollector that counts number of messages received.

func NewClientMessagesReceivedTotalStatsHandler

func NewClientMessagesReceivedTotalStatsHandler(vec *prometheus.CounterVec, opts ...StatsHandlerOption) *ClientMessagesReceivedTotalStatsHandler

NewClientMessagesReceivedTotalStatsHandler instantiates ClientMessagesReceivedTotalStatsHandler based on given CounterVec and options. The CounterVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed names are "grpc_is_fail_fast", "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ClientMessagesReceivedTotalStatsHandler) Collect

func (h *ClientMessagesReceivedTotalStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientMessagesReceivedTotalStatsHandler) Describe

func (h *ClientMessagesReceivedTotalStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientMessagesReceivedTotalStatsHandler) HandleConn

func (h *ClientMessagesReceivedTotalStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientMessagesReceivedTotalStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ClientMessagesReceivedTotalStatsHandler) TagConn

func (h *ClientMessagesReceivedTotalStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientMessagesReceivedTotalStatsHandler) TagRPC

func (h *ClientMessagesReceivedTotalStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ClientMessagesSentTotalStatsHandler

type ClientMessagesSentTotalStatsHandler struct {
	// contains filtered or unexported fields
}

ClientMessagesSentTotalStatsHandler dedicated client-side StatsHandlerCollector that counts number of messages sent.

func NewClientMessagesSentTotalStatsHandler

func NewClientMessagesSentTotalStatsHandler(vec *prometheus.CounterVec, opts ...StatsHandlerOption) *ClientMessagesSentTotalStatsHandler

NewClientMessagesSentTotalStatsHandler instantiates ClientMessagesSentTotalStatsHandler based on given CounterVec and options. The CounterVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed names are "grpc_is_fail_fast", "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ClientMessagesSentTotalStatsHandler) Collect

func (h *ClientMessagesSentTotalStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientMessagesSentTotalStatsHandler) Describe

func (h *ClientMessagesSentTotalStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientMessagesSentTotalStatsHandler) HandleConn

func (h *ClientMessagesSentTotalStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientMessagesSentTotalStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ClientMessagesSentTotalStatsHandler) TagConn

func (h *ClientMessagesSentTotalStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientMessagesSentTotalStatsHandler) TagRPC

func (h *ClientMessagesSentTotalStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ClientRequestDurationStatsHandler

type ClientRequestDurationStatsHandler struct {
	// contains filtered or unexported fields
}

ClientRequestDurationStatsHandler dedicated client-side StatsHandlerCollector that counts individual observations of request duration.

func NewClientRequestDurationStatsHandler

func NewClientRequestDurationStatsHandler(vec prometheus.ObserverVec, opts ...StatsHandlerOption) *ClientRequestDurationStatsHandler

NewClientRequestDurationStatsHandler instantiates ClientRequestDurationStatsHandler based on given ObserverVec and options. The ObserverVec must have zero, one, two, three, four or five non-const non-curried labels. For those, the only allowed names are "grpc_is_fail_fast", "grpc_method", "grpc_service", "grpc_client_user_agent" and "grpc_code".

func (*ClientRequestDurationStatsHandler) Collect

func (h *ClientRequestDurationStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientRequestDurationStatsHandler) Describe

func (h *ClientRequestDurationStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientRequestDurationStatsHandler) HandleConn

func (h *ClientRequestDurationStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientRequestDurationStatsHandler) HandleRPC

HandleRPC processes the RPC stats.

func (*ClientRequestDurationStatsHandler) TagConn

func (h *ClientRequestDurationStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientRequestDurationStatsHandler) TagRPC

func (h *ClientRequestDurationStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ClientRequestsInFlightStatsHandler

type ClientRequestsInFlightStatsHandler struct {
	// contains filtered or unexported fields
}

ClientRequestsInFlightStatsHandler dedicated client-side StatsHandlerCollector that counts the number of requests currently in flight.

func NewClientRequestsInFlightStatsHandler

func NewClientRequestsInFlightStatsHandler(vec *prometheus.GaugeVec, opts ...StatsHandlerOption) *ClientRequestsInFlightStatsHandler

NewClientRequestsInFlightStatsHandler instantiates ClientRequestsInFlightStatsHandler based on given GaugeVec and options. The GaugeVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed names are "grpc_is_fail_fast", "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ClientRequestsInFlightStatsHandler) Collect

func (h *ClientRequestsInFlightStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientRequestsInFlightStatsHandler) Describe

func (h *ClientRequestsInFlightStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientRequestsInFlightStatsHandler) HandleConn

func (h *ClientRequestsInFlightStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientRequestsInFlightStatsHandler) HandleRPC

HandleRPC processes the RPC stats.

func (*ClientRequestsInFlightStatsHandler) TagConn

func (h *ClientRequestsInFlightStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientRequestsInFlightStatsHandler) TagRPC

func (h *ClientRequestsInFlightStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ClientRequestsTotalStatsHandler

type ClientRequestsTotalStatsHandler struct {
	// contains filtered or unexported fields
}

ClientRequestsTotalStatsHandler dedicated client-side StatsHandlerCollector that counts number of requests sent.

func NewClientRequestsTotalStatsHandler

func NewClientRequestsTotalStatsHandler(vec *prometheus.CounterVec, opts ...StatsHandlerOption) *ClientRequestsTotalStatsHandler

NewClientRequestsTotalStatsHandler instantiates ClientRequestsTotalStatsHandler based on given CounterVec and options. The CounterVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed names are "grpc_is_fail_fast", "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ClientRequestsTotalStatsHandler) Collect

func (h *ClientRequestsTotalStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientRequestsTotalStatsHandler) Describe

func (h *ClientRequestsTotalStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientRequestsTotalStatsHandler) HandleConn

func (h *ClientRequestsTotalStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientRequestsTotalStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ClientRequestsTotalStatsHandler) TagConn

func (h *ClientRequestsTotalStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientRequestsTotalStatsHandler) TagRPC

func (h *ClientRequestsTotalStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ClientResponsesTotalStatsHandler

type ClientResponsesTotalStatsHandler struct {
	// contains filtered or unexported fields
}

ClientResponsesTotalStatsHandler dedicated client-side StatsHandlerCollector that counts number of responses received.

func NewClientResponsesTotalStatsHandler

func NewClientResponsesTotalStatsHandler(vec *prometheus.CounterVec, opts ...StatsHandlerOption) *ClientResponsesTotalStatsHandler

NewClientResponsesTotalStatsHandler instantiates ClientResponsesTotalStatsHandler based on given CounterVec and options. The CounterVec must have zero, one, two, three, four or five non-const non-curried labels. For those, the only allowed names are "grpc_is_fail_fast", "grpc_method", "grpc_service", "grpc_client_user_agent" and "grpc_code".

func (*ClientResponsesTotalStatsHandler) Collect

func (h *ClientResponsesTotalStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ClientResponsesTotalStatsHandler) Describe

func (h *ClientResponsesTotalStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ClientResponsesTotalStatsHandler) HandleConn

func (h *ClientResponsesTotalStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ClientResponsesTotalStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ClientResponsesTotalStatsHandler) TagConn

func (h *ClientResponsesTotalStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ClientResponsesTotalStatsHandler) TagRPC

func (h *ClientResponsesTotalStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type CollectorOption

type CollectorOption interface {
	// contains filtered or unexported methods
}

CollectorOption configures a collector.

type HandleRPCLabelFunc

type HandleRPCLabelFunc func(context.Context, stats.RPCStats) []string

HandleRPCLabelFunc type represents a function signature that can be passed into a stats handler and used instead of default one. That way caller gets the ability to modify the way labels are assembled.

type ServerConnectionsStatsHandler

type ServerConnectionsStatsHandler struct {
	// contains filtered or unexported fields
}

ServerConnectionsStatsHandler dedicated server-side StatsHandlerCollector that counts the number of incoming connections.

func NewServerConnectionsStatsHandler

func NewServerConnectionsStatsHandler(vec *prometheus.GaugeVec) *ServerConnectionsStatsHandler

NewServerConnectionsStatsHandler instantiates ServerConnectionsStatsHandler based on given GaugeVec. The GaugeVec must have zero, one, two or three non-const non-curried labels. For those, the only allowed names are "grpc_remote_addr", "grpc_local_addr" and "grpc_client_user_agent".

func (*ServerConnectionsStatsHandler) Collect

func (h *ServerConnectionsStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerConnectionsStatsHandler) Describe

func (h *ServerConnectionsStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerConnectionsStatsHandler) HandleConn

func (h *ServerConnectionsStatsHandler) HandleConn(ctx context.Context, stat stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerConnectionsStatsHandler) HandleRPC

func (h *ServerConnectionsStatsHandler) HandleRPC(_ context.Context, _ stats.RPCStats)

HandleRPC implements stats Handler interface.

func (*ServerConnectionsStatsHandler) TagConn

func (h *ServerConnectionsStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerConnectionsStatsHandler) TagRPC

func (h *ServerConnectionsStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ServerMessageReceivedSizeStatsHandler

type ServerMessageReceivedSizeStatsHandler struct {
	// contains filtered or unexported fields
}

ServerMessageReceivedSizeStatsHandler dedicated server-side StatsHandlerCollector that counts individual observations of received message size.

func NewServerMessageReceivedSizeStatsHandler

func NewServerMessageReceivedSizeStatsHandler(vec prometheus.ObserverVec, opts ...StatsHandlerOption) *ServerMessageReceivedSizeStatsHandler

NewServerMessageReceivedSizeStatsHandler instantiates ServerMessageReceivedSizeStatsHandler based on given ObserverVec and options. The ObserverVec must have zero, one, two or three non-const non-curried labels. For those, the only allowed names are "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ServerMessageReceivedSizeStatsHandler) Collect

func (h *ServerMessageReceivedSizeStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerMessageReceivedSizeStatsHandler) Describe

func (h *ServerMessageReceivedSizeStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerMessageReceivedSizeStatsHandler) HandleConn

func (h *ServerMessageReceivedSizeStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerMessageReceivedSizeStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ServerMessageReceivedSizeStatsHandler) TagConn

func (h *ServerMessageReceivedSizeStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerMessageReceivedSizeStatsHandler) TagRPC

func (h *ServerMessageReceivedSizeStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ServerMessageSentSizeStatsHandler

type ServerMessageSentSizeStatsHandler struct {
	// contains filtered or unexported fields
}

ServerMessageSentSizeStatsHandler dedicated server-side StatsHandlerCollector that counts individual observations of sent message size.

func NewServerMessageSentSizeStatsHandler

func NewServerMessageSentSizeStatsHandler(vec prometheus.ObserverVec, opts ...StatsHandlerOption) *ServerMessageSentSizeStatsHandler

NewServerMessageSentSizeStatsHandler instantiates ServerMessageSentSizeStatsHandler based on given ObserverVec and options. The ObserverVec must have zero, one, two or three non-const non-curried labels. For those, the only allowed names are "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ServerMessageSentSizeStatsHandler) Collect

func (h *ServerMessageSentSizeStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerMessageSentSizeStatsHandler) Describe

func (h *ServerMessageSentSizeStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerMessageSentSizeStatsHandler) HandleConn

func (h *ServerMessageSentSizeStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerMessageSentSizeStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ServerMessageSentSizeStatsHandler) TagConn

func (h *ServerMessageSentSizeStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerMessageSentSizeStatsHandler) TagRPC

func (h *ServerMessageSentSizeStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ServerMessagesReceivedTotalStatsHandler

type ServerMessagesReceivedTotalStatsHandler struct {
	// contains filtered or unexported fields
}

ServerMessagesReceivedTotalStatsHandler dedicated server-side StatsHandlerCollector that counts number of messages received.

func NewServerMessagesReceivedTotalStatsHandler

func NewServerMessagesReceivedTotalStatsHandler(vec *prometheus.CounterVec, opts ...StatsHandlerOption) *ServerMessagesReceivedTotalStatsHandler

NewServerMessagesReceivedTotalStatsHandler instantiates ServerMessagesReceivedTotalStatsHandler based on given CounterVec and options. The CounterVec must have zero, one, two or three non-const non-curried labels. For those, the only allowed names are "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ServerMessagesReceivedTotalStatsHandler) Collect

func (h *ServerMessagesReceivedTotalStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerMessagesReceivedTotalStatsHandler) Describe

func (h *ServerMessagesReceivedTotalStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerMessagesReceivedTotalStatsHandler) HandleConn

func (h *ServerMessagesReceivedTotalStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerMessagesReceivedTotalStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ServerMessagesReceivedTotalStatsHandler) TagConn

func (h *ServerMessagesReceivedTotalStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerMessagesReceivedTotalStatsHandler) TagRPC

func (h *ServerMessagesReceivedTotalStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ServerMessagesSentTotalStatsHandler

type ServerMessagesSentTotalStatsHandler struct {
	// contains filtered or unexported fields
}

ServerMessagesSentTotalStatsHandler dedicated server-side StatsHandlerCollector that counts number of messages sent.

func NewServerMessagesSentTotalStatsHandler

func NewServerMessagesSentTotalStatsHandler(vec *prometheus.CounterVec, opts ...StatsHandlerOption) *ServerMessagesSentTotalStatsHandler

NewServerMessagesSentTotalStatsHandler instantiates ServerMessagesSentTotalStatsHandler based on given CounterVec and options. The CounterVec must have zero, one, two or three non-const non-curried labels. For those, the only allowed names are "grpc_method", "grpc_service" and "grpc_client_user_agent".

func (*ServerMessagesSentTotalStatsHandler) Collect

func (h *ServerMessagesSentTotalStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerMessagesSentTotalStatsHandler) Describe

func (h *ServerMessagesSentTotalStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerMessagesSentTotalStatsHandler) HandleConn

func (h *ServerMessagesSentTotalStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerMessagesSentTotalStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ServerMessagesSentTotalStatsHandler) TagConn

func (h *ServerMessagesSentTotalStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerMessagesSentTotalStatsHandler) TagRPC

func (h *ServerMessagesSentTotalStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ServerRequestDurationStatsHandler

type ServerRequestDurationStatsHandler struct {
	// contains filtered or unexported fields
}

ServerRequestDurationStatsHandler dedicated server-side StatsHandlerCollector that counts individual observations of request duration.

func NewServerRequestDurationStatsHandler

func NewServerRequestDurationStatsHandler(vec prometheus.ObserverVec, opts ...StatsHandlerOption) *ServerRequestDurationStatsHandler

NewServerRequestDurationStatsHandler instantiates ServerRequestDurationStatsHandler based on given ObserverVec and options. The ObserverVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed names are "grpc_method", "grpc_service", "grpc_client_user_agent" and "grpc_code".

func (*ServerRequestDurationStatsHandler) Collect

func (h *ServerRequestDurationStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerRequestDurationStatsHandler) Describe

func (h *ServerRequestDurationStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerRequestDurationStatsHandler) HandleConn

func (h *ServerRequestDurationStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerRequestDurationStatsHandler) HandleRPC

HandleRPC processes the RPC stats.

func (*ServerRequestDurationStatsHandler) TagConn

func (h *ServerRequestDurationStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerRequestDurationStatsHandler) TagRPC

func (h *ServerRequestDurationStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ServerRequestsInFlightStatsHandler

type ServerRequestsInFlightStatsHandler struct {
	// contains filtered or unexported fields
}

ServerRequestsInFlightStatsHandler dedicated server-side StatsHandlerCollector that counts the number of requests currently in flight.

func NewServerRequestsInFlightStatsHandler

func NewServerRequestsInFlightStatsHandler(vec *prometheus.GaugeVec, opts ...StatsHandlerOption) *ServerRequestsInFlightStatsHandler

NewServerRequestsInFlightStatsHandler instantiates ServerRequestsInFlightStatsHandler based on given GaugeVec and options. The GaugeVec must have zero, one or two non-const non-curried labels. For those, the only allowed names are "grpc_method" and "grpc_service".

func (*ServerRequestsInFlightStatsHandler) Collect

func (h *ServerRequestsInFlightStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerRequestsInFlightStatsHandler) Describe

func (h *ServerRequestsInFlightStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerRequestsInFlightStatsHandler) HandleConn

func (h *ServerRequestsInFlightStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerRequestsInFlightStatsHandler) HandleRPC

HandleRPC processes the RPC stats.

func (*ServerRequestsInFlightStatsHandler) TagConn

func (h *ServerRequestsInFlightStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerRequestsInFlightStatsHandler) TagRPC

func (h *ServerRequestsInFlightStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ServerRequestsTotalStatsHandler

type ServerRequestsTotalStatsHandler struct {
	// contains filtered or unexported fields
}

ServerRequestsTotalStatsHandler dedicated server-side StatsHandlerCollector that counts number of requests sent.

func NewServerRequestsTotalStatsHandler

func NewServerRequestsTotalStatsHandler(vec *prometheus.CounterVec, opts ...StatsHandlerOption) *ServerRequestsTotalStatsHandler

NewServerRequestsTotalStatsHandler instantiates ServerRequestsTotalStatsHandler based on given CounterVec and options. The CounterVec must have zero, one or two non-const non-curried labels. For those, the only allowed names are "grpc_method" and "grpc_service".

func (*ServerRequestsTotalStatsHandler) Collect

func (h *ServerRequestsTotalStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerRequestsTotalStatsHandler) Describe

func (h *ServerRequestsTotalStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerRequestsTotalStatsHandler) HandleConn

func (h *ServerRequestsTotalStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerRequestsTotalStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ServerRequestsTotalStatsHandler) TagConn

func (h *ServerRequestsTotalStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerRequestsTotalStatsHandler) TagRPC

func (h *ServerRequestsTotalStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ServerResponsesTotalStatsHandler

type ServerResponsesTotalStatsHandler struct {
	// contains filtered or unexported fields
}

ServerResponsesTotalStatsHandler dedicated server-side StatsHandlerCollector that counts number of responses received.

func NewServerResponsesTotalStatsHandler

func NewServerResponsesTotalStatsHandler(vec *prometheus.CounterVec, opts ...StatsHandlerOption) *ServerResponsesTotalStatsHandler

NewServerResponsesTotalStatsHandler instantiates ServerResponsesTotalStatsHandler based on given CounterVec and options. The CounterVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed names are "grpc_method", "grpc_service", "grpc_client_user_agent" and "grpc_code".

func (*ServerResponsesTotalStatsHandler) Collect

func (h *ServerResponsesTotalStatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*ServerResponsesTotalStatsHandler) Describe

func (h *ServerResponsesTotalStatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*ServerResponsesTotalStatsHandler) HandleConn

func (h *ServerResponsesTotalStatsHandler) HandleConn(_ context.Context, _ stats.ConnStats)

HandleConn implements stats Handler interface.

func (*ServerResponsesTotalStatsHandler) HandleRPC

HandleRPC implements stats Handler interface.

func (*ServerResponsesTotalStatsHandler) TagConn

func (h *ServerResponsesTotalStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context

TagConn implements stats Handler interface.

func (*ServerResponsesTotalStatsHandler) TagRPC

func (h *ServerResponsesTotalStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context

TagRPC implements stats Handler interface.

type ShareableCollectorOption

type ShareableCollectorOption interface {
	ShareableOption
	CollectorOption
}

ShareableCollectorOption is CollectorOption extended with shareable capability.

func CollectorWithConstLabels

func CollectorWithConstLabels(constLabels prometheus.Labels) ShareableCollectorOption

CollectorWithConstLabels returns a ShareableCollectorOption which adds a set of constant labels to a collector.

func CollectorWithNamespace

func CollectorWithNamespace(namespace string) ShareableCollectorOption

CollectorWithNamespace returns a ShareableCollectorOption which sets namespace of a collector.

func CollectorWithUserAgent

func CollectorWithUserAgent(name, version string) ShareableCollectorOption

CollectorWithUserAgent ...

type ShareableOption

type ShareableOption interface {
	// contains filtered or unexported methods
}

ShareableOption is a simple wrapper for shareable method. It makes it possible to distinguish options reserved for direct usage, from those that are applicable on a set of objects.

type ShareableStatsHandlerOption

type ShareableStatsHandlerOption interface {
	ShareableOption
	StatsHandlerOption
}

ShareableStatsHandlerOption is StatsHandlerOption extended with shareable capability.

type StatsHandler

type StatsHandler struct {
	// contains filtered or unexported fields
}

StatsHandler wraps set of stats handlers and coordinate their execution. Additionally, it tags RPC requests with a common set of labels. That way it reduces context manipulation overhead and improves overall performance.

func ClientStatsHandler

func ClientStatsHandler(opts ...ShareableOption) *StatsHandler

ClientStatsHandler instantiates a default client-side coordinator together with every metric specific stats handler provided by this package.

func NewStatsHandler

func NewStatsHandler(handlers ...StatsHandlerCollector) *StatsHandler

NewStatsHandler allocates a new coordinator. It allows passing a various number of handlers that later it will iterate through.

func ServerStatsHandler

func ServerStatsHandler(opts ...ShareableOption) *StatsHandler

ServerStatsHandler instantiates a default server-side coordinator together with every metric specific stats handler provided by this package.

func (*StatsHandler) Collect

func (h *StatsHandler) Collect(in chan<- prometheus.Metric)

Collect implements prometheus Collector interface.

func (*StatsHandler) Describe

func (h *StatsHandler) Describe(in chan<- *prometheus.Desc)

Describe implements prometheus Collector interface.

func (*StatsHandler) HandleConn

func (h *StatsHandler) HandleConn(ctx context.Context, sts stats.ConnStats)

HandleConn implements stats Handler interface.

func (*StatsHandler) HandleRPC

func (h *StatsHandler) HandleRPC(ctx context.Context, sts stats.RPCStats)

HandleRPC implements stats Handler interface.

func (*StatsHandler) TagConn

TagConn implements stats Handler interface.

func (*StatsHandler) TagRPC

TagRPC implements stats Handler interface.

type StatsHandlerCollector

type StatsHandlerCollector interface {
	stats.Handler
	prometheus.Collector
}

StatsHandlerCollector is a simple wrapper for stats Handler and prometheus Collector interfaces.

type StatsHandlerOption

type StatsHandlerOption interface {
	// contains filtered or unexported methods
}

StatsHandlerOption configures a stats handler behaviour.

func StatsHandlerWithHandleRPCLabelsFunc

func StatsHandlerWithHandleRPCLabelsFunc(fn HandleRPCLabelFunc) StatsHandlerOption

StatsHandlerWithHandleRPCLabelsFunc allows to inject custom HandleRPCLabelFunc to a stats handler. It is not shareable because there little to no chance that all stats handlers need the same set of labels.

func StatsHandlerWithTagRPCLabelsFunc

func StatsHandlerWithTagRPCLabelsFunc(fn TagRPCLabelFunc) StatsHandlerOption

StatsHandlerWithTagRPCLabelsFunc allows to inject custom TagRPCLabelFunc to a stats handler. It is not shareable because of performance reasons. If all stats handlers require the same set of additional labels, it is better to implement a custom coordinator (e.g. by embedding StatsHandler) with self-defined TagRPC method. That way, it is guaranteed that new tagging execute only once and default implementation be overridden.

type TagRPCLabelFunc

type TagRPCLabelFunc func(context.Context, *stats.RPCTagInfo) context.Context

TagRPCLabelFunc type represents a function signature that can be passed into StatsHandlerWithTagRPCLabelsFunc.

Directories

Path Synopsis
internal
pb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL