metrics

package
Version: v0.15.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package metrics contains support for OpenCensus distributed metrics.

Index

Constants

This section is empty.

Variables

View Source
var (
	TagKeyHTTPMethod  = tag.MustNewKey("http_method")
	TagKeyService     = tag.MustNewKey("service")
	TagConfigID       = tag.MustNewKey("config_id")
	TagKeyGRPCService = tag.MustNewKey("grpc_service")
	TagKeyGRPCMethod  = tag.MustNewKey("grpc_method")
	TagKeyHost        = tag.MustNewKey("host")
	TagKeyDestination = tag.MustNewKey("destination")

	TagKeyStorageOperation = tag.MustNewKey("operation")
	TagKeyStorageResult    = tag.MustNewKey("result")
	TagKeyStorageBackend   = tag.MustNewKey("backend")
)

The following tags are applied to stats recorded by this package.

View Source
var (
	DefaulHTTPSizeDistribution = view.Distribution(
		1, 256, 512, 1024, 2048, 8192, 16384, 32768, 65536, 131072, 262144,
		524288, 1048576, 2097152, 4194304, 8388608)
	DefaultHTTPLatencyDistrubtion = view.Distribution(
		1, 2, 5, 7, 10, 25, 500, 750, 100, 250, 500, 750, 1000, 2500, 5000,
		7500, 10000, 25000, 50000, 75000, 100000)

	DefaultMillisecondsDistribution = ocgrpc.DefaultMillisecondsDistribution
)

Default distributions used by views in this package.

View Source
var (
	// GRPCClientViews contains opencensus views for GRPC Client metrics.
	GRPCClientViews = []*view.View{
		GRPCClientRequestCountView,
		GRPCClientRequestDurationView,
		GRPCClientResponseSizeView,
		GRPCClientRequestSizeView,
	}
	// GRPCServerViews contains opencensus views for GRPC Server metrics.
	GRPCServerViews = []*view.View{
		GRPCServerRequestCountView,
		GRPCServerRequestDurationView,
		GRPCServerResponseSizeView,
		GRPCServerRequestSizeView,
	}

	// GRPCServerRequestCountView is an OpenCensus view which counts GRPC Server
	// requests by pomerium service, grpc service, grpc method, and status
	GRPCServerRequestCountView = &view.View{
		Name:        "grpc/server/requests_total",
		Measure:     ocgrpc.ServerLatency,
		Description: "Total grpc Requests",
		TagKeys:     []tag.Key{TagKeyService, TagKeyGRPCMethod, ocgrpc.KeyServerStatus, TagKeyGRPCService},
		Aggregation: view.Count(),
	}

	// GRPCServerRequestDurationView is an OpenCensus view which tracks GRPC Server
	// request duration by pomerium service, grpc service, grpc method, and status
	GRPCServerRequestDurationView = &view.View{
		Name:        "grpc/server/request_duration_ms",
		Measure:     ocgrpc.ServerLatency,
		Description: "grpc Request duration in ms",
		TagKeys:     []tag.Key{TagKeyService, TagKeyGRPCMethod, ocgrpc.KeyServerStatus, TagKeyGRPCService},
		Aggregation: DefaultMillisecondsDistribution,
	}

	// GRPCServerResponseSizeView is an OpenCensus view which tracks GRPC Server
	// response size by pomerium service, grpc service, grpc method, and status
	GRPCServerResponseSizeView = &view.View{
		Name:        "grpc/server/response_size_bytes",
		Measure:     ocgrpc.ServerSentBytesPerRPC,
		Description: "grpc Server Response Size in bytes",
		TagKeys:     []tag.Key{TagKeyService, TagKeyGRPCMethod, ocgrpc.KeyServerStatus, TagKeyGRPCService},
		Aggregation: grpcSizeDistribution,
	}

	// GRPCServerRequestSizeView is an OpenCensus view which tracks GRPC Server
	// request size by pomerium service, grpc service, grpc method, and status
	GRPCServerRequestSizeView = &view.View{
		Name:        "grpc/server/request_size_bytes",
		Measure:     ocgrpc.ServerReceivedBytesPerRPC,
		Description: "grpc Server Request Size in bytes",
		TagKeys:     []tag.Key{TagKeyService, TagKeyGRPCMethod, ocgrpc.KeyServerStatus, TagKeyGRPCService},
		Aggregation: grpcSizeDistribution,
	}

	// GRPCClientRequestCountView is an OpenCensus view which tracks GRPC Client
	// requests by pomerium service, target host, grpc service, grpc method, and status
	GRPCClientRequestCountView = &view.View{
		Name:        "grpc/client/requests_total",
		Measure:     ocgrpc.ClientRoundtripLatency,
		Description: "Total grpc Client Requests",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyGRPCMethod, TagKeyGRPCService, ocgrpc.KeyClientStatus},
		Aggregation: view.Count(),
	}

	// GRPCClientRequestDurationView is an OpenCensus view which tracks GRPC Client
	// request duration by pomerium service, target host, grpc service, grpc method, and status
	GRPCClientRequestDurationView = &view.View{
		Name:        "grpc/client/request_duration_ms",
		Measure:     ocgrpc.ClientRoundtripLatency,
		Description: "grpc Client Request duration in ms",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyGRPCMethod, TagKeyGRPCService, ocgrpc.KeyClientStatus},
		Aggregation: DefaultMillisecondsDistribution,
	}

	// GRPCClientResponseSizeView  is an OpenCensus view which tracks GRPC Client
	// response size by pomerium service, target host, grpc service, grpc method, and status
	GRPCClientResponseSizeView = &view.View{
		Name:        "grpc/client/response_size_bytes",
		Measure:     ocgrpc.ClientReceivedBytesPerRPC,
		Description: "grpc Client Response Size in bytes",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyGRPCMethod, TagKeyGRPCService, ocgrpc.KeyClientStatus},
		Aggregation: grpcSizeDistribution,
	}

	// GRPCClientRequestSizeView  is an OpenCensus view which tracks GRPC Client
	// request size by pomerium service, target host, grpc service, grpc method, and status
	GRPCClientRequestSizeView = &view.View{
		Name:        "grpc/client/request_size_bytes",
		Measure:     ocgrpc.ClientSentBytesPerRPC,
		Description: "grpc Client Request Size in bytes",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyGRPCMethod, TagKeyGRPCService, ocgrpc.KeyClientStatus},
		Aggregation: grpcSizeDistribution,
	}
)

