mirror

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 18 Imported by: 0

README

caddy-mirror

A basic request mirroring/shadowing middleware for Caddy 2

This module provides an HTTP handler which mirrors matching requests to an additional target.

It was written to solve two shortcomings with ngx_http_mirror_module - mirror requests were tied to the lifecycle of the main requests, and could not reuse connections.

Because the module is a minimum viable product, it has several of it's own shortcomings:

  • Request bodies are not currently supported
  • Requests are not identical to reverse_proxied requests
  • Error logging is slow and spammy
Usage
example.com {
	route /hello {
		mirror http://mirror_server
		reverse_proxy http://hello_backend
	}
	
	route /world {
	    mirror http://mirror_server {
	        # Mirror half of all incoming requests
	        sample 0.5
	        # Use two goroutines/connections to send requests
	        concurrency 2
	        # Queue of 1024 requests shared between goroutines
	        backlog 1024
	    }
	    reverse_proxy http://world_backend
    }
}
Todo
  • Add tests
  • Add a circuit breaker for upstreams
  • Try to adapt Caddy's reverse proxy as a transport

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mirror

type Mirror struct {
	SamplingRate       float64       `json:"sampling_rate,omitempty"`
	RequestConcurrency int           `json:"request_concurrency,omitempty"`
	MaxBacklog         int           `json:"max_backlog,omitempty"`
	TargetServer       string        `json:"target,omitempty"`
	RequestTimeout     time.Duration `json:"request_timeout,omitempty"`
	AlertInterval      time.Duration `json:"alert_interval,omitempty"`
	// contains filtered or unexported fields
}

func (*Mirror) CaddyModule

func (*Mirror) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*Mirror) Cleanup

func (m *Mirror) Cleanup() error

func (*Mirror) EnsureDefaults

func (m *Mirror) EnsureDefaults()

func (*Mirror) Provision

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

func (*Mirror) ServeHTTP

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

func (*Mirror) UnmarshalCaddyfile

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

func (*Mirror) Validate

func (m *Mirror) Validate() error

type Request

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

Jump to

Keyboard shortcuts

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