random_delay

package module
v0.0.0-...-dcfd809 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

caddy-random-delay

Go Reference

A caddy handler to introduce a delay for some requests

Purpose

This module was written to facilitate reproducing a problem that occurred when some HTTP requests began taking too long, resulting in client-side timeouts. While one usually doesn't want to make requests take longer, this module could be useful for chaos testing or simulating slow HTTP servers.

Usage

random_delay <percent_delayed> <duration>

The module has only two options:

  • percent_delayed is a float that determines the chance a request will be delayed (e.g. 0.2, 0.69, 1.0)
  • duration is a string that determines the duration of the delay injected by the module following Go's duration format (e.g. 10s, 5m, 200ms)

A full Caddyfile example is below. This would introduce a 10 second delay to approximately 50% of requests.

{
	order random_delay before reverse_proxy
}

http://localhost:8000 {
    random_delay 0.5 10s
	reverse_proxy https://icanhazip.com {
		header_up Host {upstream_hostport}
	}
	log {
		format console
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	DelayDuration  time.Duration `json:"delay_duration"`
	PercentDelayed float64       `json:"percent_delayed"`
	// contains filtered or unexported fields
}

Middleware implements an HTTP handler that delays approximately PercentDelayed requests by DelayDuration

func (Middleware) CaddyModule

func (Middleware) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*Middleware) Provision

func (m *Middleware) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (Middleware) ServeHTTP

func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler

func (*Middleware) UnmarshalCaddyfile

func (m *Middleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler. Syntax:

random_delay <percent_delayed> <duration>

When radnom_delay is used, precent_delayed of requests will be delayed by <duration> before the request is passed to the next handler. This can be helpful in scenarios where latency or timeouts need to be simulated such as when chaos testing or reproducing a problem.

func (*Middleware) Validate

func (m *Middleware) Validate() error

Validate implements caddy.Validator.

Jump to

Keyboard shortcuts

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