GRPC Views

View Source
var (
	// HTTPClientViews contains opencensus views for HTTP Client metrics.
	HTTPClientViews = []*view.View{
		HTTPClientRequestCountView,
		HTTPClientRequestDurationView,
		HTTPClientResponseSizeView,
	}
	// HTTPServerViews contains opencensus views for HTTP Server metrics.
	HTTPServerViews = []*view.View{
		HTTPServerRequestCountView,
		HTTPServerRequestDurationView,
		HTTPServerRequestSizeView,
		HTTPServerResponseSizeView,
	}

	// HTTPServerRequestCountView is an OpenCensus View that tracks HTTP server
	// requests by pomerium service, host, method and status
	HTTPServerRequestCountView = &view.View{
		Name:        "http/server/requests_total",
		Measure:     ochttp.ServerLatency,
		Description: "Total HTTP Requests",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode},
		Aggregation: view.Count(),
	}

	// HTTPServerRequestDurationView is an OpenCensus view that tracks HTTP
	// server request duration by pomerium service, host, method and status
	HTTPServerRequestDurationView = &view.View{
		Name:        "http/server/request_duration_ms",
		Measure:     ochttp.ServerLatency,
		Description: "HTTP Request duration in ms",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode},
		Aggregation: DefaultHTTPLatencyDistrubtion,
	}

	// HTTPServerRequestSizeView is an OpenCensus view that tracks HTTP server
	// request size by pomerium service, host and method
	HTTPServerRequestSizeView = &view.View{
		Name:        "http/server/request_size_bytes",
		Measure:     ochttp.ServerRequestBytes,
		Description: "HTTP Server Request Size in bytes",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod},
		Aggregation: DefaulHTTPSizeDistribution,
	}

	// HTTPServerResponseSizeView is an OpenCensus view that tracks HTTP server
	// response size by pomerium service, host, method and status
	HTTPServerResponseSizeView = &view.View{
		Name:        "http/server/response_size_bytes",
		Measure:     ochttp.ServerResponseBytes,
		Description: "HTTP Server Response Size in bytes",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode},
		Aggregation: DefaulHTTPSizeDistribution,
	}

	// HTTPClientRequestCountView is an OpenCensus View that tracks HTTP client
	// requests by pomerium service, destination, host, method and status
	HTTPClientRequestCountView = &view.View{
		Name:        "http/client/requests_total",
		Measure:     ochttp.ClientRoundtripLatency,
		Description: "Total HTTP Client Requests",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode, TagKeyDestination},
		Aggregation: view.Count(),
	}

	// HTTPClientRequestDurationView is an OpenCensus view that tracks HTTP
	// client request duration by pomerium service, destination, host, method and status
	HTTPClientRequestDurationView = &view.View{
		Name:        "http/client/request_duration_ms",
		Measure:     ochttp.ClientRoundtripLatency,
		Description: "HTTP Client Request duration in ms",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode, TagKeyDestination},
		Aggregation: DefaultHTTPLatencyDistrubtion,
	}

	// HTTPClientResponseSizeView is an OpenCensus view that tracks HTTP client
	// esponse size by pomerium service, destination, host, method and status
	HTTPClientResponseSizeView = &view.View{
		Name:        "http/client/response_size_bytes",
		Measure:     ochttp.ClientReceivedBytes,
		Description: "HTTP Client Response Size in bytes",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode, TagKeyDestination},
		Aggregation: DefaulHTTPSizeDistribution,
	}

	// HTTPClientRequestSizeView is an OpenCensus view that tracks HTTP client
	// request size by pomerium service, destination, host and method
	HTTPClientRequestSizeView = &view.View{
		Name:        "http/client/response_size_bytes",
		Measure:     ochttp.ClientSentBytes,
		Description: "HTTP Client Response Size in bytes",
		TagKeys:     []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, TagKeyDestination},
		Aggregation: DefaulHTTPSizeDistribution,
	}
)

