-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (65 loc) · 2.03 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
package main
import (
"context"
"errors"
"fmt"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/alexflint/go-arg"
"github.com/c2h5oh/datasize"
"github.com/go-logr/logr"
"github.com/spegel-org/benchmark/internal/analyze"
"github.com/spegel-org/benchmark/internal/generate"
"github.com/spegel-org/benchmark/internal/measure"
)
type GenerateCmd struct {
ImageName string `arg:"--image-name,required"`
LayerCount int `arg:"--layer-count,required"`
ImageSize datasize.ByteSize `arg:"--image-size,required"`
}
type MeasureCmd struct {
ResultDir string `arg:"--result-dir,required"`
KubeconfigPath string `arg:"--kubeconfig,required"`
Namespace string `arg:"--namespace" default:"spegel-benchmark"`
Images []string `arg:"--images,required"`
}
type AnalyzeCmd struct {
Path string `args:"--path,required"`
}
type Arguments struct {
Generate *GenerateCmd `arg:"subcommand:generate" help:"Generate iamges for benchmarking."`
Measure *MeasureCmd `arg:"subcommand:measure" help:"Run benchmark measurement."`
Analyze *AnalyzeCmd `arg:"subcommand:analyze" help:"Analyze benchmark results."`
}
func main() {
args := &Arguments{}
arg.MustParse(args)
err := run(*args)
if err != nil {
fmt.Println("unexpected error:", err)
os.Exit(1)
}
}
func run(args Arguments) error {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM)
defer cancel()
opts := slog.HandlerOptions{
AddSource: false,
Level: slog.Level(-1),
}
handler := slog.NewTextHandler(os.Stderr, &opts)
log := logr.FromSlogHandler(handler)
ctx = logr.NewContext(ctx, log)
switch {
case args.Generate != nil:
return generate.Generate(ctx, args.Generate.ImageName, args.Generate.LayerCount, args.Generate.ImageSize)
case args.Measure != nil:
return measure.Measure(ctx, args.Measure.KubeconfigPath, args.Measure.Namespace, args.Measure.ResultDir, args.Measure.Images)
case args.Analyze != nil:
return analyze.Analyze(ctx, args.Analyze.Path)
default:
return errors.New("unknown command")
}
}