-
Notifications
You must be signed in to change notification settings - Fork 0
/
cycle.go
62 lines (53 loc) · 1.09 KB
/
cycle.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
package main
import (
"strconv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var lastSite *ConfigSite
var (
routesGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "current_announcements",
Help: "current announcements",
}, []string{"prefix", "site", "id"})
)
func (p *Prefix) update(site *ConfigSite) {
if p.announcing {
routesGauge.DeleteLabelValues(
p.prefix,
p.lastAdvSite.Name,
strconv.Itoa(p.lastAdvSite.Id+2000),
)
p.bgpWithdraw()
return
}
p.bgpAnnounce(site)
routesGauge.WithLabelValues(
p.prefix,
p.lastAdvSite.Name,
strconv.Itoa(p.lastAdvSite.Id+2000),
).Set(1)
return
}
func cycle() {
for i := range prefixes {
prefix := prefixes[i]
site := nextSite()
prefix.update(site)
lastSite = site
}
}
func nextSite() *ConfigSite {
if lastSite == nil {
return Config.Sites[0]
}
for i, site := range Config.Sites {
if site == lastSite {
if i == len(Config.Sites)-1 {
return Config.Sites[0]
}
return Config.Sites[i+1]
}
}
panic("unreachable, maybe Config.Sites empty")
}