Skip to content

Commit

Permalink
Merge pull request #64 from m-lab/scamper-backup
Browse files Browse the repository at this point in the history
Add scamper-standalone as a backup option for scamper-daemon
  • Loading branch information
pboothe authored Dec 17, 2019
2 parents 8106ad9 + 99d9dd2 commit 8a95751
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
12 changes: 11 additions & 1 deletion caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
waitTime = flag.Duration("waitTime", 5*time.Second, "how long to wait between subsequent listings of open connections")
poll = flag.Bool("poll", true, "Whether the polling method should be used to see new connections.")
tracerType = flagx.Enum{
Options: []string{"paris-traceroute", "scamper", "scamper-daemon", "scamper-daemon-with-paris-backup"},
Options: []string{"paris-traceroute", "scamper", "scamper-daemon", "scamper-daemon-with-paris-backup", "scamper-daemon-with-scamper-backup"},
Value: "scamper",
}

Expand Down Expand Up @@ -97,6 +97,16 @@ func main() {
cancel()
wg.Done()
}()
// These are hacks - the scamper daemon should not fail at all.
case "scamper-daemon-with-scamper-backup":
cache = ipcache.New(ctx, scamperDaemon, *ipcache.IPCacheTimeout, *ipcache.IPCacheUpdatePeriod)
wg.Add(1)
go func() {
scamperDaemon.MustStart(ctx)
// When the scamper daemon dies, switch to scamper
cache.UpdateTracer(scamper)
wg.Done()
}()
case "scamper-daemon-with-paris-backup":
cache = ipcache.New(ctx, scamperDaemon, *ipcache.IPCacheTimeout, *ipcache.IPCacheUpdatePeriod)
wg.Add(1)
Expand Down
24 changes: 24 additions & 0 deletions caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ func TestMainWithConnectionListener(t *testing.T) {
main()
}

func TestMainWithBackupScamper(t *testing.T) {
dir, err := ioutil.TempDir("", "TestMainWithBackupScamper")
rtx.Must(err, "Could not create temp dir")
defer os.RemoveAll(dir)
srv := eventsocket.New(dir + "/events.sock")
rtx.Must(srv.Listen(), "Could not start the empty server")

*prometheusx.ListenAddress = ":0"
*eventsocket.Filename = dir + "/events.sock"
*outputPath = dir
*poll = false
*scamperCtrlSocket = dir + "/scamper.sock"
*scamperBin = "false"
tracerType.Value = "scamper-daemon-with-scamper-backup"

ctx, cancel = context.WithCancel(context.Background())
go srv.Serve(ctx)
go func() {
time.Sleep(1 * time.Second)
cancel()
}()
main()
}

func TestMainWithBackupPT(t *testing.T) {
dir, err := ioutil.TempDir("", "TestMainWithBackupPT")
rtx.Must(err, "Could not create temp dir")
Expand Down
2 changes: 2 additions & 0 deletions tracer/scamper.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ type ScamperDaemon struct {
// We expect this function to be mostly used as a goroutine:
// go d.MustStart(ctx)
func (d *ScamperDaemon) MustStart(ctx context.Context) {
scamperDaemonRunning.Set(1)
defer scamperDaemonRunning.Set(0)
derivedCtx, derivedCancel := context.WithCancel(ctx)
defer derivedCancel()
if _, err := os.Stat(d.ControlSocket); !os.IsNotExist(err) {
Expand Down
6 changes: 6 additions & 0 deletions tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ var (
},
[]string{"type", "error"},
)
scamperDaemonRunning = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "traces_scamper_daemon_running",
Help: "Whether the scamper daemon is running or not.",
},
)

// hostname of the current machine. Only call os.Hostname once, because the
// result should never change.
Expand Down

0 comments on commit 8a95751

Please sign in to comment.