Skip to content

goreplay-cli package #1148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ vendor:
go mod vendor

release-bin-linux-amd64: vendor
docker run --platform linux/amd64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER_AMD) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS)
docker run --platform linux/amd64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER_AMD) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) ./cmd/gor/

release-bin-linux-arm64: vendor
docker run --platform linux/arm64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=arm64 -i $(CONTAINER_ARM) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS)
docker run --platform linux/arm64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=arm64 -i $(CONTAINER_ARM) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) ./cmd/gor/

release-bin-mac-amd64: vendor
GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS)
GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) ./cmd/gor/

release-bin-mac-arm64: vendor
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS)

release-bin-windows: vendor
docker run -it --rm -v `pwd`:$(SOURCE_PATH) -w $(SOURCE_PATH) -e CGO_ENABLED=1 docker.elastic.co/beats-dev/golang-crossbuild:1.19.2-main --build-cmd "make VERSION=$(VERSION) build" -p "windows/amd64"
docker run -it --rm -v `pwd`:$(SOURCE_PATH) -w $(SOURCE_PATH) -e CGO_ENABLED=1 docker.elastic.co/beats-dev/golang-crossbuild:1.19.2-main --build-cmd "make VERSION=$(VERSION) build" -p "windows/amd64" ./cmd/gor/
mv $(BIN_NAME) "$(BIN_NAME).exe"

release-linux-amd64: dist release-bin-linux-amd64
Expand Down
27 changes: 14 additions & 13 deletions gor.go → cmd/gor/gor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"expvar"
"flag"
"fmt"
"github.com/buger/goreplay"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -71,23 +72,23 @@ func main() {
}

args := os.Args[1:]
var plugins *InOutPlugins
var plugins *goreplay.InOutPlugins
if len(args) > 0 && args[0] == "file-server" {
if len(args) != 2 {
log.Fatal("You should specify port and IP (optional) for the file server. Example: `gor file-server :80`")
}
dir, _ := os.Getwd()

Debug(0, "Started example file server for current directory on address ", args[1])
goreplay.Debug(0, "Started example file server for current directory on address ", args[1])

log.Fatal(http.ListenAndServe(args[1], loggingMiddleware(args[1], http.FileServer(http.Dir(dir)))))
} else {
flag.Parse()
checkSettings()
plugins = NewPlugins()
goreplay.CheckSettings()
plugins = goreplay.NewPlugins()
}

log.Printf("[PPID %d and PID %d] Version:%s\n", os.Getppid(), os.Getpid(), VERSION)
log.Printf("[PPID %d and PID %d] Version:%s\n", os.Getppid(), os.Getpid(), goreplay.VERSION)

