protosessions

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package protosessions provides functionality for aggregating hits into proto-sessions

Index

Constants

View Source
const BucketsPrefix = "sessions.buckets"

BucketsPrefix is the prefix for session buckets keys.

View Source
const CompactedHitsPrefix = "sessions.hits.compacted"

CompactedHitsPrefix is the prefix for the compacted hits key

View Source
const NextBucketKey = "sessions.buckets.next"

NextBucketKey is the key for the next session bucket.

View Source
const ProtoSessionHitsPrefix = "sessions.hits"

ProtoSessionHitsPrefix is the prefix for session hits keys.

View Source
const SessionStampByClientIDPrefix = "sessions.stamps.by.client.id"

SessionStampByClientIDPrefix is the prefix for session stamps by client ID keys.

View Source
const SessionStampPrefix = "sessions.stamps"

SessionStampPrefix is the prefix for session stamps keys.

Variables

This section is empty.

Functions

func BucketNumber

func BucketNumber(time time.Time, tickInterval time.Duration) int64

BucketNumber returns the bucket number for a given time and session duration.

func BucketsKey

func BucketsKey(bucketNumber int64) string

BucketsKey returns the key for the buckets of the session.

func BucketsParseNumber

func BucketsParseNumber(bucketKey string) (int64, error)

BucketsParseNumber parses the bucket number from a bucket key.

func CompactedHitsKey

func CompactedHitsKey(authoritativeClientID hits.ClientID) string

CompactedHitsKey returns the key for the compacted hits

func DoTick

func DoTick(closeTriggerCandidate Middleware)

DoTick is an e2e test utility function that performs a single tick of the closeTriggerMiddleware.

func ExpirationKey

func ExpirationKey(authoritativeClientID string) string

ExpirationKey returns the expiration key for a given client ID.

func Handler

func Handler(
	ctx context.Context,
	set storage.Set,
	kv storage.KV,
	encoder encoding.EncoderFunc,
	decoder encoding.DecoderFunc,
	middlewares []Middleware,
) func(_ map[string]string, h *hits.HitProcessingTask) *worker.Error

Handler returns a function that processes hit processing tasks.

func ProtoSessionHitsKey

func ProtoSessionHitsKey(authoritativeClientID hits.ClientID) string

ProtoSessionHitsKey returns the key for the session hits of the given authoritative client ID.

func SessionStampByClientIDKey

func SessionStampByClientIDKey(clientID string) string

SessionStampByClientIDKey returns the key for the session stamp by client ID.

func SessionStampKey

func SessionStampKey(sessionStamp string) string

SessionStampKey returns the key for the session stamp.

func StopCloseTrigger

func StopCloseTrigger(closeTriggerCandidate Middleware)

StopCloseTrigger is an e2e test utility function that stops the closeTriggerMiddleware.

Types

type Closer

type Closer interface {
	Close(protosession []*hits.Hit) error
}

Closer defines an interface for closing and processing hit sessions

func NewPrintingCloser

func NewPrintingCloser() Closer

NewPrintingCloser creates a new Closer implementation that prints the hits to stdout

type Context

type Context struct {
	StorageSet storage.Set
	StorageKV  storage.KV
	Encoder    encoding.EncoderFunc
	Decoder    encoding.DecoderFunc
	// contains filtered or unexported fields
}

Context holds the context for protosessions operations.

func (*Context) CollectAll

func (c *Context) CollectAll(authoritativeClientID hits.ClientID) ([]*hits.Hit, error)

CollectAll collects all hits for the given clientID from all middlewares and storage.

func (*Context) TriggerCleanup

func (c *Context) TriggerCleanup(authoritativeClientID hits.ClientID) error

TriggerCleanup triggers cleanup for the given clientID across all middlewares.

type Middleware

type Middleware interface {
	Handle(ctx *Context, hit *hits.Hit, next func() error) error
	// OnCleanup is called when the data for proto-session for given clientID should be cleared
	OnCleanup(ctx *Context, authoritativeClientID hits.ClientID) error
	OnCollect(ctx *Context, authoritativeClientID hits.ClientID) ([]*hits.Hit, error)

	OnPing(ctx *Context, pingTimestamp time.Time) error
}

Middleware defines an interface for task processing middleware

func NewCloseTriggerMiddleware

func NewCloseTriggerMiddleware(
	kv storage.KV,
	set storage.Set,
	sessionDuration,
	tickInterval time.Duration,
	closer Closer,
) Middleware

NewCloseTriggerMiddleware creates a new closer middleware for session management.

func NewCompactorMiddleware

func NewCompactorMiddleware(
	kv storage.KV,
	encoder encoding.EncoderFunc,
	decoder encoding.DecoderFunc,
	thresholdBytes uint32,
) Middleware

NewCompactorMiddleware creates a new middleware, that compresses bigger proto-sessions

func NewEvicterMiddleware

func NewEvicterMiddleware(kv storage.KV, rs receiver.Storage) Middleware

NewEvicterMiddleware creates a new evicter middleware instance.

Jump to

Keyboard shortcuts

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