Debian Codegraph @

stress/v2/statement/timestamp.go

raw symbols SCIP
1 package statement
2
3 import (
4 "log"
5 "time"
6 )
7
8 // A Timestamp contains all informaiton needed to generate timestamps for points created by InsertStatements
9 type Timestamp struct {
10 Count int
11 Duration time.Duration
12 Jitter bool
13 }
14
15 // Time returns the next timestamp needed by the InsertStatement
16 func (t *Timestamp) Time(startDate string, series int, precision string) func() int64 {
17 var start time.Time
18 var err error
19
20 if startDate == "now" {
21 start = time.Now()
22 } else {
23 start, err = time.Parse("2006-01-02", startDate)
24 }
25
26 if err != nil {
27 log.Fatalf("Error parsing start time from StartDate\n string: %v\n error: %v\n", startDate, err)
28 }
29
30 return nextTime(start, t.Duration, series, precision)
31 }
32
33 func nextTime(ti time.Time, step time.Duration, series int, precision string) func() int64 {
34 t := ti
35 count := 0
36 return func() int64 {
37 count++
38 if count > series {
39 t = t.Add(step)
40 count = 1
41 }
42
43 var timestamp int64
44 if precision == "s" {
45 timestamp = t.Unix()
46 } else {
47 timestamp = t.UnixNano()
48 }
49 return timestamp
50 }
51 }