if len(plugins.Inputs) == 0 || len(plugins.Outputs) == 0 {
log.Fatal("Required at least 1 input and 1 output")
Expand All @@ -101,20 +102,20 @@ func main() {
profileCPU(*cpuprofile)
}

if Settings.Pprof != "" {
if goreplay.Settings.Pprof != "" {
go func() {
log.Println(http.ListenAndServe(Settings.Pprof, nil))
log.Println(http.ListenAndServe(goreplay.Settings.Pprof, nil))
}()
}

closeCh := make(chan int)
emitter := NewEmitter()
go emitter.Start(plugins, Settings.Middleware)
if Settings.ExitAfter > 0 {
log.Printf("Running gor for a duration of %s\n", Settings.ExitAfter)
emitter := goreplay.NewEmitter()
go emitter.Start(plugins, goreplay.Settings.Middleware)
if goreplay.Settings.ExitAfter > 0 {
log.Printf("Running gor for a duration of %s\n", goreplay.Settings.ExitAfter)

time.AfterFunc(Settings.ExitAfter, func() {
log.Printf("gor run timeout %s\n", Settings.ExitAfter)
time.AfterFunc(goreplay.Settings.ExitAfter, func() {
log.Printf("gor run timeout %s\n", goreplay.Settings.ExitAfter)
close(closeCh)
})
}
Expand Down
5 changes: 2 additions & 3 deletions elasticsearch.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package main
package goreplay

import (
"encoding/json"
"github.com/buger/goreplay/proto"
"log"
"net/url"
"strings"
"time"

"github.com/buger/goreplay/proto"

elastigo "github.com/mattbaird/elastigo/lib"
)

Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"testing"
Expand Down
4 changes: 2 additions & 2 deletions emitter.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package main
package goreplay

import (
"fmt"
"github.com/buger/goreplay/internal/byteutils"
"hash/fnv"
"io"
"log"
"sync"

"github.com/buger/goreplay/byteutils"
"github.com/coocood/freecache"
)

Expand Down
2 changes: 1 addition & 1 deletion emitter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"fmt"
Expand Down
3 changes: 1 addition & 2 deletions examples/middleware/token_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
"bytes"
"encoding/hex"
"fmt"
"os"

"github.com/buger/goreplay/proto"
"os"
)

// requestID -> originalToken
Expand Down
2 changes: 1 addition & 1 deletion gor_stat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"runtime"
Expand Down
5 changes: 2 additions & 3 deletions http_modifier.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package main
package goreplay

import (
"bytes"
"encoding/base64"
"github.com/buger/goreplay/proto"
"hash/fnv"
"strings"

"github.com/buger/goreplay/proto"
)

type HTTPModifier struct {
Expand Down
18 changes: 1 addition & 17 deletions http_modifier_settings.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"errors"
Expand All @@ -24,9 +24,7 @@ type HTTPModifierConfig struct {
Methods HTTPMethods `json:"http-allow-method"`
}

//
// Handling of --http-allow-header, --http-disallow-header options
//
type headerFilter struct {
name []byte
regexp *regexp.Regexp
Expand Down Expand Up @@ -56,9 +54,7 @@ func (h *HTTPHeaderFilters) Set(value string) error {
return nil
}

//
// Handling of --http-basic-auth-filter option
//
type basicAuthFilter struct {
regexp *regexp.Regexp
}
Expand All @@ -82,9 +78,7 @@ func (h *HTTPHeaderBasicAuthFilters) Set(value string) error {
return nil
}

//
// Handling of --http-allow-header-hash and --http-allow-param-hash options
//
type hashFilter struct {
name []byte
percent uint32
Expand Down Expand Up @@ -129,9 +123,7 @@ func (h *HTTPHashFilters) Set(value string) error {
return nil
}

//
// Handling of --http-set-header option
//
type httpHeader struct {
Name string
Value string
Expand Down Expand Up @@ -160,9 +152,7 @@ func (h *HTTPHeaders) Set(value string) error {
return nil
}

//
// Handling of --http-set-param option
//
type httpParam struct {
Name []byte
Value []byte
Expand Down Expand Up @@ -208,9 +198,7 @@ func (h *HTTPMethods) Set(value string) error {
return nil
}

//
// Handling of --http-rewrite-url option
//
type urlRewrite struct {
src *regexp.Regexp
target []byte
Expand All @@ -237,9 +225,7 @@ func (r *URLRewriteMap) Set(value string) error {
return nil
}

//
// Handling of --http-rewrite-header option
//
type headerRewrite struct {
header []byte
src *regexp.Regexp
Expand Down Expand Up @@ -275,9 +261,7 @@ func (r *HeaderRewriteMap) Set(value string) error {
return nil
}

//
// Handling of --http-allow-url option
//
type urlRegexp struct {
regexp *regexp.Regexp
}
Expand Down
2 changes: 1 addition & 1 deletion http_modifier_settings_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"testing"
Expand Down
5 changes: 2 additions & 3 deletions http_modifier_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package main
package goreplay

import (
"bytes"
"testing"

"github.com/buger/goreplay/proto"
"testing"
)

func TestHTTPModifierWithoutConfig(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions http_prettifier.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package main
package goreplay

import (
"bytes"
"compress/gzip"
"fmt"
"github.com/buger/goreplay/proto"
"io/ioutil"
"net/http/httputil"
"strconv"

"github.com/buger/goreplay/proto"
)

func prettifyHTTP(p []byte) []byte {
Expand Down
5 changes: 2 additions & 3 deletions http_prettifier_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package main
package goreplay

import (
"bytes"
"compress/gzip"
"github.com/buger/goreplay/proto"
"strconv"
"testing"

"github.com/buger/goreplay/proto"
)

func TestHTTPPrettifierGzip(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion input_dummy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion input_file.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion input_file_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion input_http.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"log"
Expand Down
2 changes: 1 addition & 1 deletion input_http_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion input_kafka.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion input_kafka_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"testing"
Expand Down
9 changes: 4 additions & 5 deletions input_raw.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package main
package goreplay

import (
"context"
"fmt"
"github.com/buger/goreplay/internal/capture"
"github.com/buger/goreplay/internal/tcp"
"github.com/buger/goreplay/proto"
"log"
"net"
"strconv"
"strings"
"sync"

"github.com/buger/goreplay/capture"
"github.com/buger/goreplay/proto"
"github.com/buger/goreplay/tcp"
)

// RAWInputConfig represents configuration that can be applied on raw input
Expand Down
9 changes: 4 additions & 5 deletions input_raw_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package main
package goreplay

import (
"bytes"
"github.com/buger/goreplay/internal/capture"
"github.com/buger/goreplay/internal/tcp"
"github.com/buger/goreplay/proto"
"io/ioutil"
"net"
"net/http"
Expand All @@ -13,10 +16,6 @@ import (
"sync/atomic"
"testing"
"time"

"github.com/buger/goreplay/capture"
"github.com/buger/goreplay/proto"
"github.com/buger/goreplay/tcp"
)

const testRawExpire = time.Millisecond * 200
Expand Down
2 changes: 1 addition & 1 deletion input_tcp.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package goreplay

import (
"bufio"
Expand Down
Loading