Git Product home page Git Product logo

log-replay's Introduction

Replay Nginx/Haproxy/SOLR logs

MIT License Build Go Report Card

Installation

go install github.com/Gonzih/log-replay@latest

Usage

Usage of log-replay:
  -debug
        Print extra debugging information
  -enable-window
        Enable rolling window functionality to stop log replaying in case of failure
  -error-rate float
        Percentage of the error to stop log replaying (min:1, max:99) (default 40)
  -file string
        Log file name to read. Read from STDIN if file name is '-' (default "-")
  -file-type string
        Input log type (nginx, haproxy or solr) (default "nginx")
  -format string
        Nginx log format (default "$remote_addr [$time_local] \"$request\" $status $request_length $body_bytes_sent $request_time \"$t_size\" $read_time $gen_time")
  -log string
        File to report timings to, default is stdout (default "-")
  -password string
        Basic auth password
  -prefix string
        URL prefix to query (default "http://localhost")
  -ratio int
        Replay speed ratio, higher means faster replay speed (default 1)
  -skip-sleep
        Skip sleep between http calls based on log timestamps
  -ssl-skip-verify
        Should HTTP client ignore ssl errors
  -timeout int
        Request timeout in milliseconds, 0 means no timeout (default 60000)
  -user-name string
        Basic auth username
  -window-size int
        Size of the window to track response status (default 1000)
# Replay access log
log-replay --file my-acces.log --debug --log out.log

# Duplicate traffic on the staging host - with basic auth
tail -f /var/log/acces.log | log-replay --prefix http://staging-host --log staging.log --skip-sleep \
      --user-name test-user --password supersecrEt

Output log format

Log is tab separated values:

status	start-time	duration	url payload err

# Examples
200	1469792268	629904766	/my-url
500	1469792268	629904766	/my-url	Get http://localhost/another-url: dial tcp [::1]:80: getsockopt: connection refused
  • status is integer
  • start-time is unix timestamp in seconds
  • duration is in nanoseconds
  • url is full url with prefix
  • payload is stringified post data
  • error is go lang error formatted to string and is optional

Only GET?

Nginx/Haproxy logs are currently limited to GET only. SOLR requests will use post format for everything, as a way to subvert GET length limitations.

Log formats

  • To correctly use the solr adapter, it is required that the log4 pattern is configured as follows:
<PatternLayout>
  <pattern>%d %p %C{1.} [%t] %m%n%ex</pattern>
</PatternLayout>

License

MIT

log-replay's People

Contributors

burakkose avatar dependabot-preview[bot] avatar dependabot[bot] avatar dpryden avatar gonzih avatar mgs255 avatar self-perfection avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

log-replay's Issues

Providing a custom format

My log format is a bit different than the default one. I tried providing a --format argument, but whatever I tried, I didn't succeed in making it work.

My log lines look like this:

0.0.0.0 - - [11/Jun/2017:02:00:00 +0200] "POST /path HTTP/1.1" 200 129 "https://www.example.com/path?gclid=CL7u8Iq-tNQC" "Mozilla/5.0 (Linux; Android 6.0.1; SAMSUNG SM-J700M Build/MMB29K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.4 Chrome/51.0.2704.106 Mobile Safari/537.36"

I tried with these formats:

"$remote_addr $ident $auth [$time_local] \"$verb $request HTTP/$http\" $status $request_length \"$referrer\" \"$agent\""
"$remote_addr $ident $auth [$time_local] \"$verb $request HTTP/$http\" $status $request_length $referrer $agent"
"$remote_addr $ident $auth [$time_local] $verb $request HTTP/$http $status $request_length $referrer $agent"
'$remote_addr $ident $auth [$time_local] "$verb $request HTTP/$http" $status $request_length "$referrer" "$agent"'

Unfortunately, nothing worked (got just Reached EOF or ERROR while parsing string: /path). What am I doing wrong? How should the format parts be given/named? And how should the quotes/whitespace be handled?

Add a switch to set custom request headers

Hi. It would be great if we could supply custom headers (including overwriting the hardcoded user-agent). Personally, I need this to supply a host header, because the application expects a certain host and will not work with a different one.

Allow a way to limit idle connections

Currently, it looks like fireHTTPRequest creates a new http.Client for every request, which is unnecessary. But I believe this is also responsible for leaking TCP connections. Since the client doesn't close the connection after making a request (since the default Transport caches connections for later use), on the server side (nginx in my case), when replaying 100 requests per second, I see 1000 or more idle connections (and this appears to scale up as I increase load). At a high enough level of load, I hit nginx's worker_connections limit, and nginx stops being able to receive new connections, even though the server has capacity to serve them.

I see a couple of ways to resolve this: one way would be to simply create the http.Client in mainLoop instead and share it with all the goroutines. This seems like it would probably be the simplest solution.

On the other hand, there may be value in allowing a user to customize the http.Transport being used, especially the MaxIdleConns and IdleConnTimeout settings. If I could control those, either for a single http.Client or for each client, that would resolve this issue as well.

If you are interested, I could try to put together a pull request.

Use user-agent from the access log

Currently hardcoded. Being able to overwrite with one static value (#6) would already be an improvement, but ideally, log-replay would replay the per-request user-agent from the log.

Running log-replay

It may be a stupid question, but how do I run log-replay? I've installed it with go get, but there is no executable. I tried to build main.go then, but it gives me some undefined errors.

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.