forked from timescale/tsbs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
53 lines (45 loc) · 1.46 KB
/
main.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
// tsbs_load_victoriametrics loads a VictoriaMetrics with data from stdin or file.
package main
import (
"fmt"
"github.com/blagojts/viper"
"github.com/spf13/pflag"
"github.com/benchant/tsbs/internal/utils"
"github.com/benchant/tsbs/load"
"github.com/benchant/tsbs/pkg/data/source"
"github.com/benchant/tsbs/pkg/targets/victoriametrics"
"log"
"strings"
)
// Parse args:
func initProgramOptions() (*victoriametrics.SpecificConfig, load.BenchmarkRunner, *load.BenchmarkRunnerConfig) {
target := victoriametrics.NewTarget()
loaderConf := load.BenchmarkRunnerConfig{}
loaderConf.AddToFlagSet(pflag.CommandLine)
target.TargetSpecificFlags("", pflag.CommandLine)
pflag.Parse()
if err := utils.SetupConfigFile(); err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
if err := viper.Unmarshal(&loaderConf); err != nil {
panic(fmt.Errorf("unable to decode config: %s", err))
}
urls := viper.GetString("urls")
if len(urls) == 0 {
log.Fatalf("missing `urls` flag")
}
vmURLs := strings.Split(urls, ",")
loader := load.GetBenchmarkRunner(loaderConf)
return &victoriametrics.SpecificConfig{ServerURLs: vmURLs}, loader, &loaderConf
}
func main() {
vmConf, loader, loaderConf := initProgramOptions()
benchmark, err := victoriametrics.NewBenchmark(vmConf, &source.DataSourceConfig{
Type: source.FileDataSourceType,
File: &source.FileDataSourceConfig{Location: loaderConf.FileName},
})
if err != nil {
panic(err)
}
loader.RunBenchmark(benchmark)
}