-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from buger/module_architecture
Merge listener and replay functionality
- Loading branch information
Showing
46 changed files
with
1,306 additions
and
1,596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
language: go | ||
go: 1.1 | ||
script: sudo -E bash -c "source /etc/profile && gvm use go1.1 && export GOPATH=$HOME/gopath:$GOPATH && go test -v ./..." | ||
script: sudo -E bash -c "source /etc/profile && gvm use go1.1 && export GOPATH=$HOME/gopath:$GOPATH && go test -v" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
web: python -m SimpleHTTPServer 8000 | ||
replayed_web: python -m SimpleHTTPServer 8001 | ||
listener: sudo -E go run gor.go listen -p 8000 -r localhost:8002 --verbose | ||
replay: go run gor.go replay -f localhost:8001 -p 8002 --verbose | ||
listener: sudo -E go run ./bin/gor.go --input-raw :8000 --output-tcp :8002 --verbose | ||
replay: go run ./bin/gor.go --input-tcp :8002 --output-http localhost:8001 --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,116 +9,110 @@ Its main goal is to replay traffic from production servers to staging and dev en | |
Now you can test your code on real user sessions in an automated and repeatable fashion. | ||
**No more falling down in production!** | ||
|
||
Gor consists of 2 parts: listener and replay servers. | ||
|
||
The listener server catches http traffic from a given port in real-time | ||
and sends it to the replay server or saves to file. | ||
The replay server forwards traffic to a given address. | ||
Here is basic worlkflow: The listener server catches http traffic and sends it to the replay server or saves to file.The replay server forwards traffic to a given address. | ||
|
||
|
||
![Diagram](http://i.imgur.com/9mqj2SK.png) | ||
|
||
|
||
## Basic example | ||
## Examples | ||
|
||
### Capture traffic from port | ||
```bash | ||
# Run on servers where you want to catch traffic. You can run it on each `web` machine. | ||
sudo gor listen -p 80 -r replay.server.local:28020 | ||
sudo gor --input-raw :80 --output-tcp replay.local:28020 | ||
|
||
# Replay server (replay.local). | ||
gor --input-tcp replay.local:28020 --output-http http://staging.com | ||
``` | ||
|
||
# Replay server (replay.server.local). | ||
gor replay -f http://staging.server -p 28020 | ||
### Using 1 Gor instance for both listening and replaying | ||
It's recommended to use separate server for replaying traffic, but if you have enough CPU resources you can use single Gor instance. | ||
|
||
``` | ||
sudo gor --input-raw :80 --output-http "http://staging.com" | ||
``` | ||
|
||
## Advanced use | ||
|
||
### Rate limiting | ||
Both replay and listener supports rate limiting. It can be useful if you want | ||
Both replay and listener support rate limiting. It can be useful if you want | ||
forward only part of production traffic and not overload your staging | ||
environment. You can specify your desired requests per second using the | ||
"|" operator after the server address: | ||
|
||
#### Limiting replay | ||
``` | ||
# staging.server will not get more than 10 requests per second | ||
gor replay -f "http://staging.server|10" | ||
gor --input-tcp :28020 --output-http "http://staging.com|10" | ||
``` | ||
|
||
#### Limiting listener | ||
``` | ||
# replay server will not get more than 10 requests per second | ||
# useful for high-load environments | ||
gor listen -p 8080 -r "replay.server.local:28020|10" | ||
gor --input-raw :80 --output-tcp "replay.local:28020|10" | ||
``` | ||
|
||
### Forward to multiple addresses | ||
|
||
You can forward traffic to multiple endpoints. Just separate the addresses by comma. | ||
You can forward traffic to multiple endpoints. Just add multiple --output-* arguments. | ||
``` | ||
gor replay -f "http://staging.server|10,http://dev.server|5" | ||
gor --input-tcp :28020 --output-http "http://staging.com" --output-http "http://dev.com" | ||
``` | ||
|
||
### Saving requests to file | ||
You can save requests to file: | ||
#### Splitting traffic | ||
By default it will send same traffic to all outputs, but you have options to equally split it: | ||
|
||
``` | ||
gor listen -p 8080 -file requests.gor | ||
gor --input-tcp :28020 --output-http "http://staging.com" --output-http "http://dev.com" --split-output true | ||
``` | ||
|
||
And replay them later: | ||
### Saving requests to file | ||
You can save requests to file, and replay them later: | ||
``` | ||
gor replay -f "http://staging.server" -file requests.gor | ||
# write to file | ||
gor --input-raw :80 --output-file requests.gor | ||
# read from file | ||
gor --input-file requests.gor --output-http "http://staging.com" | ||
``` | ||
|
||
**Note:** Replay will preserve the original time differences between requests. | ||
|
||
### Injecting headers | ||
Additional headers can be injected/overwritten into requests during replay. | ||
This may be useful if the hostname that staging responds to differs from | ||
production, you need to identify requests generated by Gor, or enable | ||
feature flagged functionality in an application: | ||
|
||
Additional headers can be injected/overwritten into requests during replay. This may be useful if the hostname that staging responds to differs from production, you need to identify requests generated by Gor, or enable feature flagged functionality in an application: | ||
|
||
``` | ||
gor replay -f "http://staging.server" \ | ||
-header "Host: staging.server" \ | ||
-header "User-Agent: Replayed by Gor" -header " \ | ||
-header "Enable-Feature-X: true" | ||
gor --input-raw :80 --output-http "http://staging.server" \ | ||
--output-http-header "Host: staging.server" \ | ||
--output-http-header "User-Agent: Replayed by Gor" -header " \ | ||
--output-http-header "Enable-Feature-X: true" | ||
``` | ||
|
||
### Basic Auth | ||
If your development or staging environment is protected by Basic Authentication | ||
then those credentials can be injected in during the replay: | ||
|
||
If your development or staging environment is protected by Basic Authentication then those credentials can be injected in during the replay: | ||
|
||
``` | ||
gor replay -f "http://user1:[email protected],http://user2:pass2@staging.server" | ||
gor --input-raw :80 --output-http "http://user:pass@staging .com" | ||
``` | ||
|
||
**Note:** This will overwrite any `Authorization` headers in the original | ||
request. | ||
Note: This will overwrite any Authorization headers in the original request. | ||
|
||
## Stats | ||
|
||
|
||
### ElasticSearch | ||
For deep reponse analyze based on url, cookie, user-agent and etc. you can export response metadata to ElasticSearch. See [ELASTICSEARCH.md](ELASTICSEARCH.md) for more details. | ||
For deep response analyze based on url, cookie, user-agent and etc. you can export response metadata to ElasticSearch. See [ELASTICSEARCH.md](ELASTICSEARCH.md) for more details. | ||
|
||
``` | ||
gor replay -f "http://staging.server" -es "es_host:api_port/index_name" | ||
gor --input-tcp :80 --output-http "http://staging.com" --output-http-elasticsearch "es_host:api_port/index_name" | ||
``` | ||
|
||
|
||
## Additional help | ||
``` | ||
$ gor listen -h | ||
Usage of ./bin/gor-linux: | ||
-i="any": By default it try to listen on all network interfaces.To get list of interfaces run `ifconfig` | ||
-p=80: Specify the http server port whose traffic you want to capture | ||
-r="localhost:28020": Address of replay server. | ||
``` | ||
|
||
``` | ||
$ gor replay -h | ||
Usage of ./bin/gor-linux: | ||
-f="http://localhost:8080": http address to forward traffic. | ||
You can limit requests per second by adding `|#{num}` after address. | ||
If you have multiple addresses with different limits. For example: http://staging.example.com|100,http://dev.example.com|10 | ||
-ip="0.0.0.0": ip addresses to listen on | ||
-p=28020: specify port number | ||
``` | ||
Feel free to ask question directly by email or by creating github issue. | ||
|
||
## Latest releases (including binaries) | ||
|
||
|
@@ -128,14 +122,14 @@ https://github.com/buger/gor/releases | |
1. Setup standard Go environment http://golang.org/doc/code.html and ensure that $GOPATH environment variable properly set. | ||
2. `go get github.com/buger/gor`. | ||
3. `cd $GOPATH/src/github.com/buger/gor` | ||
4. `go build gor.go` to get binary, or `go run gor.go` to build and run (useful for development) | ||
4. `go build ./bin/gor.go` to get binary, or `go run ./bin/gor.go` to build and run (useful for development) | ||
|
||
## FAQ | ||
|
||
### What OS are supported? | ||
For now only Linux based. *BSD (including MacOS is not supported yet, check https://github.com/buger/gor/issues/22 for details) | ||
|
||
### Why does the `gor listener` requires sudo or root access? | ||
### Why does the `--input-raw` requires sudo or root access? | ||
Listener works by sniffing traffic from a given port. It's accessible | ||
only by using sudo or root access. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.