Documentation
¶
Index ¶
- type Event
- type EventBus
- type InMemoryEventBus
- type RedisClient
- type RedisEventBus
- func (b *RedisEventBus) Client() RedisClient
- func (b *RedisEventBus) EventCount(ctx context.Context) (int64, error)
- func (b *RedisEventBus) Publish(ctx context.Context, evt Event)
- func (b *RedisEventBus) ReadEvents(ctx context.Context, start, end int64) ([]Event, error)
- func (b *RedisEventBus) Stop()
- func (b *RedisEventBus) Subscribe() <-chan Event
- type RedisGoClientAdapter
- func (a *RedisGoClientAdapter) EXPIRE(ctx context.Context, key string, expiration time.Duration) error
- func (a *RedisGoClientAdapter) Get(ctx context.Context, key string) (string, error)
- func (a *RedisGoClientAdapter) Incr(ctx context.Context, key string) (int64, error)
- func (a *RedisGoClientAdapter) LLEN(ctx context.Context, key string) (int64, error)
- func (a *RedisGoClientAdapter) LPush(ctx context.Context, key string, values ...interface{}) error
- func (a *RedisGoClientAdapter) LRANGE(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (a *RedisGoClientAdapter) LTRIM(ctx context.Context, key string, start, stop int64) error
- func (a *RedisGoClientAdapter) Set(ctx context.Context, key, value string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { LogID int64 // Monotonic event log ID RequestID string Method string Path string Status int Duration time.Duration ResponseHeaders http.Header ResponseBody []byte RequestBody []byte }
Event represents an observability event emitted by the proxy.
type InMemoryEventBus ¶
type InMemoryEventBus struct {
// contains filtered or unexported fields
}
InMemoryEventBus is an EventBus implementation backed by a buffered channel and fan-out broadcasting to multiple subscribers. Events are dispatched asynchronously to avoid blocking the request path.
func NewInMemoryEventBus ¶
func NewInMemoryEventBus(bufferSize int) *InMemoryEventBus
NewInMemoryEventBus creates a new in-memory event bus with the given buffer size.
func (*InMemoryEventBus) Publish ¶
func (b *InMemoryEventBus) Publish(ctx context.Context, evt Event)
Publish sends an event to the bus without blocking if the buffer is full.
func (*InMemoryEventBus) Stats ¶
func (b *InMemoryEventBus) Stats() (published, dropped int)
Stats returns the number of published and dropped events.
func (*InMemoryEventBus) Stop ¶
func (b *InMemoryEventBus) Stop()
Stop gracefully stops the event bus and closes all subscriber channels.
func (*InMemoryEventBus) Subscribe ¶
func (b *InMemoryEventBus) Subscribe() <-chan Event
Subscribe returns a channel that receives events published to the bus. Each subscriber receives all events.
type RedisClient ¶
type RedisClient interface { LPush(ctx context.Context, key string, values ...interface{}) error LRANGE(ctx context.Context, key string, start, stop int64) ([]string, error) LLEN(ctx context.Context, key string) (int64, error) EXPIRE(ctx context.Context, key string, expiration time.Duration) error LTRIM(ctx context.Context, key string, start, stop int64) error Incr(ctx context.Context, key string) (int64, error) Get(ctx context.Context, key string) (string, error) Set(ctx context.Context, key, value string) error }
Extend RedisClient interface for LRANGE, LLEN, EXPIRE, LTRIM, Incr, Get, Set
type RedisEventBus ¶
type RedisEventBus struct {
// contains filtered or unexported fields
}
RedisEventBus is a Redis-backed EventBus implementation. Events are encoded as JSON and pushed to a Redis list. This version is a persistent log: events are never removed by consumers.
func NewRedisEventBusLog ¶
func NewRedisEventBusLog(client RedisClient, key string, ttl time.Duration, maxLen int64) *RedisEventBus
NewRedisEventBusLog creates a Redis event bus that acts as a persistent log (non-destructive, with TTL and optional max length)
func NewRedisEventBusPublisher ¶
func NewRedisEventBusPublisher(client RedisClient, key string) *RedisEventBus
NewRedisEventBusPublisher creates a Redis event bus that only publishes events (no background consumer).
func (*RedisEventBus) Client ¶
func (b *RedisEventBus) Client() RedisClient
Client returns the underlying RedisClient for this RedisEventBus
func (*RedisEventBus) EventCount ¶
func (b *RedisEventBus) EventCount(ctx context.Context) (int64, error)
EventCount returns the current number of events in the log
func (*RedisEventBus) Publish ¶
func (b *RedisEventBus) Publish(ctx context.Context, evt Event)
Publish pushes the event JSON to the Redis list.
func (*RedisEventBus) ReadEvents ¶
ReadEvents returns events in [start, end] (inclusive, like LRANGE)
func (*RedisEventBus) Stop ¶
func (b *RedisEventBus) Stop()
Stop is a no-op for the log-based RedisEventBus (required to satisfy EventBus interface)
func (*RedisEventBus) Subscribe ¶
func (b *RedisEventBus) Subscribe() <-chan Event
Subscribe is not supported for the log-based RedisEventBus. It returns a closed channel.
type RedisGoClientAdapter ¶
type RedisGoClientAdapter struct {
Client *redis.Client
}
RedisGoClientAdapter adapts go-redis/v9 Client to the RedisClient interface.
func (*RedisGoClientAdapter) LPush ¶
func (a *RedisGoClientAdapter) LPush(ctx context.Context, key string, values ...interface{}) error
func (*RedisGoClientAdapter) LRANGE ¶
func (a *RedisGoClientAdapter) LRANGE(ctx context.Context, key string, start, stop int64) ([]string, error)
Extend RedisGoClientAdapter to implement new methods