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

Method Run

coderd/healthcheck/workspaceproxy.go:39–108  ·  view source on GitHub ↗
(ctx context.Context, opts *WorkspaceProxyReportOptions)

Source from the content-addressed store, hash-verified

37}
38
39func (r *WorkspaceProxyReport) Run(ctx context.Context, opts *WorkspaceProxyReportOptions) {
40 r.Healthy = true
41 r.Severity = health.SeverityOK
42 r.Warnings = make([]health.Message, 0)
43 r.Dismissed = opts.Dismissed
44
45 if opts.WorkspaceProxiesFetchUpdater == nil {
46 opts.WorkspaceProxiesFetchUpdater = &AGPLWorkspaceProxiesFetchUpdater{}
47 }
48
49 // If this fails, just mark it as a warning. It is still updated in the background.
50 if err := opts.WorkspaceProxiesFetchUpdater.Update(ctx); err != nil {
51 r.Severity = health.SeverityWarning
52 r.Warnings = append(r.Warnings, health.Messagef(health.CodeProxyUpdate, "update proxy health: %s", err))
53 return
54 }
55
56 proxies, err := opts.WorkspaceProxiesFetchUpdater.Fetch(ctx)
57 if err != nil {
58 r.Healthy = false
59 r.Severity = health.SeverityError
60 r.Error = health.Errorf(health.CodeProxyFetch, "fetch workspace proxies: %s", err)
61 return
62 }
63
64 for _, proxy := range proxies.Regions {
65 if !proxy.Deleted {
66 r.WorkspaceProxies.Regions = append(r.WorkspaceProxies.Regions, proxy)
67 }
68 }
69 if r.WorkspaceProxies.Regions == nil {
70 r.WorkspaceProxies.Regions = make([]codersdk.WorkspaceProxy, 0)
71 }
72
73 // Stable sort based on create timestamp.
74 sort.Slice(r.WorkspaceProxies.Regions, func(i int, j int) bool {
75 return r.WorkspaceProxies.Regions[i].CreatedAt.Before(r.WorkspaceProxies.Regions[j].CreatedAt)
76 })
77
78 var total, healthy, warning int
79 var errs []string
80 for _, proxy := range r.WorkspaceProxies.Regions {
81 total++
82 if proxy.Healthy {
83 // Warnings in the report are not considered unhealthy, only errors.
84 healthy++
85 }
86 if len(proxy.Status.Report.Warnings) > 0 {
87 warning++
88 }
89
90 for _, err := range proxy.Status.Report.Warnings {
91 r.Warnings = append(r.Warnings, health.Messagef(health.CodeProxyUnhealthy, "%s: %s", proxy.Name, err))
92 }
93 for _, err := range proxy.Status.Report.Errors {
94 errs = append(errs, fmt.Sprintf("%s: %s", proxy.Name, err))
95 }
96 }

Callers 3

WorkspaceProxyMethod · 0.95
TestWorkspaceProxiesFunction · 0.95

Calls 7

appendErrorMethod · 0.95
MessagefFunction · 0.92
ErrorfFunction · 0.92
calculateSeverityFunction · 0.85
UpdateMethod · 0.65
FetchMethod · 0.65
ValueMethod · 0.45

Tested by 2

TestWorkspaceProxiesFunction · 0.76