Skip to content

Commit

Permalink
fix(optimizer): use bird directory instead of runtime cache
Browse files Browse the repository at this point in the history
Closes: #182
  • Loading branch information
natesales committed Jun 27, 2023
1 parent eee94f4 commit 8e22178
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/optimizer/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,20 @@ func computeMetrics(o *config.Optimizer, global *config.Config, noConfigure bool
var alerts []string
peerASN, peerName := parsePeerDelimiter(peer)
if p[peer].PacketLoss >= o.PacketLossThreshold {
alerts = append(alerts, fmt.Sprintf("Peer AS%s %s met or exceeded maximum allowable packet loss: %f >= %f",
peerASN, peerName, p[peer].PacketLoss, o.PacketLossThreshold))
alerts = append(
alerts,
fmt.Sprintf("Peer AS%s %s met or exceeded maximum allowable packet loss: %.1f >= %.1f",
peerASN, peerName, p[peer].PacketLoss, o.PacketLossThreshold,
),
)
}
if p[peer].Latency >= time.Duration(o.LatencyThreshold)*time.Millisecond {
alerts = append(alerts, fmt.Sprintf("Peer AS%s %s met or exceeded maximum allowable latency: %v >= %v",
peerASN, peerName, p[peer].Latency, o.LatencyThreshold))
alerts = append(
alerts,
fmt.Sprintf("Peer AS%s %s met or exceeded maximum allowable latency: %v >= %v",
peerASN, peerName, p[peer].Latency, o.LatencyThreshold,
),
)
}

// If there is at least one alert,
Expand Down Expand Up @@ -187,7 +195,7 @@ func modifyPref(
dryRun bool,
) {
peerASN, peerName := parsePeerDelimiter(peerPair)
fileName := path.Join(cacheDirectory, fmt.Sprintf("AS%s_%s.conf", peerASN, *util.Sanitize(peerName)))
fileName := path.Join(birdDirectory, fmt.Sprintf("AS%s_%s.conf", peerASN, *util.Sanitize(peerName)))
peerFile, err := os.ReadFile(fileName)
if err != nil {
log.Fatalf("reading peer file: %s", err)
Expand All @@ -211,7 +219,7 @@ func modifyPref(
}

// Run BIRD config validation
bird.Validate(birdBinary, cacheDirectory)
bird.Validate(birdBinary, birdDirectory)

if !dryRun {
bird.MoveCacheAndReconfigure(birdDirectory, cacheDirectory, birdSocket, noConfigure)
Expand Down

0 comments on commit 8e22178

Please sign in to comment.