Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

some improvements #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this addition intentional?

Copy link
Author

@cfz cfz Dec 12, 2018

Choose a reason for hiding this comment

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

we use goland as IDE, which by default will generate some metadata in the project path. this one is for excluding those metadata

24 changes: 19 additions & 5 deletions cmd/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
strict, kapacitorMode bool
recordStats bool
tlsSkipVerify bool
readTimeout, writeTimeout time.Duration
printError bool
)

const (
Expand Down Expand Up @@ -68,6 +70,12 @@ func insertRun(cmd *cobra.Command, args []string) {
batchSize = pps
concurrency = 1
}
if uint64(seriesN) < batchSize {
// otherwise, the tool will generate points with identical timestamp
fmt.Fprintf(os.Stderr, "series number(%v) should not be smaller than batch size(%v)\n", seriesN, batchSize)
os.Exit(1)
return
}
if !quiet {
fmt.Printf("Using point template: %s %s <timestamp>\n", seriesKey, fieldStr)
fmt.Printf("Using batch size of %d line(s)\n", batchSize)
Expand Down Expand Up @@ -125,7 +133,7 @@ func insertRun(cmd *cobra.Command, args []string) {

cfg := stress.WriteConfig{
BatchSize: batchSize,
MaxPoints: pointsN / concurrency, // divide by concurreny
MaxPoints: pointsN / concurrency, // divide by concurrency
GzipLevel: gzip,
Deadline: time.Now().Add(runtime),
Tick: tick,
Expand Down Expand Up @@ -185,6 +193,9 @@ func init() {
insertCmd.Flags().StringVar(&dump, "dump", "", "Dump to given file instead of writing over HTTP")
insertCmd.Flags().BoolVarP(&strict, "strict", "", false, "Strict mode will exit as soon as an error or unexpected status is encountered")
insertCmd.Flags().BoolVarP(&tlsSkipVerify, "tls-skip-verify", "", false, "Skip verify in for TLS")
insertCmd.Flags().DurationVarP(&readTimeout, "read-timeout", "", 0, "read timeout")
insertCmd.Flags().DurationVarP(&writeTimeout, "write-timeout", "", 0, "write timeout")
insertCmd.Flags().BoolVarP(&printError, "print-error", "", true, "print error to stderr")
}

func client() write.Client {
Expand All @@ -198,6 +209,8 @@ func client() write.Client {
Consistency: consistency,
TLSSkipVerify: tlsSkipVerify,
Gzip: gzip != 0,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
}

if dump != "" {
Expand Down Expand Up @@ -251,12 +264,12 @@ func (s *errorSink) checkErrors() {

const timeFormat = "[2006-01-02 15:04:05]"
for r := range s.Ch {
if r.Err != nil {
if r.Err != nil && printError {
fmt.Fprintln(os.Stderr, time.Now().Format(timeFormat), "Error sending write:", r.Err.Error())
continue
}

if r.StatusCode != 204 {
if r.StatusCode != 204 && printError {
fmt.Fprintln(os.Stderr, time.Now().Format(timeFormat), "Unexpected write: status", r.StatusCode, ", body:", r.Body)
}

Expand Down Expand Up @@ -379,9 +392,10 @@ func (s *influxDBSink) run() {
case result := <-s.Ch:
// Add to batch
if result.Err != nil {
continue
s.buf.WriteString(fmt.Sprintf("err,status=%v latNs=%v %v\n", result.StatusCode, result.LatNs, result.Timestamp))
} else {
s.buf.WriteString(fmt.Sprintf("req,status=%v latNs=%v %v\n", result.StatusCode, result.LatNs, result.Timestamp))
}
s.buf.WriteString(fmt.Sprintf("req,status=%v latNs=%v %v\n", result.StatusCode, result.LatNs, result.Timestamp))
}
}
}
13 changes: 8 additions & 5 deletions write/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type ClientConfig struct {
TLSSkipVerify bool

Gzip bool

ReadTimeout time.Duration
WriteTimeout time.Duration
}

type Client interface {
Expand All @@ -48,12 +51,12 @@ type client struct {
}

func NewClient(cfg ClientConfig) Client {
var httpClient *fasthttp.Client
var httpClient = &fasthttp.Client{}
httpClient.WriteTimeout = cfg.WriteTimeout
httpClient.ReadTimeout = cfg.ReadTimeout
if cfg.TLSSkipVerify {
httpClient = &fasthttp.Client{
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
httpClient.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
return &client{
Expand Down