HTTP Views

View Source
var (
	// InfoViews contains opencensus views for informational metrics about
	// pomerium itself.
	InfoViews = []*view.View{
		ConfigLastReloadView,
		ConfigLastReloadSuccessView,
		IdentityManagerLastRefreshView,
		ConfigDBVersionView,
		ConfigDBErrorsView,
	}

	// ConfigDBVersionView contains last databroker config version that was processed
	ConfigDBVersionView = &view.View{
		Name:        configDBVersion.Name(),
		Description: configDBVersion.Description(),
		Measure:     configDBVersion,
		TagKeys:     []tag.Key{TagKeyService, TagConfigID},
		Aggregation: view.LastValue(),
	}

	// ConfigDBErrorsView contains list of errors encountered while parsing this databroker config
	ConfigDBErrorsView = &view.View{
		Name:        configDBErrors.Name(),
		Description: configDBErrors.Description(),
		Measure:     configDBErrors,
		TagKeys:     []tag.Key{TagKeyService, TagConfigID},
		Aggregation: view.LastValue(),
	}

	// ConfigLastReloadView contains the timestamp the configuration was last
	// reloaded, labeled by service.
	ConfigLastReloadView = &view.View{
		Name:        configLastReload.Name(),
		Description: configLastReload.Description(),
		Measure:     configLastReload,
		TagKeys:     []tag.Key{TagKeyService},
		Aggregation: view.LastValue(),
	}

	// ConfigLastReloadSuccessView contains the result of the last configuration
	// reload, labeled by service.
	ConfigLastReloadSuccessView = &view.View{
		Name:        configLastReloadSuccess.Name(),
		Description: configLastReloadSuccess.Description(),
		Measure:     configLastReloadSuccess,
		TagKeys:     []tag.Key{TagKeyService},
		Aggregation: view.LastValue(),
	}

	// IdentityManagerLastRefreshView contains the timestamp the identity manager
	// was last refreshed, labeled by service.
	IdentityManagerLastRefreshView = &view.View{
		Name:        identityManagerLastRefresh.Name(),
		Description: identityManagerLastRefresh.Description(),
		Measure:     identityManagerLastRefresh,
		Aggregation: view.LastValue(),
	}
)
View Source
var (
	// StorageViews contains opencensus views for storage system metrics
	StorageViews = []*view.View{StorageOperationDurationView}

	// StorageOperationDurationView is an OpenCensus view that tracks storage client
	// latency by operation, result and backend
	StorageOperationDurationView = &view.View{
		Name:        storageOperationDuration.Name(),
		Description: storageOperationDuration.Description(),
		Measure:     storageOperationDuration,
		TagKeys:     []tag.Key{TagKeyStorageOperation, TagKeyStorageResult, TagKeyStorageBackend, TagKeyService},
		Aggregation: DefaultMillisecondsDistribution,
	}
)

DefaultViews are a set of default views to view HTTP and GRPC metrics.

Functions

