add debug option to save all map responses

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2023-07-17 11:13:48 +02:00 committed by Kristoffer Dalby
parent f73172fb21
commit 78268d78a0
3 changed files with 76 additions and 4 deletions

View file

@ -212,6 +212,7 @@ func New(
env := []string{
"HEADSCALE_PROFILING_ENABLED=1",
"HEADSCALE_PROFILING_PATH=/tmp/profile",
"HEADSCALE_DEBUG_DUMP_MAPRESPONSE_PATH=/tmp/mapresponses",
}
for key, value := range hsic.env {
env = append(env, fmt.Sprintf("%s=%s", key, value))
@ -339,6 +340,14 @@ func (t *HeadscaleInContainer) Shutdown() error {
)
}
err = t.SaveMapResponses("/tmp/control")
if err != nil {
log.Printf(
"Failed to save mapresponses from control: %s",
fmt.Errorf("failed to save mapresponses from control: %w", err),
)
}
return t.pool.Purge(t.container)
}
@ -354,6 +363,24 @@ func (t *HeadscaleInContainer) SaveProfile(savePath string) error {
return err
}
err = os.WriteFile(
path.Join(savePath, t.hostname+"maps.tar"),
tarFile,
os.ModePerm,
)
if err != nil {
return err
}
return nil
}
func (t *HeadscaleInContainer) SaveMapResponses(savePath string) error {
tarFile, err := t.FetchPath("/tmp/mapresponses")
if err != nil {
return err
}
err = os.WriteFile(
path.Join(savePath, t.hostname+".pprof.tar"),
tarFile,