Documentation ¶
Index ¶
- Constants
- Variables
- func AddMiddleware(ctx context.Context, s *backend.DataSourceInstanceSettings) (httpclient.Options, error)
- func FromStatus(status backend.Status) backend.ErrorSource
- func Middleware() httpclient.Middleware
- func NewClient(opts ...httpclient.Options) (*http.Client, error)
- func RoundTripper(_ httpclient.Options, next http.RoundTripper) http.RoundTripper
- func SanitizeLabelName(name string) (string, error)
- type Collector
- type Duration
- type DurationKey
- type Endpoint
- type Metrics
- type MetricsWrapper
- func (ds *MetricsWrapper) CallResource(ctx context.Context, req *backend.CallResourceRequest, ...) error
- func (ds *MetricsWrapper) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
- func (ds *MetricsWrapper) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- type Source
- type Status
Constants ¶
const ( StatusOK Status = "ok" StatusError Status = "error" EndpointHealth Endpoint = "health" EndpointQuery Endpoint = "query" EndpointResource Endpoint = "resource" SourceDownstream Source = "downstream" SourcePlugin Source = "plugin" )
const DataSourceSLOMiddlewareName = "slo"
DataSourceSLOMiddlewareName is the middleware name used by Middleware.
Variables ¶
var Logger = log.DefaultLogger
Functions ¶
func AddMiddleware ¶ added in v0.235.0
func AddMiddleware(ctx context.Context, s *backend.DataSourceInstanceSettings) (httpclient.Options, error)
AddMiddleware adds the middleware to the http client options.
func FromStatus ¶ added in v0.235.0
func FromStatus(status backend.Status) backend.ErrorSource
FromStatus returns the error source from backend status
func Middleware ¶
func Middleware() httpclient.Middleware
Middleware applies the duration to the context.
func NewClient ¶ added in v0.235.0
func NewClient(opts ...httpclient.Options) (*http.Client, error)
NewClient wraps the existing http client constructor and adds the duration middleware
func RoundTripper ¶
func RoundTripper(_ httpclient.Options, next http.RoundTripper) http.RoundTripper
RoundTripper captures the duration of the request in the context
func SanitizeLabelName ¶
Types ¶
type Collector ¶ added in v0.235.0
type Collector interface { CollectDuration(source Source, status Status, statusCode int, duration float64) WithEndpoint(endpoint Endpoint) Collector }
func NewMetrics ¶ added in v0.235.0
NewMetrics creates a new Metrics instance
type Duration ¶ added in v0.235.0
type Duration struct {
// contains filtered or unexported fields
}
Duration is stored in the Context and used to collect metrics
func NewDuration ¶ added in v0.235.0
type DurationKey ¶ added in v0.235.0
type DurationKey struct{}
DurationKey is a key for storing the duration in the context
type Endpoint ¶ added in v0.235.0
type Endpoint string
Endpoint is the endpoint of the request (health, query, resource)
type Metrics ¶ added in v0.235.0
Metrics is an abstraction for collecting metrics
func (Metrics) CollectDuration ¶ added in v0.235.0
CollectDuration collects the duration as a metric
func (Metrics) WithEndpoint ¶ added in v0.235.0
WithEndpoint returns a new Metrics instance with the given endpoint
type MetricsWrapper ¶ added in v0.235.0
type MetricsWrapper struct { Name string Type string Metrics Collector // contains filtered or unexported fields }
MetricsWrapper is a wrapper for a plugin that collects metrics
func NewMetricsWrapper ¶ added in v0.235.0
func NewMetricsWrapper(plugin any, s backend.DataSourceInstanceSettings, c ...Collector) *MetricsWrapper
NewMetricsWrapper creates a new MetricsWrapper instance
func (*MetricsWrapper) CallResource ¶ added in v0.235.0
func (ds *MetricsWrapper) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error
CallResource calls the CallResourceHandler and collects metrics
func (*MetricsWrapper) CheckHealth ¶ added in v0.235.0
func (ds *MetricsWrapper) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
CheckHealth calls the CheckHealthHandler and collects metrics
func (*MetricsWrapper) QueryData ¶ added in v0.235.0
func (ds *MetricsWrapper) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
QueryData calls the QueryDataHandler and collects metrics