MCPcopy Index your code
hub / github.com/coder/coder / NetworkInfo

Function NetworkInfo

support/support.go:366–442  ·  view source on GitHub ↗
(ctx context.Context, client *codersdk.Client, log slog.Logger)

Source from the content-addressed store, hash-verified

364}
365
366func NetworkInfo(ctx context.Context, client *codersdk.Client, log slog.Logger) Network {
367 var (
368 n Network
369 eg errgroup.Group
370 )
371
372 eg.Go(func() error {
373 coordResp, err := client.Request(ctx, http.MethodGet, "/api/v2/debug/coordinator", nil)
374 if err != nil {
375 return xerrors.Errorf("fetch coordinator debug page: %w", err)
376 }
377 defer coordResp.Body.Close()
378 if coordResp.StatusCode == http.StatusForbidden || coordResp.StatusCode == http.StatusUnauthorized {
379 _, _ = io.Copy(io.Discard, coordResp.Body)
380 log.Warn(ctx, "unable to fetch coordinator debug page",
381 slog.F("status", coordResp.StatusCode))
382 return nil
383 }
384 bs, err := io.ReadAll(coordResp.Body)
385 if err != nil {
386 return xerrors.Errorf("read coordinator debug page: %w", err)
387 }
388 n.CoordinatorDebug = string(bs)
389 return nil
390 })
391
392 eg.Go(func() error {
393 tailResp, err := client.Request(ctx, http.MethodGet, "/api/v2/debug/tailnet", nil)
394 if err != nil {
395 return xerrors.Errorf("fetch tailnet debug page: %w", err)
396 }
397 defer tailResp.Body.Close()
398 if tailResp.StatusCode == http.StatusForbidden || tailResp.StatusCode == http.StatusUnauthorized {
399 _, _ = io.Copy(io.Discard, tailResp.Body)
400 log.Warn(ctx, "unable to fetch tailnet debug page",
401 slog.F("status", tailResp.StatusCode))
402 return nil
403 }
404 bs, err := io.ReadAll(tailResp.Body)
405 if err != nil {
406 return xerrors.Errorf("read tailnet debug page: %w", err)
407 }
408 n.TailnetDebug = string(bs)
409 return nil
410 })
411
412 eg.Go(func() error {
413 // Need connection info to get DERP map for netcheck
414 connInfo, err := workspacesdk.New(client).AgentConnectionInfoGeneric(ctx)
415 if err != nil {
416 log.Warn(ctx, "unable to fetch generic agent connection info")
417 return nil
418 }
419 n.ConnectionInfo = connInfo
420 var rpt derphealth.Report
421 rpt.Run(ctx, &derphealth.ReportOptions{
422 DERPMap: connInfo.DERPMap,
423 })

Callers 1

RunFunction · 0.85

Calls 12

RunMethod · 0.95
NewFunction · 0.92
RunInterfacesReportFunction · 0.92
GoMethod · 0.80
CloseMethod · 0.65
CopyMethod · 0.65
WaitMethod · 0.65
RequestMethod · 0.45
ErrorfMethod · 0.45
ReadAllMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected