Skip to content
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

add proxy support #87

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM golang:1.15 as builder
antonioua marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /build

COPY go.mod go.sum ./

RUN go mod download

COPY *.go/ ./
COPY internal/ internal/

ARG VERSION="0.0.1"

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on \
go build \
-ldflags "-X main.Version=$VERSION" \
-a \
-o bombardier-linux-amd64

FROM debian:bookworm-slim

WORKDIR /

RUN apt-get update && \
apt-get install -y ca-certificates curl && \
update-ca-certificates && \
rm -rf /var/lib/apt/lists/*

RUN addgroup --gid 901 bombardier && \
adduser --uid 901 --gid 901 bombardier

USER bombardier

COPY --from=builder /build/bombardier-linux-amd64 .

ENTRYPOINT ["./bombardier-linux-amd64"]
10 changes: 6 additions & 4 deletions bombardier.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ func (b *bombardier) bombard() {
func (b *bombardier) printIntro() {
if b.conf.testType() == counted {
fmt.Fprintf(b.out,
"Bombarding %v with %v request(s) using %v connection(s)\n",
b.conf.url, *b.conf.numReqs, b.conf.numConns)
"Bombarding %v with %v request(s) using %v connection(s). Proxy: `%s`\n",
b.conf.url, *b.conf.numReqs, b.conf.numConns, proxyServer)
} else if b.conf.testType() == timed {
fmt.Fprintf(b.out, "Bombarding %v for %v using %v connection(s)\n",
b.conf.url, *b.conf.duration, b.conf.numConns)
fmt.Fprintf(b.out, "Bombarding %v for %v using %v connection(s). Proxy: `%s`\n",
b.conf.url, *b.conf.duration, b.conf.numConns, proxyServer)
}
}

Expand Down Expand Up @@ -441,6 +441,8 @@ func (b *bombardier) disableOutput() {
}

func main() {
proxyServer = os.Getenv("BOMBARDIER_PROXY")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably come from a command line argument

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


cfg, err := parser.parse(os.Args)
if err != nil {
fmt.Println(err)
Expand Down
18 changes: 17 additions & 1 deletion clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func newFastHTTPClient(opts *clientOpts) client {
c.host = u.Host
c.requestURI = u.RequestURI()
c.client = &fasthttp.HostClient{

Addr: u.Host,
IsTLS: u.Scheme == "https",
MaxConns: int(opts.maxConns),
Expand Down Expand Up @@ -131,12 +132,27 @@ type httpClient struct {
}

func newHTTPClient(opts *clientOpts) client {
var err error
var proxyURL *url.URL

if len(proxyServer) != 0 {
proxyURL, err = url.Parse(proxyServer)
if err != nil {
panic(err)
}
}

c := new(httpClient)
tr := &http.Transport{
TLSClientConfig: opts.tlsConfig,
MaxIdleConnsPerHost: int(opts.maxConns),
DisableKeepAlives: opts.disableKeepAlives,
}

if len(proxyServer) != 0 {
tr.Proxy = http.ProxyURL(proxyURL)
}

tr.DialContext = httpDialContextFunc(opts.bytesRead, opts.bytesWritten)
if opts.HTTP2 {
_ = http2.ConfigureTransport(tr)
Expand All @@ -157,7 +173,7 @@ func newHTTPClient(opts *clientOpts) client {

c.headers = headersToHTTPHeaders(opts.headers)
c.method, c.body, c.bodProd = opts.method, opts.body, opts.bodProd
var err error

c.url, err = url.Parse(opts.url)
if err != nil {
// opts.url guaranteed to be valid at this point
Expand Down
2 changes: 2 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
var (
version = "unspecified"

proxyServer = "none"

emptyConf = config{}
parser = newKingpinParser()

Expand Down