Documentation ¶
Index ¶
- type HandlerWrapper
- type HandlerWrapperBuilder
- func (b *HandlerWrapperBuilder) Build() (result *HandlerWrapper, err error)
- func (b *HandlerWrapperBuilder) Path(value string) *HandlerWrapperBuilder
- func (b *HandlerWrapperBuilder) Registerer(value prometheus.Registerer) *HandlerWrapperBuilder
- func (b *HandlerWrapperBuilder) Subsystem(value string) *HandlerWrapperBuilder
- type TransportWrapper
- type TransportWrapperBuilder
- func (b *TransportWrapperBuilder) Build() (result *TransportWrapper, err error)
- func (b *TransportWrapperBuilder) Path(value string) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) Registerer(value prometheus.Registerer) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) Subsystem(value string) *TransportWrapperBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerWrapper ¶
type HandlerWrapper struct {
// contains filtered or unexported fields
}
HandlerWrapper contains the data and logic needed to wrap an HTTP handler with another one that generates Prometheus metrics.
type HandlerWrapperBuilder ¶
type HandlerWrapperBuilder struct {
// contains filtered or unexported fields
}
HandlerWrapperBuilder contains the data and logic needed to build a new metrics handler wrapper that creates HTTP handlers that generate the following Prometheus metrics:
<subsystem>_request_count - Number of API requests sent. <subsystem>_request_duration_sum - Total time to send API requests, in seconds. <subsystem>_request_duration_count - Total number of API requests measured. <subsystem>_request_duration_bucket - Number of API requests organized in buckets.
To set the subsystem prefix use the Subsystem method.
The duration buckets metrics contain an `le` label that indicates the upper bound. For example if the `le` label is `1` then the value will be the number of requests that were processed in less than one second.
The metrics will have the following labels:
method - Name of the HTTP method, for example GET or POST. path - Request path, for example /api/clusters_mgmt/v1/clusters. code - HTTP response code, for example 200 or 500. apiservice - API service name, for example ocm-clusters-service.
To calculate the average request duration during the last 10 minutes, for example, use a Prometheus expression like this:
rate(api_outbound_request_duration_sum[10m]) / rate(api_outbound_request_duration_count[10m])
In order to reduce the cardinality of the metrics the path label is modified to remove the identifiers of the objects. For example, if the original path is .../clusters/123 then it will be replaced by .../clusters/-, and the values will be accumulated. The line returned by the metrics server will be like this:
<subsystem>_request_count{code="200",method="GET",path="/api/clusters_mgmt/v1/clusters/-", apiservice="ocm-clusters-service"} 56
The meaning of that is that there were a total of 56 requests to get specific clusters, independently of the specific identifier of the cluster.
The value of the `code` label will be zero when sending the request failed without a response code, for example if it wasn't possible to open the connection, or if there was a timeout waiting for the response.
Note that setting this attribute is not enough to have metrics published, you also need to create and start a metrics server, as described in the documentation of the Prometheus library.
Don't create objects of this type directly; use the NewHandlerWrapper function instead.
func NewHandlerWrapper ¶
func NewHandlerWrapper() *HandlerWrapperBuilder
NewHandlerWrapper creates a new builder that can then be used to configure and create a new metrics handler wrapper.
func (*HandlerWrapperBuilder) Build ¶
func (b *HandlerWrapperBuilder) Build() (result *HandlerWrapper, err error)
Build uses the information stored in the builder to create a new handler wrapper.
func (*HandlerWrapperBuilder) Path ¶
func (b *HandlerWrapperBuilder) Path(value string) *HandlerWrapperBuilder
Path adds a path that will be accepted as a value for the `path` label. By default all the paths of the API are already added. This is intended for additional pads, for example the path for token requests. If those paths aren't explicitly specified here then their metrics will be accumulated in the `/-` path.
func (*HandlerWrapperBuilder) Registerer ¶
func (b *HandlerWrapperBuilder) Registerer(value prometheus.Registerer) *HandlerWrapperBuilder
Registerer sets the Prometheus registerer that will be used to register the metrics. The default is to use the default Prometheus registerer and there is usually no need to change that. This is intended for unit tests, where it is convenient to have a registerer that doesn't interfere with the rest of the system.
func (*HandlerWrapperBuilder) Subsystem ¶
func (b *HandlerWrapperBuilder) Subsystem(value string) *HandlerWrapperBuilder
Subsystem sets the name of the subsystem that will be used by to register the metrics with Prometheus. For example, if the value is `api_inbound` then the following metrics will be registered:
api_inbound_request_count - Number of API requests sent. api_inbound_request_duration_sum - Total time to send API requests, in seconds. api_inbound_request_duration_count - Total number of API requests measured. api_inbound_request_duration_bucket - Number of API requests organized in buckets.
This is mandatory.
type TransportWrapper ¶
type TransportWrapper struct {
// contains filtered or unexported fields
}
TransportWrapper contains the data and logic needed to wrap an HTTP round tripper with another one that generates Prometheus metrics.
func (*TransportWrapper) Wrap ¶
func (w *TransportWrapper) Wrap(transport http.RoundTripper) http.RoundTripper
Wrap creates a new round tripper that wraps the given one and generates the Prometheus metrics.
type TransportWrapperBuilder ¶
type TransportWrapperBuilder struct {
// contains filtered or unexported fields
}
TransportWrapperBuilder contains the data and logic needed to build a new metrics transport wrapper that creates HTTP round trippers that generate the following Prometheus metrics:
<subsystem>_request_count - Number of API requests sent. <subsystem>_request_duration_sum - Total time to send API requests, in seconds. <subsystem>_request_duration_count - Total number of API requests measured. <subsystem>_request_duration_bucket - Number of API requests organized in buckets.
To set the subsystem prefix use the Subsystem method.
The duration buckets metrics contain an `le` label that indicates the upper bound. For example if the `le` label is `1` then the value will be the number of requests that were processed in less than one second.
The metrics will have the following labels:
method - Name of the HTTP method, for example GET or POST. path - Request path, for example /api/clusters_mgmt/v1/clusters. code - HTTP response code, for example 200 or 500. apiservice - API service name, for example ocm-clusters-service.
To calculate the average request duration during the last 10 minutes, for example, use a Prometheus expression like this:
rate(api_outbound_request_duration_sum[10m]) / rate(api_outbound_request_duration_count[10m])
In order to reduce the cardinality of the metrics the path label is modified to remove the identifiers of the objects. For example, if the original path is .../clusters/123 then it will be replaced by .../clusters/-, and the values will be accumulated. The line returned by the metrics server will be like this:
<subsystem>_request_count{code="200",method="GET",path="/api/clusters_mgmt/v1/clusters/-", apiservice="ocm-clusters-service"} 56
The meaning of that is that there were a total of 56 requests to get specific clusters, independently of the specific identifier of the cluster.
The value of the `code` label will be zero when sending the request failed without a response code, for example if it wasn't possible to open the connection, or if there was a timeout waiting for the response.
Note that setting this attribute is not enough to have metrics published, you also need to create and start a metrics server, as described in the documentation of the Prometheus library.
Don't create objects of this type directly; use the NewTransportWrapper function instead.
func NewTransportWrapper ¶
func NewTransportWrapper() *TransportWrapperBuilder
NewTransportWrapper creates a new builder that can then be used to configure and create a new metrics round tripper.
func (*TransportWrapperBuilder) Build ¶
func (b *TransportWrapperBuilder) Build() (result *TransportWrapper, err error)
Build uses the information stored in the builder to create a new transport wrapper.
func (*TransportWrapperBuilder) Path ¶
func (b *TransportWrapperBuilder) Path(value string) *TransportWrapperBuilder
Path adds a path that will be accepted as a value for the `path` label. By default all the paths of the API are already added. This is intended for additional pads, for example the path for token requests. If those paths aren't explicitly specified here then their metrics will be accumulated in the `/-` path.
func (*TransportWrapperBuilder) Registerer ¶
func (b *TransportWrapperBuilder) Registerer(value prometheus.Registerer) *TransportWrapperBuilder
Registerer sets the Prometheus registerer that will be used to register the metrics. The default is to use the default Prometheus registerer and there is usually no need to change that. This is intended for unit tests, where it is convenient to have a registerer that doesn't interfere with the rest of the system.
func (*TransportWrapperBuilder) Subsystem ¶
func (b *TransportWrapperBuilder) Subsystem(value string) *TransportWrapperBuilder
Subsystem sets the name of the subsystem that will be used by to register the metrics with Prometheus. For example, if the value is `api_outbound` then the following metrics will be registered:
api_outbound_request_count - Number of API requests sent. api_outbound_request_duration_sum - Total time to send API requests, in seconds. api_outbound_request_duration_count - Total number of API requests measured. api_outbound_request_duration_bucket - Number of API requests organized in buckets.
This is mandatory.