receiver

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package receiver implements the receiver service.

Package receiver provides raw log storage implementations for storing and batching raw log data.

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(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 HitBodyNotNil = NewSimpleHitValidatingRule(func(hit *hits.Hit) error {
	if hit.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(hit *hits.Hit) error {
	if len(hit.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(hit *hits.Hit) error {
	if hit.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(hit *hits.Hit) error {
	if hit.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(hit *hits.Hit) error {
	if hit.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(hit *hits.Hit) error {
	if hit.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(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

func FormatTimestamp

func FormatTimestamp(t time.Time) string

FormatTimestamp formats a timestamp to a readable ISO format

func RawLogDetailPageHandler

func RawLogDetailPageHandler(rawLogSet storage.Set) func(fctx *fasthttp.RequestCtx)

RawLogDetailPageHandler returns a handler for the detail page showing content of a specific item

func RawLogDetailPageHandlerFromReader

func RawLogDetailPageHandlerFromReader(reader RawLogReader) func(fctx *fasthttp.RequestCtx)

RawLogDetailPageHandlerFromReader returns a handler for the detail page using RawLogReader

func RawLogMainPageHandler

func RawLogMainPageHandler(rawLogIndexSet storage.Set) func(fctx *fasthttp.RequestCtx)

RawLogMainPageHandler returns a handler for the main rawlog page showing all index items

func RawLogMainPageHandlerFromReader

func RawLogMainPageHandlerFromReader(reader RawLogReader) func(fctx *fasthttp.RequestCtx)

RawLogMainPageHandlerFromReader returns a handler for the main rawlog page using RawLogReader

func Serve

func Serve(
	ctx context.Context,
	storage Storage,
	rawLogStorage RawLogStorage,
	port int,
	protocols protocol.PathProtocolMapping,
	otherHandlers map[string]func(fctx *fasthttp.RequestCtx),
) error

Serve starts the HTTP server with the given storage backend and port

Types

type BatchingRawlogStorage

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

BatchingRawlogStorage is a storage that batches raw log buffers and flushes them to a child storage.

func NewBatchingRawlogStorage

func NewBatchingRawlogStorage(child RawLogStorage, batchSize int, timeout time.Duration) *BatchingRawlogStorage

NewBatchingRawlogStorage creates a new BatchingRawlogStorage instance.

func (*BatchingRawlogStorage) Close

func (brs *BatchingRawlogStorage) Close()

Close closes the BatchingRawlogStorage instance.

func (*BatchingRawlogStorage) Flush

func (brs *BatchingRawlogStorage) Flush() error

Flush flushes the buffer to the child storage.

func (*BatchingRawlogStorage) Store

func (brs *BatchingRawlogStorage) Store(buffer *bytes.Buffer) error

Store implements the RawLogStorage interface

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) *BatchingStorage

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(hits []*hits.Hit) error

Push implements the Storage interface

type HitValidatingRule

type HitValidatingRule interface {
	Validate(*hits.Hit) error
}

HitValidatingRule defines the interface for validating hits.

func HitValidatingRuleSet

func HitValidatingRuleSet() 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(*hits.Hit) error) HitValidatingRule

NewSimpleHitValidatingRule creates a new validating rule from a simple function.

type RawLogItem

type RawLogItem struct {
	ID            string
	Timestamp     time.Time
	FormattedTime string
}

RawLogItem represents a single raw log item with its identifier and timestamp

type RawLogReader

type RawLogReader interface {
	// ListItems returns a list of raw log items sorted by timestamp (newest first)
	ListItems() ([]RawLogItem, error)
	// GetContent returns the content of a specific raw log item by ID
	GetContent(itemID string) ([]byte, error)
}

RawLogReader defines the interface for reading raw log data

type RawLogStorage

type RawLogStorage interface {
	Store(*bytes.Buffer) 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.

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

type StorageSetRawLogStorage

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

StorageSetRawLogStorage implements RawLogStorage using a storage.KV backend.

func NewFromStorageSetRawLogStorage

func NewFromStorageSetRawLogStorage(rawlogSet, indexSet storage.Set) *StorageSetRawLogStorage

NewFromStorageSetRawLogStorage creates a new StorageSetRawLogStorage instance.

func (*StorageSetRawLogStorage) GetContent

func (s *StorageSetRawLogStorage) GetContent(itemID string) ([]byte, error)

GetContent implements RawLogReader by loading and joining content for a given item ID.

func (*StorageSetRawLogStorage) ListItems

func (s *StorageSetRawLogStorage) ListItems() ([]RawLogItem, error)

ListItems implements RawLogReader by returning indexed raw log items sorted by timestamp.

func (*StorageSetRawLogStorage) Store

func (s *StorageSetRawLogStorage) Store(buffer *bytes.Buffer) error

Store implements the RawLogStorage interface by storing the buffer data in KV storage. It generates a unique timestamp-based key for each log entry.

Jump to

Keyboard shortcuts

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