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

Function Run

support/support.go:1033–1144  ·  view source on GitHub ↗

Run generates a support bundle with the given dependencies.

(ctx context.Context, d *Deps)

Source from the content-addressed store, hash-verified

1031
1032// Run generates a support bundle with the given dependencies.
1033func Run(ctx context.Context, d *Deps) (*Bundle, error) {
1034 var b Bundle
1035 if d.Client == nil {
1036 return nil, xerrors.Errorf("developer error: missing client!")
1037 }
1038
1039 // Ensure we capture logs from the client.
1040 var logw strings.Builder
1041 d.Log = d.Log.AppendSinks(sloghuman.Sink(&logw))
1042 d.Client.SetLogger(d.Log)
1043 defer func() {
1044 b.Logs = strings.Split(logw.String(), "\n")
1045 }()
1046
1047 // No point running without auth as minimal information available.
1048 me, err := d.Client.User(ctx, codersdk.Me)
1049 if err != nil {
1050 return nil, err
1051 }
1052 d.Log.Info(ctx, "running as user", slog.F("me", me))
1053
1054 totalCap := d.WorkspacesTotalCap
1055
1056 var eg errgroup.Group
1057 eg.Go(func() error {
1058 di := DeploymentInfo(ctx, d.Client, d.Log, totalCap)
1059
1060 if di.Workspaces != nil && totalCap > 0 {
1061 origTotal := di.Workspaces.Count // server-reported total
1062
1063 // Ensure at most 'totalCap' are returned (covers non-early-exit path).
1064 if len(di.Workspaces.Workspaces) > totalCap {
1065 di.Workspaces.Workspaces = di.Workspaces.Workspaces[:totalCap]
1066 }
1067 // If we returned fewer than the original total, log a truncation.
1068 if origTotal > len(di.Workspaces.Workspaces) {
1069 di.Workspaces.Count = len(di.Workspaces.Workspaces)
1070 d.Log.Warn(ctx, "workspace list truncated",
1071 slog.F("cap", totalCap),
1072 slog.F("original_total", origTotal),
1073 )
1074 }
1075 }
1076 b.Deployment = di
1077 return nil
1078 })
1079 eg.Go(func() error {
1080 wi := WorkspaceInfo(ctx, d.Client, d.Log, d.WorkspaceID)
1081 b.Workspace = wi
1082 return nil
1083 })
1084 eg.Go(func() error {
1085 ni := NetworkInfo(ctx, d.Client, d.Log)
1086 b.Network = ni
1087 return nil
1088 })
1089 eg.Go(func() error {
1090 ai := AgentInfo(ctx, d.Client, d.Log, d.AgentID)

Callers 2

supportBundleMethod · 0.92
TestRunFunction · 0.92

Calls 15

DeploymentInfoFunction · 0.85
WorkspaceInfoFunction · 0.85
NetworkInfoFunction · 0.85
AgentInfoFunction · 0.85
collectPprofFunction · 0.85
GoMethod · 0.80
TemplateMethod · 0.80
DownloadWithFormatMethod · 0.80
SetLoggerMethod · 0.65
UserMethod · 0.65
TemplateVersionMethod · 0.65
WaitMethod · 0.65

Tested by 1

TestRunFunction · 0.74