promgrpc

package module
v4.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 11 Imported by: 4

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

func NewClientMessageReceivedSizeHistogramVec

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

func NewClientMessageSentSizeHistogramVec

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

func NewClientMessagesReceivedTotalCounterVec

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

func NewClientMessagesSentTotalCounterVec

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

func NewClientRequestDurationHistogramVec

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

func NewClientRequestsInFlightGaugeVec

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

func NewClientRequestsTotalCounterVec

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

func NewClientResponsesTotalCounterVec

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

NewClientResponsesTotalCounterVec allocates a new Prometheus CounterVec for the client and given set of options.

func NewServerConnectionsGaugeVec

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

func NewServerMessageReceivedSizeHistogramVec

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

func NewServerMessageSentSizeHistogramVec

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

func NewServerMessagesReceivedTotalCounterVec

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

func NewServerMessagesSentTotalCounterVec

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

func NewServerRequestDurationHistogramVec

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

func NewServerRequestsInFlightGaugeVec

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

func NewServerRequestsTotalCounterVec

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

func NewServerResponsesTotalCounterVec

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

NewServerResponsesTotalCounterVec allocates a new Prometheus CounterVec for the server and given set of options.

Types

type ClientConnectionsStatsHandler

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

func NewClientConnectionsStatsHandler

func NewClientConnectionsStatsHandler(vec *prometheus.GaugeVec) *ClientConnectionsStatsHandler

NewClientConnectionsStatsHandler ...

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 HandleRPC processes the RPC stats.

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
}

func NewClientMessageReceivedSizeStatsHandler

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

NewMessageReceivedSizeStatsHandler ...

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
}

func NewClientMessageSentSizeStatsHandler

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

NewMessageSentSizeStatsHandler ...

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
}

func NewClientMessagesReceivedTotalStatsHandler

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

NewClientMessagesReceivedTotalStatsHandler ... The GaugeVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed labelsFn names are "fail_fast", "handler", "service" and "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
}

func NewClientMessagesSentTotalStatsHandler

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

NewClientMessagesSentTotalStatsHandler ... The GaugeVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed labelsFn names are "fail_fast", "handler", "service".

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
}

func NewClientRequestDurationStatsHandler

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

NewClientRequestDurationStatsHandler ...

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
}

func NewClientRequestsInFlightStatsHandler

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

NewClientRequestsInFlightStatsHandler ...

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

type ClientRequestsTotalStatsHandler

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

func NewClientRequestsTotalStatsHandler

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

NewClientRequestsTotalStatsHandler ... The GaugeVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed labelsFn names are "fail_fast", "handler", "service".

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 is responsible for counting number of incoming (server side) or outgoing (client side) requests.

func NewClientResponsesTotalStatsHandler

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

NewClientResponsesTotalStatsHandler ...

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
}

func NewServerConnectionsStatsHandler

func NewServerConnectionsStatsHandler(vec *prometheus.GaugeVec) *ServerConnectionsStatsHandler

NewConnectionsStatsHandler ...

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)

HandleRPC processes the RPC stats.

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
}

func NewServerMessageReceivedSizeStatsHandler

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

NewServerMessageReceivedSizeStatsHandler ...

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
}

func NewServerMessageSentSizeStatsHandler

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

NewServerMessageSentSizeStatsHandler ...

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
}

func NewServerMessagesReceivedTotalStatsHandler

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

NewServerMessagesReceivedTotalStatsHandler ... The GaugeVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed labelsFn names are "fail_fast", "handler", "service" and "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
}

func NewServerMessagesSentTotalStatsHandler

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

NewServerMessagesSentTotalStatsHandler ... The GaugeVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed labelsFn names are "fail_fast", "handler", "service".

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
}

func NewServerRequestDurationStatsHandler

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

NewServerRequestDurationStatsHandler ...

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
}

func NewServerRequestsInFlightStatsHandler

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

NewServerRequestsInFlightStatsHandler ...

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
}

func NewServerRequestsTotalStatsHandler

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

NewServerRequestsTotalStatsHandler ... The GaugeVec must have zero, one, two, three or four non-const non-curried labels. For those, the only allowed labelsFn names are "fail_fast", "handler", "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 is responsible for counting number of incoming (server side) or outgoing (client side) requests.

func NewServerResponsesTotalStatsHandler

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

NewServerResponsesTotalStatsHandler ...

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

Directories

Path Synopsis
internal
pb

Jump to

Keyboard shortcuts

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