Documentation
¶
Overview ¶
Package perfinsights defines middleware that reports the latency of API calls to Prometheus.
Unlike the gRPC middleware, the perf insights middleware records API calls by "shape", versus aggregating all calls simply by API kind. The shapes allow for more granular determination of the latency of API calls, and can be used to determine if there are any specific performance issues with specific API calls.
Index ¶
- Variables
- func ObserveShapeLatency(ctx context.Context, methodName string, shape APIShapeLabels, ...)
- func SetInContext(ctx context.Context, builder ShapeBuilder)
- func StreamServerInterceptor(isEnabled bool) grpc.StreamServerInterceptor
- func UnaryServerInterceptor(isEnabled bool) grpc.UnaryServerInterceptor
- type APIShapeLabel
- type APIShapeLabels
- type ShapeBuilder
Constants ¶
This section is empty.
Variables ¶
var APIShapeLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: "spicedb", Subsystem: "perf_insights", Name: "api_shape_latency_seconds", Help: "The latency of API calls, by shape", Buckets: nil, NativeHistogramBucketFactor: 1.1, }, append([]string{"api_kind"}, allLabels...))
APIShapeLatency is the metric that SpiceDB uses to keep track of the latency of API calls, by shape. The "shape" of an API call is defined as the portions of the API call that are not the specific object IDs, e.g. the resource type, the relation, the subject type, etc.
NOTE: This metric is a *native* histogram, which means that instead of predefined the buckets, it uses a factor to determine the buckets. This is useful for latency-based metrics, as the latency can vary widely and having a fixed set of buckets can lead to imprecise results.
To use make use of native histograms, a special flag must be set on Prometheus: https://prometheus.io/docs/prometheus/latest/feature_flags/#native-histograms
Functions ¶
func ObserveShapeLatency ¶
func ObserveShapeLatency(ctx context.Context, methodName string, shape APIShapeLabels, duration time.Duration)
ObserveShapeLatency observes the latency of the API call with the given shape.
func SetInContext ¶
func SetInContext(ctx context.Context, builder ShapeBuilder)
SetInContext sets the ShapeBuilder in the context.
func StreamServerInterceptor ¶
func StreamServerInterceptor(isEnabled bool) grpc.StreamServerInterceptor
StreamServerInterceptor returns a gRPC server-side interceptor that provides reporting for Streaming RPCs.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(isEnabled bool) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a gRPC server-side interceptor that provides reporting for Unary RPCs.
Types ¶
type APIShapeLabel ¶
type APIShapeLabel string
const ( ResourceTypeLabel APIShapeLabel = "resource_type" ResourceRelationLabel APIShapeLabel = "resource_relation" SubjectTypeLabel APIShapeLabel = "subject_type" SubjectRelationLabel APIShapeLabel = "subject_relation" NameLabel APIShapeLabel = "name" FilterLabel APIShapeLabel = "filter" )
type APIShapeLabels ¶
type APIShapeLabels map[APIShapeLabel]any
APIShapeLabels is a map of APIShapeLabel to any value.
type ShapeBuilder ¶
type ShapeBuilder func() APIShapeLabels
ShapeBuilder is a function that returns a slice of strings representing the shape of the API call. This is used to report the shape of the API call to Prometheus.