perfinsights

package
v1.45.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

func NoLabels

func NoLabels() APIShapeLabels

NoLabels returns an empty APIShapeLabels map.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL