middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package middleware provides decorators for backend implementations, including logging and latency simulation.

Index

Constants

This section is empty.

Variables

View Source
var GCSDelays = DelayOptions{
	MetaRead:       Latency{22 * time.Millisecond, 7 * time.Millisecond},
	MetaWrite:      Latency{31 * time.Millisecond, 8 * time.Millisecond},
	ObjRead:        Latency{57 * time.Millisecond, 7 * time.Millisecond},
	ObjWrite:       Latency{70 * time.Millisecond, 15 * time.Millisecond},
	List:           Latency{10 * time.Millisecond, 3 * time.Millisecond},
	SameObjWritePs: 1,
}

GCSDelays contains typical latency values observed with Google Cloud Storage.

Functions

This section is empty.

Types

type BackendLogger

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

BackendLogger is a backend.Backend decorator that logs all operations.

func NewBackendLogger

func NewBackendLogger(inner backend.Backend, id string, log *slog.Logger) BackendLogger

NewBackendLogger creates a BackendLogger that wraps inner with debug logging.

func (BackendLogger) Delete

func (b BackendLogger) Delete(ctx context.Context, path string) error

Delete implements backend.Backend.

func (BackendLogger) DeleteIf

func (b BackendLogger) DeleteIf(
	ctx context.Context,
	path string,
	expected backend.Version,
) error

DeleteIf implements backend.Backend.

func (BackendLogger) GetMetadata

func (b BackendLogger) GetMetadata(
	ctx context.Context,
	path string,
) (backend.Metadata, error)

GetMetadata implements backend.Backend.

func (BackendLogger) List

func (b BackendLogger) List(ctx context.Context, dirPath string) (backend.ListIter, error)

List implements backend.Backend.

func (BackendLogger) Read

func (b BackendLogger) Read(ctx context.Context, path string) (backend.ReadReply, error)

func (BackendLogger) ReadIfModified

func (b BackendLogger) ReadIfModified(
	ctx context.Context,
	path string,
	version int64,
) (backend.ReadReply, error)

ReadIfModified implements backend.Backend.

func (BackendLogger) SetTagsIf

func (b BackendLogger) SetTagsIf(
	ctx context.Context,
	path string,
	expected backend.Version,
	t backend.Tags,
) (backend.Metadata, error)

SetTagsIf implements backend.Backend.

func (BackendLogger) Write

func (b BackendLogger) Write(
	ctx context.Context,
	path string,
	value []byte,
	t backend.Tags,
) (backend.Metadata, error)

func (BackendLogger) WriteIf

func (b BackendLogger) WriteIf(
	ctx context.Context,
	path string,
	value []byte,
	expected backend.Version,
	t backend.Tags,
) (backend.Metadata, error)

WriteIf implements backend.Backend.

func (BackendLogger) WriteIfNotExists

func (b BackendLogger) WriteIfNotExists(
	ctx context.Context,
	path string,
	value []byte,
	t backend.Tags,
) (backend.Metadata, error)

WriteIfNotExists implements backend.Backend.

type DelayBackend

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

DelayBackend is a backend.Backend decorator that simulates network latency and per-object write rate limiting.

func NewDelayBackend

func NewDelayBackend(
	inner backend.Backend,
	clock clockwork.Clock,
	opts DelayOptions,
) *DelayBackend

NewDelayBackend creates a DelayBackend that adds simulated latency to backend operations.

func (*DelayBackend) Delete

func (b *DelayBackend) Delete(ctx context.Context, path string) error

Delete implements backend.Backend.

func (*DelayBackend) DeleteIf

func (b *DelayBackend) DeleteIf(
	ctx context.Context,
	path string,
	expected backend.Version,
) error

DeleteIf implements backend.Backend.

func (*DelayBackend) GetMetadata

func (b *DelayBackend) GetMetadata(
	ctx context.Context,
	path string,
) (backend.Metadata, error)

GetMetadata implements backend.Backend.

func (*DelayBackend) List

func (b *DelayBackend) List(ctx context.Context, dirPath string) (backend.ListIter, error)

List implements backend.Backend.

func (*DelayBackend) Read

func (b *DelayBackend) Read(ctx context.Context, path string) (backend.ReadReply, error)

func (*DelayBackend) ReadIfModified

func (b *DelayBackend) ReadIfModified(
	ctx context.Context,
	path string,
	version int64,
) (backend.ReadReply, error)

ReadIfModified implements backend.Backend.

func (*DelayBackend) SetTagsIf

func (b *DelayBackend) SetTagsIf(
	ctx context.Context,
	path string,
	expected backend.Version,
	t backend.Tags,
) (backend.Metadata, error)

SetTagsIf implements backend.Backend.

func (*DelayBackend) Write

func (b *DelayBackend) Write(
	ctx context.Context,
	path string,
	value []byte,
	t backend.Tags,
) (backend.Metadata, error)

func (*DelayBackend) WriteIf

func (b *DelayBackend) WriteIf(
	ctx context.Context,
	path string,
	value []byte,
	expected backend.Version,
	t backend.Tags,
) (backend.Metadata, error)

WriteIf implements backend.Backend.

func (*DelayBackend) WriteIfNotExists

func (b *DelayBackend) WriteIfNotExists(
	ctx context.Context,
	path string,
	value []byte,
	t backend.Tags,
) (backend.Metadata, error)

WriteIfNotExists implements backend.Backend.

type DelayOptions

type DelayOptions struct {
	MetaRead  Latency
	MetaWrite Latency
	ObjRead   Latency
	ObjWrite  Latency
	List      Latency
	// How many writes per second to the same object before being
	// rate limited?
	SameObjWritePs int
}

DelayOptions configures simulated latency for each type of backend operation.

type Latency

type Latency struct {
	Mean   time.Duration
	StdDev time.Duration
}

Latency describes the mean and standard deviation of an operation's duration.

Jump to

Keyboard shortcuts

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