-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmd_service.go
54 lines (44 loc) · 1.06 KB
/
cmd_service.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
package main
import (
"fmt"
"time"
"github.com/last9/slo-computer/slo"
"github.com/pkg/errors"
"gopkg.in/alecthomas/kingpin.v2"
)
type suggestCmd struct {
throughput float64
sloDesire float64
sloPeriod int
}
func (c *suggestCmd) run(ctx *kingpin.ParseContext) error {
s, err := slo.NewSLO(
time.Duration(c.sloPeriod)*time.Hour,
c.throughput, c.sloDesire,
)
if err != nil {
return err
}
imp, yes := slo.IsLowTraffic(s)
if yes {
return errors.Errorf(
errorMessage, imp.Errors, imp.Duration,
imp.BreaksAfter,
)
}
a := slo.AlertCalculator(s)
for _, aw := range a {
fmt.Println(aw.String())
}
return nil
}
func suggestCommand(app *kingpin.Application) {
c := &suggestCmd{}
sg := app.Command(
"suggest",
"suggest alerts based on service throughput and SLO duration",
).Action(c.run)
sg.Flag("throughput", "Throughput for this service").Required().FloatVar(&c.throughput)
sg.Flag("slo", "Desired SLO for this service").Required().FloatVar(&c.sloDesire)
sg.Flag("duration", "Duration for the SLO").Required().IntVar(&c.sloPeriod)
}