| 61 | } |
| 62 | |
| 63 | func getDebug(ctx context.Context, store database.Store) (HTMLDebug, error) { |
| 64 | out := HTMLDebug{} |
| 65 | coords, err := store.GetAllTailnetCoordinators(ctx) |
| 66 | if err != nil && !xerrors.Is(err, sql.ErrNoRows) { |
| 67 | return HTMLDebug{}, xerrors.Errorf("failed to query coordinators: %w", err) |
| 68 | } |
| 69 | peers, err := store.GetAllTailnetPeers(ctx) |
| 70 | if err != nil && !xerrors.Is(err, sql.ErrNoRows) { |
| 71 | return HTMLDebug{}, xerrors.Errorf("failed to query peers: %w", err) |
| 72 | } |
| 73 | tunnels, err := store.GetAllTailnetTunnels(ctx) |
| 74 | if err != nil && !xerrors.Is(err, sql.ErrNoRows) { |
| 75 | return HTMLDebug{}, xerrors.Errorf("failed to query tunnels: %w", err) |
| 76 | } |
| 77 | now := time.Now() // call this once so all our ages are on the same timebase |
| 78 | for _, coord := range coords { |
| 79 | out.Coordinators = append(out.Coordinators, coordToHTML(coord, now)) |
| 80 | } |
| 81 | for _, peer := range peers { |
| 82 | ph, err := peerToHTML(peer, now) |
| 83 | if err != nil { |
| 84 | return HTMLDebug{}, err |
| 85 | } |
| 86 | out.Peers = append(out.Peers, ph) |
| 87 | } |
| 88 | for _, tunnel := range tunnels { |
| 89 | out.Tunnels = append(out.Tunnels, tunnelToHTML(tunnel, now)) |
| 90 | } |
| 91 | return out, nil |
| 92 | } |
| 93 | |
| 94 | func coordToHTML(d database.TailnetCoordinator, now time.Time) *HTMLCoordinator { |
| 95 | return &HTMLCoordinator{ |