forked from timescale/tsbs
-
Notifications
You must be signed in to change notification settings - Fork 6
/
common_generate_data.go
84 lines (69 loc) · 2.56 KB
/
common_generate_data.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package devops
import (
"time"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/common"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/serialize"
)
type commonDevopsSimulator struct {
madePoints uint64
maxPoints uint64
hostIndex uint64
hosts []Host
epoch uint64
epochs uint64
epochHosts uint64
initHosts uint64
timestampStart time.Time
timestampEnd time.Time
interval time.Duration
}
// Finished tells whether we have simulated all the necessary points
func (s *commonDevopsSimulator) Finished() bool {
return s.madePoints >= s.maxPoints
}
func (s *commonDevopsSimulator) Fields() map[string][][]byte {
return s.fields(s.hosts[0].SimulatedMeasurements)
}
func (s *commonDevopsSimulator) fields(measurements []common.SimulatedMeasurement) map[string][][]byte {
data := make(map[string][][]byte)
for _, sm := range measurements {
point := serialize.NewPoint()
sm.ToPoint(point)
data[string(point.MeasurementName())] = point.FieldKeys()
}
return data
}
func (s *commonDevopsSimulator) populatePoint(p *serialize.Point, measureIdx int) bool {
host := &s.hosts[s.hostIndex]
// Populate host-specific tags:
p.AppendTag(MachineTagKeys[0], host.Name)
p.AppendTag(MachineTagKeys[1], host.Region)
p.AppendTag(MachineTagKeys[2], host.Datacenter)
p.AppendTag(MachineTagKeys[3], host.Rack)
p.AppendTag(MachineTagKeys[4], host.OS)
p.AppendTag(MachineTagKeys[5], host.Arch)
p.AppendTag(MachineTagKeys[6], host.Team)
p.AppendTag(MachineTagKeys[7], host.Service)
p.AppendTag(MachineTagKeys[8], host.ServiceVersion)
p.AppendTag(MachineTagKeys[9], host.ServiceEnvironment)
// Populate measurement-specific tags and fields:
host.SimulatedMeasurements[measureIdx].ToPoint(p)
ret := s.hostIndex < s.epochHosts
s.madePoints++
s.hostIndex++
return ret
}
// TODO(rrk) - Can probably turn this logic into a separate interface and implement other
// types of scale up, e.g., exponential
//
// To "scale up" the number of reporting items, we need to know when
// which epoch we are currently in. Once we know that, we can take the "missing"
// amount of scale -- i.e., the max amount of scale less the initial amount
// -- and add it in proportion to the percentage of epochs that have passed. This
// way we simulate all items at each epoch, but at the end of the function
// we check whether the point should be recorded by the calling process.
func (s *commonDevopsSimulator) adjustNumHostsForEpoch() {
s.epoch++
missingScale := float64(uint64(len(s.hosts)) - s.initHosts)
s.epochHosts = s.initHosts + uint64(missingScale*float64(s.epoch)/float64(s.epochs-1))
}