GithubHelp home page GithubHelp logo

rb3ckers / trafficmirror Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 4.0 152 KB

Mirror HTTP traffic to a main target (acting as a reverse proxy) and a runtime modifiable set of mirror targets

License: Apache License 2.0

Shell 3.46% Go 93.42% Dockerfile 3.12%
mirroring shadowing traffic http

trafficmirror's Introduction

Traffic mirror

Mirror HTTP traffic to a main target (acting as a reverse proxy) and a runtime modifiable set of mirror targets.

At the moment this code is a first attempt at implementing traffic mirroring (aka shadowing) to multiple targets. Most existing tools only support one additional target (the shadow copy) next to the real (production) target who's response is returned to the client.

How to run

If you just run the command ./trafficmirror it will bind and start listening on the default address *:8080 and will by default reverse proxy all traffic to http://localhost:8888. All the defaults can be customized with command line arguments, see trafficmirror -h for the details.

Now that the normal flow of traffic to your application is running we can start adding mirrors. To be as flexible as possible this is not done via the command line. Instead an extra endpoint (/targets by default) has been exposed on the address that traffic mirror just bound to. This endpoint can be used to add,remove or list the current mirror targets.

IMPORTANT By default this endpoint will be publicly accessible. This is quick and easy, but likely not what you want. You can add password protection to it with the -password option. Note that the assumption here is that your application was already behind a TLS load balancer or proxy, traffic mirror doesn't support TLS traffic at the moment. Additionally you can use -targets-address to bind this targets endpoint to a separate address, for example localhost:1234 (effectively limiting access to only the server itself).

Mirror targets

Let's assume traffic mirror was started with ./trafficmirror -targets-address=localhost:1234.

To add a target:

curl -X PUT 127.0.0.1:1234/targets?url=http://firstmirror:8080

To list the targets (in plain text):

curl 127.0.0.1:1234/targets

returns

http://firstmirror:8080

To remove the target again:

curl -X DELETE 127.0.0.1:1234/targets?url=http://firstmirror:8080

Because a request parameter can be added multiple times to a url we can also add and remove multiple targets in one go:

curl -X PUT "127.0.0.1:1234/targets?url=http://firstmirror:8080&url=http://secondmirror:8081"
curl 127.0.0.1:1234/targets

Returns

http://firstmirror:8080
http://secondmirror:8081

When password protection was enabled adapt all curl commands accordingly. For example if your password file contained

user:password

The list command should become:

curl -u user:password 127.0.0.1:1234/targets

Error behavior

While a target is available and responding to requests it will keep on receiving mirrored data. However when it starts failing, either returning errors or maybe it is down, the target will temporarily not receive any traffic anymore. After a minute (see the retry-after option) it will be retried with a single request, if this succeeds it will start receiving traffic again. If a target is persistently failing for 30 minutes (see fail-after option) it will be automatically removed from the set of targets and will need to be added manually again if the situation has been resolved.

Developing

This repository uses Pre-commit to run some basic go linting and checks. Please install it when developing.

brew install pre-commit # install pre-commit if you haven't already
pre-commit install # install the hooks in your local clone

trafficmirror's People

Contributors

hierynomus avatar rb3ckers avatar sc250024 avatar voronenko avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

trafficmirror's Issues

Amplification factor

To simulate (extreme) high loads a target should be able to specify an amplification factor such that traffic mirror will send every request X times to the target instead of only once.

Optional external storage for the target set

The idea is to store the set of targets not just in memory but also, optionally, in, for example, a Redis cache. This has multiple advantages:

  • Upon restarts of the application/docker container the targets will keep receiving traffic
  • Allows for running multiple instances of traffic mirror if needed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.