receiver

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package receiver implements the receiver service.

Index

Constants

View Source
const (
	// HitProtocolMetadataKey is the key used to store the protocol ID in the hit metadata
	HitProtocolMetadataKey string = "protocol"
)

Variables

View Source
var ClientIDNotEmpty = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if hit.ClientID == "" || hit.AuthoritativeClientID == "" {
		return fmt.Errorf("hit.ClientID and hit.AuthoritativeClientID can not be empty")
	}
	return nil
})

ClientIDNotEmpty validates that both ClientID and AuthoritativeClientID are not empty.

View Source
var EventNameNotEmpty = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if hit.EventName == "" {
		return fmt.Errorf("hit.EventName can not be empty")
	}
	return nil
})

EventNameNotEmpty validates that EventName is not empty.

View Source
var HitBodyNotNil = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if hit.MustParsedRequest().Body == nil {
		return fmt.Errorf("hit.Body can not be nil")
	}
	return nil
})

HitBodyNotNil validates that Body is not nil.

View Source
var HitHeadersNotEmpty = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if len(hit.MustParsedRequest().Headers) == 0 {
		return fmt.Errorf("hit.Headers can not be empty")
	}
	return nil
})

HitHeadersNotEmpty validates that Headers are not empty.

View Source
var HitHostNotEmpty = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if hit.MustParsedRequest().Host == "" {
		return fmt.Errorf("hit.Host can not be empty")
	}
	return nil
})

HitHostNotEmpty validates that Host is not empty.

View Source
var HitMethodNotEmpty = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if hit.MustParsedRequest().Method == "" {
		return fmt.Errorf("hit.Method can not be empty")
	}
	return nil
})

HitMethodNotEmpty validates that Method is not empty.

View Source
var HitPathNotEmpty = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if hit.MustParsedRequest().Path == "" {
		return fmt.Errorf("hit.Path can not be empty")
	}
	return nil
})

HitPathNotEmpty validates that Path is not empty.

View Source
var HitQueryParamsNotNil = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if hit.MustParsedRequest().QueryParams == nil {
		return fmt.Errorf("hit.QueryParams can not be nil")
	}
	return nil
})

HitQueryParamsNotNil validates that QueryParams are not nil.

View Source
var PropertyIDNotEmpty = NewSimpleHitValidatingRule(func(_ protocol.Protocol, hit *hits.Hit) error {
	if hit.PropertyID == "" {
		return fmt.Errorf("hit.PropertyID can not be empty")
	}
	return nil
})

PropertyIDNotEmpty validates that PropertyID is not empty.

Functions

This section is empty.

Types

type BatchingBackend added in v0.49.1

type BatchingBackend interface {
	Append([]*hits.Hit) error
	Flush(func([]*hits.Hit) error) error
	Close() error
}

BatchingBackend abstracts the persistence layer used by BatchingStorage to stage hits before flushing them to the child storage.

func NewFileBatchingBackend added in v0.49.1

func NewFileBatchingBackend(cfg FileBatchingBackendConfig) BatchingBackend

NewFileBatchingBackend creates a BatchingBackend that durably stages hits to disk using an append-only framed JSON file.

type BatchingOption added in v0.49.1

type BatchingOption func(*BatchingStorage)

BatchingOption configures a BatchingStorage instance.

func WithBackend added in v0.49.1

func WithBackend(backend BatchingBackend) BatchingOption

WithBackend sets the backend used by BatchingStorage for staging hits. When not provided, an in-memory backend is used.

type BatchingStorage

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

BatchingStorage is a storage that batches hits and flushes them to a child storage.

func NewBatchingStorage

func NewBatchingStorage(
	child Storage,
	batchSize int,
	timeout time.Duration,
	opts ...BatchingOption,
) (storage *BatchingStorage, cleanup func())

NewBatchingStorage creates a new BatchingStorage instance.

func (*BatchingStorage) Close

func (bs *BatchingStorage) Close()

Close closes the BatchingStorage instance.

func (*BatchingStorage) Flush

func (bs *BatchingStorage) Flush() error

Flush flushes the buffer to the child storage.

func (*BatchingStorage) Push

func (bs *BatchingStorage) Push(h []*hits.Hit) error

Push implements the Storage interface.

type FileBatchingBackendConfig added in v0.49.1

type FileBatchingBackendConfig struct {
	Dir           string
	FlushFileName string
}

FileBatchingBackendConfig configures a file-backed batching backend.

type HitValidatingRule

type HitValidatingRule interface {
	Validate(p protocol.Protocol, hit *hits.Hit) error
}

HitValidatingRule defines the interface for validating hits.

func HitValidatingRuleSet

func HitValidatingRuleSet(
	maxHitSizeBytes uint32,
	settings properties.SettingsRegistry,
) HitValidatingRule

HitValidatingRuleSet returns a complete set of validation rules for hits.

func NewMultipleHitValidatingRule

