forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (49 loc) · 1.43 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package stress
import (
"fmt"
"log"
"time"
influx "github.com/influxdata/influxdb/client/v2"
"github.com/influxdata/influxdb/stress/v2/stress_client"
"github.com/influxdata/influxdb/stress/v2/stressql"
)
// RunStress takes a configFile and kicks off the stress test
func RunStress(file string) {
// Spin up the Client
s := stressClient.NewStressTest()
// Parse the file into Statements
stmts, err := stressql.ParseStatements(file)
// Log parse errors and quit if found
if err != nil {
log.Fatalf("Parsing Error\n error: %v\n", err)
}
// Run all statements
for _, stmt := range stmts {
stmt.Run(s)
}
// Clear out the batch of unsent response points
resp := blankResponse()
s.ResultsChan <- resp
resp.Tracer.Wait()
// Compile all Reports
for _, stmt := range stmts {
fmt.Println(stmt.Report(s))
}
}
func blankResponse() stressClient.Response {
// Points must have at least one field
fields := map[string]interface{}{"done": true}
// Make a 'blank' point
p, err := influx.NewPoint("done", make(map[string]string), fields, time.Now())
// Panic on error
if err != nil {
log.Fatalf("Error creating blank response point\n error: %v\n", err)
}
// Add a tracer to prevent program from returning too early
tracer := stressClient.NewTracer(make(map[string]string))
// Add to the WaitGroup
tracer.Add(1)
// Make a new response with the point and the tracer
resp := stressClient.NewResponse(p, tracer)
return resp
}