/
main.go
100 lines (87 loc) · 3.77 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// tsbs_generate_queries generates queries for various use cases. Its output will
// be consumed by the corresponding tsbs_run_queries_ program.
package main
import (
"fmt"
"github.com/timescale/tsbs/pkg/query/config"
"os"
"time"
"github.com/blagojts/viper"
"github.com/spf13/pflag"
"github.com/timescale/tsbs/cmd/tsbs_generate_queries/uses/devops"
"github.com/timescale/tsbs/cmd/tsbs_generate_queries/uses/iot"
"github.com/timescale/tsbs/cmd/tsbs_generate_queries/utils"
"github.com/timescale/tsbs/internal/inputs"
internalUtils "github.com/timescale/tsbs/internal/utils"
)
var useCaseMatrix = map[string]map[string]utils.QueryFillerMaker{
"devops": {
devops.LabelSingleGroupby + "-1-1-1": devops.NewSingleGroupby(1, 1, 1),
devops.LabelSingleGroupby + "-1-1-12": devops.NewSingleGroupby(1, 1, 12),
devops.LabelSingleGroupby + "-1-8-1": devops.NewSingleGroupby(1, 8, 1),
devops.LabelSingleGroupby + "-5-1-1": devops.NewSingleGroupby(5, 1, 1),
devops.LabelSingleGroupby + "-5-1-12": devops.NewSingleGroupby(5, 1, 12),
devops.LabelSingleGroupby + "-5-8-1": devops.NewSingleGroupby(5, 8, 1),
devops.LabelMaxAll + "-1": devops.NewMaxAllCPU(1, devops.MaxAllDuration),
devops.LabelMaxAll + "-8": devops.NewMaxAllCPU(8, devops.MaxAllDuration),
devops.LabelMaxAll + "-32-24": devops.NewMaxAllCPU(32, 24*time.Hour),
devops.LabelDoubleGroupby + "-1": devops.NewGroupBy(1),
devops.LabelDoubleGroupby + "-5": devops.NewGroupBy(5),
devops.LabelDoubleGroupby + "-all": devops.NewGroupBy(devops.GetCPUMetricsLen()),
devops.LabelGroupbyOrderbyLimit: devops.NewGroupByOrderByLimit,
devops.LabelHighCPU + "-all": devops.NewHighCPU(0),
devops.LabelHighCPU + "-1": devops.NewHighCPU(1),
devops.LabelLastpoint: devops.NewLastPointPerHost,
},
"iot": {
iot.LabelLastLoc: iot.NewLastLocPerTruck,
iot.LabelLastLocSingleTruck: iot.NewLastLocSingleTruck,
iot.LabelLowFuel: iot.NewTruckWithLowFuel,
iot.LabelHighLoad: iot.NewTruckWithHighLoad,
iot.LabelStationaryTrucks: iot.NewStationaryTrucks,
iot.LabelLongDrivingSessions: iot.NewTrucksWithLongDrivingSession,
iot.LabelLongDailySessions: iot.NewTruckWithLongDailySession,
iot.LabelAvgVsProjectedFuelConsumption: iot.NewAvgVsProjectedFuelConsumption,
iot.LabelAvgDailyDrivingDuration: iot.NewAvgDailyDrivingDuration,
iot.LabelAvgDailyDrivingSession: iot.NewAvgDailyDrivingSession,
iot.LabelAvgLoad: iot.NewAvgLoad,
iot.LabelDailyActivity: iot.NewDailyTruckActivity,
iot.LabelBreakdownFrequency: iot.NewTruckBreakdownFrequency,
},
}
var conf = &config.QueryGeneratorConfig{}
// Parse args:
func init() {
useCaseMatrix["cpu-only"] = useCaseMatrix["devops"]
// Change the Usage function to print the use case matrix of choices:
oldUsage := pflag.Usage
pflag.Usage = func() {
oldUsage()
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "The use case matrix of choices is:\n")
for uc, queryTypes := range useCaseMatrix {
for qt := range queryTypes {
fmt.Fprintf(os.Stderr, " use case: %s, query type: %s\n", uc, qt)
}
}
}
conf.AddToFlagSet(pflag.CommandLine)
pflag.Parse()
err := internalUtils.SetupConfigFile()
if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
if err := viper.Unmarshal(&conf.BaseConfig); err != nil {
panic(fmt.Errorf("unable to decode base config: %s", err))
}
if err := viper.Unmarshal(&conf); err != nil {
panic(fmt.Errorf("unable to decode config: %s", err))
}
}
func main() {
qg := inputs.NewQueryGenerator(useCaseMatrix)
err := qg.Generate(conf)
if err != nil {
fmt.Printf("error: %v\n", err)
}
}