func NewMultipleHitValidatingRule(rules ...HitValidatingRule) HitValidatingRule

NewMultipleHitValidatingRule creates a new validating rule that combines multiple rules.

func NewSimpleHitValidatingRule

func NewSimpleHitValidatingRule(rule func(protocol.Protocol, *hits.Hit) error) HitValidatingRule

NewSimpleHitValidatingRule creates a new validating rule from a simple function.

func PropertyProtocolMatchesTheEndpointProtocol added in v0.19.4

func PropertyProtocolMatchesTheEndpointProtocol(settings properties.SettingsRegistry) HitValidatingRule

PropertyProtocolMatchesTheEndpointProtocol checks if the protocols of endpoint and property match.

func TotalHitSizeDoesNotExceed added in v0.17.0

func TotalHitSizeDoesNotExceed(maxHitSizeBytes uint32) HitValidatingRule

TotalHitSizeDoesNotExceed validates that the total size of the hit does not exceed the max allowed size.

type NoopRawLogStorage added in v0.13.0

type NoopRawLogStorage struct{}

NoopRawLogStorage discards all raw log data.

func (*NoopRawLogStorage) Store added in v0.13.0

Store implements RawLogStorage

type ProxyTrust added in v0.49.2

type ProxyTrust interface {
	IsTrustedProxy(ip net.IP) bool
}

ProxyTrust controls whether and which proxy-set headers are trusted when extracting the client's real IP address.

Implement this interface and pass it to WithProxyTrust to inject fully custom proxy-trust logic.

type RawLogStorage

type RawLogStorage interface {
	Store(*hits.ParsedRequest) error
}

RawLogStorage defines the interface for storing raw log data

func NewDummyRawLogStorage

func NewDummyRawLogStorage() RawLogStorage

NewDummyRawLogStorage creates a dummy raw log storage that discards all data.

func NewNoopRawLogStorage added in v0.13.0

func NewNoopRawLogStorage() RawLogStorage

NewNoopRawLogStorage creates a noop raw log storage that discards all data.

type Server added in v0.17.0

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

Server holds all server-related dependencies and configuration

func NewServer added in v0.17.0

func NewServer(
	storage Storage,
	rawLogStorage RawLogStorage,
	validationRules HitValidatingRule,
	protocols []protocol.Protocol,
	port int,
	opts ...ServerOption,
) *Server

NewServer creates a new Server instance with the provided dependencies

func (*Server) Run added in v0.17.0

func (s *Server) Run(ctx context.Context) error

Run starts the HTTP server and blocks until the context is cancelled or an error occurs

type ServerOption added in v0.38.0

type ServerOption func(*Server)

func WithHost added in v0.38.0

func WithHost(host string) ServerOption

func WithMaxConcurrency added in v0.49.1

func WithMaxConcurrency(n int) ServerOption

WithMaxConcurrency sets the maximum number of concurrent connections the server will accept. Zero means fasthttp's default. Default is 256 * 1024.

func WithProxyTrust added in v0.49.2

func WithProxyTrust(trust ProxyTrust) ServerOption

WithProxyTrust configures the server to use a custom ProxyTrust implementation for deciding which proxies are trusted. This is the escape hatch for scenarios where neither WithTrustAllProxies nor WithTrustedProxies fits (e.g. dynamic allow-lists, cloud-metadata lookups).

func WithReadTimeout added in v0.49.1

func WithReadTimeout(d time.Duration) ServerOption

WithReadTimeout sets the maximum duration for reading the full request (including body). Zero means no timeout. Default is 5s.

func WithTrustAllProxies added in v0.49.1

func WithTrustAllProxies() ServerOption

WithTrustAllProxies configures the server to trust all proxies, honouring forwarded-IP headers from any source. Use only behind a reverse proxy that sanitises these headers.

func WithTrustedProxies added in v0.49.1

func WithTrustedProxies(cidrs ...string) ServerOption

WithTrustedProxies configures the server to trust forwarded-IP headers only when the immediate connection comes from one of the given CIDRs or IPs. Bare IP addresses (without a prefix length) are treated as /32 (IPv4) or /128 (IPv6). Returns a fatal-level log and falls back to no-trust if any entry is unparseable.

func WithWriteTimeout added in v0.49.1

func WithWriteTimeout(d time.Duration) ServerOption

WithWriteTimeout sets the maximum duration for writing the full response. Zero means no timeout. Default is 10s.

type Storage

type Storage interface {
	Push([]*hits.Hit) error
}

Storage is a storage interface for storing hits

func NewDropToStdoutStorage

func NewDropToStdoutStorage() Storage

NewDropToStdoutStorage creates a new storage instance that writes hits to stdout

func NewTestStorage added in v0.13.0

func NewTestStorage(pushFunc func(hits []*hits.Hit) error) Storage

NewTestStorage creates a new test storage instance with the given push function.

Jump to

Keyboard shortcuts

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