Add support for `tag_count` config option

It is now possible to configure arbitrarily many tags in a generic
format. That is specifying the config option `tag_count=10` will add 10
tags to a series that are of the form `tag-key-n=tag-value` where n
ranges from 0 to 9.

Save current state
pull/4168/head
Michael Desa 2015-09-22 09:48:14 -07:00
parent 03f291d78c
commit 22a6f79a3c
3 changed files with 42 additions and 12 deletions

View File

@ -7,14 +7,14 @@
address = "localhost:8086"
reset_database = true
# doesnt do anything
starting_point = "6m" # how far back in time to go
starting_point = 0 # how far back in time to go in weeks
[[series]]
point_count = 10 # number of points that will be written for each of the series
measurement = "cpu"
series_count = 100000
tag_count = 20 # doesnt do anything yet
# tag_count = 20 # number of "generic" tags on a series (e.g. tag-key-1=tag-value, ... ,tag-key-20=tag-value)
[[series.tag]]
key = "host"

View File

@ -3,6 +3,7 @@ package runner
import (
"fmt"
"math/rand"
"time"
"github.com/BurntSushi/toml"
"github.com/influxdb/influxdb/client"
@ -29,6 +30,7 @@ type series struct {
PointCount int `toml:"point_count"`
Measurement string `toml:"measurement"`
SeriesCount int `toml:"series_count"`
TagCount int `toml:"tag_count"`
Tags []tag `toml:"tag"`
Fields []field `toml:"field"`
}
@ -43,7 +45,7 @@ type write struct {
BatchInterval string `toml:"batch_interval"`
Database string `toml:"database"`
ResetDatabase bool `toml:"reset_database"`
StartingPoint string `toml:"starting_time"`
StartingPoint int `toml:"starting_point"`
Address string `toml:"address"`
Precision string `toml:"precision"`
}
@ -115,10 +117,29 @@ func NewConfig() *Config {
func DecodeFile(s string) (*Config, error) {
t := &Config{}
// Decode the toml file
if _, err := toml.DecodeFile(s, t); err != nil {
return nil, err
}
// Initialize Config struct
// NOTE: Not happy with the implementation
// but it will do for now
for j, srs := range t.Series {
for i := 0; i < srs.TagCount; i++ {
tag := tag{
Key: fmt.Sprintf("tag-key-%d", i),
Value: "tag-value",
}
srs.Tags = append(srs.Tags, tag)
fmt.Println(srs)
}
t.Series[j] = srs
}
return t, nil
}
@ -127,13 +148,21 @@ func DecodeFile(s string) (*Config, error) {
// number of points that have been written
// for the series `s`
type seriesIter struct {
s *series
count int
s *series
count int
timestamp time.Time
}
func (s *series) writeInterval(weeks int, i int) time.Time {
st := time.Duration(weeks) * 7 * 24 * time.Hour
w := st - (st/time.Duration(s.PointCount))*time.Duration(i)
return time.Now().Add(-1 * w)
}
// Iter returns a pointer to a seriesIter
func (s *series) Iter() *seriesIter {
return &seriesIter{s: s, count: -1}
func (s *series) Iter(weeks int, i int) *seriesIter {
return &seriesIter{s: s, count: -1, timestamp: s.writeInterval(weeks, i)}
}
// newTagMap returns a tagset
@ -178,6 +207,7 @@ func (iter *seriesIter) Next() (client.Point, bool) {
Measurement: iter.s.Measurement,
Tags: iter.s.newTagMap(iter.count),
Fields: iter.s.newFieldMap(),
Time: iter.timestamp,
}
b := iter.count < iter.s.SeriesCount
return p, b

View File

@ -134,9 +134,6 @@ func resetDB(c *client.Client, database string) error {
// and the times that the test started at and ended as a `Timer`
func Run(cfg *Config) (totalPoints int, failedRequests int, responseTimes ResponseTimes, timer *Timer) {
timer = NewTimer()
defer timer.StopTimer()
c, err := cfg.NewClient()
if err != nil {
panic(err)
@ -173,9 +170,12 @@ func Run(cfg *Config) (totalPoints int, failedRequests int, responseTimes Respon
Precision: cfg.Write.Precision,
}
timer = NewTimer()
defer timer.StopTimer()
for _, testSeries := range cfg.Series {
for i := 0; i < testSeries.PointCount; i++ {
iter := testSeries.Iter()
iter := testSeries.Iter(cfg.Write.StartingPoint, i)
p, ok := iter.Next()
for ok {
batch.Points = append(batch.Points, p)
@ -217,7 +217,7 @@ func Run(cfg *Config) (totalPoints int, failedRequests int, responseTimes Respon
Database: cfg.Write.Database,
WriteConsistency: "any",
Precision: cfg.Write.Precision,
Time: time.Now(),
//Time: time.Now(),
}
}
p, ok = iter.Next()