metrics

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: Apache-2.0 Imports: 25 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")
	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}

	// 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(),
	}
)
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(service string) func(next http.Handler) http.Handler

HTTPMetricsHandler creates a metrics middleware for incoming HTTP requests

func HTTPMetricsRoundTripper

func HTTPMetricsRoundTripper(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) (http.Handler, error)

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

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 string)

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

func SetConfigChecksum

func SetConfigChecksum(service string, checksum uint64)

SetConfigChecksum creates the configuration checksum metric. You must call RegisterInfoMetrics to have this exported

func SetConfigInfo

func SetConfigInfo(service string, success bool)

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

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 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
y or Y : Canonical URL