-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
79 lines (67 loc) · 2.56 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
// 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/blagojts/viper"
"github.com/cnosdb/tsdb-comparisons/cmd/generate_queries/uses/iot"
"github.com/cnosdb/tsdb-comparisons/cmd/generate_queries/utils"
"github.com/cnosdb/tsdb-comparisons/internal/inputs"
internalUtils "github.com/cnosdb/tsdb-comparisons/internal/utils"
"github.com/cnosdb/tsdb-comparisons/pkg/query/config"
"github.com/spf13/pflag"
"os"
)
var useCaseMatrix = map[string]map[string]utils.QueryFillerMaker{
"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)
}
}