replay

package
v0.0.0-...-d231d64 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2013 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Replay server receive requests objects from Listeners and forward it to given address. Basic usage:

gor replay -f http://staging.server

Rate limiting

It can be useful if you want forward only part of production traffic, not to overload staging environment. You can specify desired request per second using "|" operator after server address:

# staging.server not get more than 10 requests per second
gor replay -f "http://staging.server|10"

Forward to multiple addresses

Just separate addresses by coma:

  gor replay -f "http://staging.server|10,http://dev.server|20"

For more help run:

   gor replay -h

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Enable debug logging only if "--verbose" flag passed

func ParseRequest

func ParseRequest(data []byte) (request *http.Request, err error)

func Run

func Run()

Because its sub-program, Run acts as `main` Replay server listen to UDP traffic from Listeners Each request processed by RequestFactory

Types

type ForwardHost

type ForwardHost struct {
	Url   string
	Limit int

	Stat *RequestStat
}

type HttpResponse

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

type ReplaySettings

type ReplaySettings struct {
	Port int
	Host string

	ForwardAddress string

	Verbose bool
}
var Settings ReplaySettings = ReplaySettings{}

func (*ReplaySettings) Address

func (r *ReplaySettings) Address() string

Helper to return address with port, e.g.: 127.0.0.1:28020

func (*ReplaySettings) ForwardedHosts

func (r *ReplaySettings) ForwardedHosts() (hosts []*ForwardHost)

ForwardedHosts implements forwardAddress syntax support for multiple hosts (coma separated), and rate limiting by specifing "|maxRps" after host name.

-f "host1,http://host2|10,host3"

type RequestFactory

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

Class for processing requests

Basic workflow:

1. When request added via Add() it get pushed to `responses` chan 2. handleRequest() listen for `responses` chan and decide where request should be forwarded, and apply rate-limit if needed 3. sendRequest() forwards request and returns response info to `responses` chan 4. handleRequest() listen for `response` channel and updates stats

func NewRequestFactory

func NewRequestFactory() (factory *RequestFactory)

RequestFactory contstuctor One created, it starts listening for incoming requests: requests channel

func (*RequestFactory) Add

func (f *RequestFactory) Add(request *http.Request)

Add request to channel for further processing

type RequestStat

type RequestStat struct {
	Codes map[int]int // { 200: 10, 404:2, 500:1 }

	Count  int // All requests including errors
	Errors int // Rquests with errors (timeout or host not reachable). Not include 50x errors.
	// contains filtered or unexported fields
}

Stats stores in context of current timestamp

func NewRequestStats

func NewRequestStats(host *ForwardHost) (stat *RequestStat)

RequestStat constructor

func (*RequestStat) IncReq

func (s *RequestStat) IncReq()

Called on request start

func (*RequestStat) IncResp

func (s *RequestStat) IncResp(resp *HttpResponse)

Called after response

func (*RequestStat) Touch

func (s *RequestStat) Touch()

Ensure that current stats is actual (for current timestamp)

Jump to

Keyboard shortcuts

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