Skip to content

Commit

Permalink
Merge pull request #303 from ragnarlonn/master
Browse files Browse the repository at this point in the history
HTTP-based usage reports, fixed opts.NoUsageReport.Valid bug
  • Loading branch information
liclac authored Aug 31, 2017
2 parents 0737dba + 425fde3 commit 3a9cb76
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"os/signal"
Expand Down Expand Up @@ -471,15 +471,17 @@ func actionRun(cc *cli.Context) error {
ctx, cancel := context.WithCancel(context.Background())
engine.Collector = collector

// Send usage report, if we're allowed to
if opts.NoUsageReport.Valid && !opts.NoUsageReport.Bool {
if !opts.NoUsageReport.Valid || !opts.NoUsageReport.Bool {
go func() {
conn, err := net.Dial("udp", "k6reports.loadimpact.com:6565")
jsonStr := []byte(`{"k6_version":"` + cc.App.Version + `"}`)
req, err := http.NewRequest("POST", "http://k6reports.loadimpact.com/", bytes.NewBuffer(jsonStr))
if err == nil {
// This is a best-effort attempt to send a usage report. We don't want
// to inconvenience users if this doesn't work, for whatever reason
_, _ = conn.Write([]byte("nyoom"))
_ = conn.Close()
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err == nil {
_ = resp.Body.Close()
}
}
}()
}
Expand Down

0 comments on commit 3a9cb76

Please sign in to comment.