| 1 |
package statement |
| 2 |
|
| 3 |
import ( |
| 4 |
"log" |
| 5 |
"time" |
| 6 |
|
| 7 |
"github.com/influxdata/influxdb/stress/v2/stress_client" |
| 8 |
) |
| 9 |
|
| 10 |
|
| 11 |
type InfluxqlStatement struct { |
| 12 |
StatementID string |
| 13 |
Query string |
| 14 |
Tracer *stressClient.Tracer |
| 15 |
} |
| 16 |
|
| 17 |
func (i *InfluxqlStatement) tags() map[string]string { |
| 18 |
tags := make(map[string]string) |
| 19 |
return tags |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
func (i *InfluxqlStatement) SetID(s string) { |
| 24 |
i.StatementID = s |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
func (i *InfluxqlStatement) Run(s *stressClient.StressTest) { |
| 29 |
|
| 30 |
|
| 31 |
i.Tracer = stressClient.NewTracer(i.tags()) |
| 32 |
|
| 33 |
|
| 34 |
p := stressClient.NewPackage(stressClient.Query, []byte(i.Query), i.StatementID, i.Tracer) |
| 35 |
|
| 36 |
|
| 37 |
i.Tracer.Add(1) |
| 38 |
|
| 39 |
|
| 40 |
s.SendPackage(p) |
| 41 |
|
| 42 |
|
| 43 |
i.Tracer.Wait() |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
func (i *InfluxqlStatement) Report(s *stressClient.StressTest) (out string) { |
| 49 |
allData := s.GetStatementResults(i.StatementID, "query") |
| 50 |
|
| 51 |
iqlr := &influxQlReport{ |
| 52 |
statement: i.Query, |
| 53 |
columns: allData[0].Series[0].Columns, |
| 54 |
values: allData[0].Series[0].Values, |
| 55 |
} |
| 56 |
|
| 57 |
iqlr.responseTime = time.Duration(responseTimes(iqlr.columns, iqlr.values)[0].Value) |
| 58 |
|
| 59 |
switch countSuccesses(iqlr.columns, iqlr.values) { |
| 60 |
case 0: |
| 61 |
iqlr.success = false |
| 62 |
case 1: |
| 63 |
iqlr.success = true |
| 64 |
default: |
| 65 |
log.Fatal("Error fetching response for InfluxQL statement") |
| 66 |
} |
| 67 |
|
| 68 |
return iqlr.String() |
| 69 |
} |