Debian Codegraph @

stress/v2/main.go

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