middleware

package
v0.30.38 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeySubject     = authmw.ContextKeySubject
	ContextKeyAuthMethod  = authmw.ContextKeyAuthMethod
	ContextKeyTenantGrant = authmw.ContextKeyTenantGrant
)

Variables

View Source
var (
	AuthMiddleware         = authmw.AuthMiddleware
	GetSubject             = authmw.GetSubject
	GetAuthMethod          = authmw.GetAuthMethod
	TenantGrantFromContext = authmw.TenantGrantFromContext
)

Functions

func MetricsMiddleware

func MetricsMiddleware(m *Metrics) func(http.Handler) http.Handler

MetricsMiddleware creates a middleware that collects request metrics

func RateLimitMiddleware

func RateLimitMiddleware(cfg *config.Config, limiter *RateLimiter) func(http.Handler) http.Handler

RateLimitMiddleware creates a rate limiting middleware

Types

type ContextKey

type ContextKey = authmw.ContextKey

type JWTClaims

type JWTClaims = authmw.JWTClaims

type Metrics

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

Metrics collects server metrics for observability

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a new metrics collector

func (*Metrics) GetSnapshot

func (m *Metrics) GetSnapshot() MetricsSnapshot

GetSnapshot returns a snapshot of current metrics

func (*Metrics) PrometheusFormat

func (m *Metrics) PrometheusFormat() string

PrometheusFormat returns metrics in Prometheus exposition format.

func (*Metrics) PrometheusFormatSnapshot

func (m *Metrics) PrometheusFormatSnapshot(snapshot MetricsSnapshot) string

PrometheusFormatSnapshot renders an already-built snapshot. Use this when the caller has augmented the snapshot (e.g. with blob usage figures) before rendering, to avoid a second GetSnapshot call.

func (*Metrics) RecordCacheHit

func (m *Metrics) RecordCacheHit()

RecordCacheHit records a cache hit

func (*Metrics) RecordCacheMiss

func (m *Metrics) RecordCacheMiss()

RecordCacheMiss records a cache miss

func (*Metrics) RecordEntityCreate

func (m *Metrics) RecordEntityCreate()

RecordEntityCreate records an entity creation

func (*Metrics) RecordEntityDelete

func (m *Metrics) RecordEntityDelete()

RecordEntityDelete records an entity deletion

func (*Metrics) RecordEntityList

func (m *Metrics) RecordEntityList()

RecordEntityList records an entity list operation

func (*Metrics) RecordEntityRead

func (m *Metrics) RecordEntityRead()

RecordEntityRead records an entity read

func (*Metrics) RecordEntityUpdate

func (m *Metrics) RecordEntityUpdate()

RecordEntityUpdate records an entity update

func (*Metrics) RecordGraphQuery

func (m *Metrics) RecordGraphQuery()

RecordGraphQuery records a graph query

func (*Metrics) RecordOQLQuery

func (m *Metrics) RecordOQLQuery()

RecordOQLQuery records an OQL query

func (*Metrics) RecordSearchQuery

func (m *Metrics) RecordSearchQuery()

RecordSearchQuery records a search query

type MetricsSnapshot

type MetricsSnapshot struct {
	Uptime         time.Duration
	RequestsTotal  uint64
	RequestsByPath map[string]uint64
	RequestsByCode map[int]uint64
	RequestErrors  uint64
	ActiveRequests int64
	LatencyAvgMs   float64
	LatencySumSec  float64 // total latency in seconds (for Prometheus _sum)
	LatencyCount   uint64  // total observations (for Prometheus _count)
	LatencyBuckets map[string]uint64
	EntityCreates  uint64
	EntityReads    uint64
	EntityUpdates  uint64
	EntityDeletes  uint64
	EntityLists    uint64
	CacheHits      uint64
	CacheMisses    uint64
	SearchQueries  uint64
	OQLQueries     uint64
	GraphQueries   uint64

	// Blob store usage — populated by the server from the UsageSampler cache.
	// All zero when the blob store is disabled or the sampler has not yet run.
	BlobEnabled   bool
	BlobBlobCount int64
	BlobKeyCount  int64
	BlobBytes     int64
	BlobTenants   int64
}

MetricsSnapshot is a point-in-time snapshot of metrics

type RateLimiter

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

RateLimiter implements a fixed-window rate limiter. This allows up to 2x burst at window boundaries; a sliding-window approach would prevent that but adds complexity. Acceptable for the current use case.

func NewRateLimiter

func NewRateLimiter(cfg *config.Config) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) (bool, int, time.Time)

Allow checks if a request is allowed and increments the counter

func (*RateLimiter) Stop

func (rl *RateLimiter) Stop()

Stop stops the rate limiter cleanup goroutine

type TenantGrant

type TenantGrant = authmw.TenantGrant

Jump to

Keyboard shortcuts

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