func AddPolicyCountCallback

func AddPolicyCountCallback(service string, f func() int64)

AddPolicyCountCallback sets the function to call when exporting the policy count metric. You must call RegisterInfoMetrics to have this exported

func AddRedisMetrics added in v0.7.0

func AddRedisMetrics(stats func() *redis.PoolStats)

AddRedisMetrics registers a metrics handler against a redis Client's PoolStats() method

func GRPCClientInterceptor

func GRPCClientInterceptor(service string) grpc.UnaryClientInterceptor

GRPCClientInterceptor creates a UnaryClientInterceptor which updates the RPC context with metric tag metadata

TODO: This handler will NOT currently propagate B3 headers to upstream servers. See GRPCServerStatsHandler for changes required

func HTTPMetricsHandler

func HTTPMetricsHandler(getInstallationID func() string, service string) func(next http.Handler) http.Handler

HTTPMetricsHandler creates a metrics middleware for incoming HTTP requests

func HTTPMetricsRoundTripper

func HTTPMetricsRoundTripper(getInstallationID func() string, service string, destination string) func(next http.RoundTripper) http.RoundTripper

HTTPMetricsRoundTripper creates a metrics tracking tripper for outbound HTTP Requests

func PrometheusHandler

func PrometheusHandler(envoyURL *url.URL, installationID string) (http.Handler, error)

PrometheusHandler creates an exporter that exports stats to Prometheus and returns a handler suitable for exporting metrics.

func RecordAutocertCertificates added in v0.14.0

func RecordAutocertCertificates(certs []tls.Certificate)

RecordAutocertCertificates records the next timestamp an autocert certificate will expire.

func RecordAutocertRenewal added in v0.14.0

func RecordAutocertRenewal()

RecordAutocertRenewal records an autocert renewal.

func RecordIdentityManagerLastRefresh added in v0.14.0

func RecordIdentityManagerLastRefresh()

RecordIdentityManagerLastRefresh records that the identity manager refreshed users and groups.

func RecordStorageOperation added in v0.10.0

func RecordStorageOperation(ctx context.Context, tags *StorageOperationTags, duration time.Duration)

RecordStorageOperation records the duration of a storage operation with the corresponding tags

func RegisterInfoMetrics

func RegisterInfoMetrics()

RegisterInfoMetrics registers non-view based metrics registry globally for export

func SetBuildInfo

func SetBuildInfo(service, hostname, envoyVersion string)

SetBuildInfo records the pomerium build info. You must call RegisterInfoMetrics to have this exported

func SetConfigInfo

func SetConfigInfo(ctx context.Context, service, configName string, checksum uint64, success bool)

SetConfigInfo records the status, checksum and timestamp of a configuration reload. You must register InfoViews or the related config views before calling

func SetDBConfigInfo added in v0.14.0

func SetDBConfigInfo(ctx context.Context, service, configID string, version uint64, errCount int64)

SetDBConfigInfo records status, databroker version and error count while parsing the configuration from a databroker

func SetDBConfigRejected added in v0.14.0

func SetDBConfigRejected(ctx context.Context, service, configID string, version uint64, err error)

SetDBConfigRejected records that a certain databroker config version has been rejected

Types

type GRPCServerMetricsHandler added in v0.9.0

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

GRPCServerMetricsHandler implements a telemetry tagRPCHandler methods for metrics

func NewGRPCServerMetricsHandler added in v0.9.0

func NewGRPCServerMetricsHandler(service string) *GRPCServerMetricsHandler

NewGRPCServerMetricsHandler creates a new GRPCServerStatsHandler for a pomerium service

func (*GRPCServerMetricsHandler) TagRPC added in v0.9.0

TagRPC handles adding any metrics related values to the incoming context

type ProcessCollector added in v0.14.0

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

A ProcessCollector collects stats about a process.

func NewProcessCollector added in v0.14.0

func NewProcessCollector(name string) *ProcessCollector

NewProcessCollector creates a new ProcessCollector.

func (*ProcessCollector) Measure added in v0.14.0

func (pc *ProcessCollector) Measure(ctx context.Context, pid int) error

Measure measures the stats for a process.

func (*ProcessCollector) Views added in v0.14.0

func (pc *ProcessCollector) Views() []*view.View

Views returns the views for the process collector.

type StorageOperationTags added in v0.10.0

type StorageOperationTags struct {
	Operation string
	Error     error
	Backend   string
}

StorageOperationTags contains tags to apply when recording a storage operation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL