Skip to content

fix: improve wsproxy error when proxyurl is set to a primary #11586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 12, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jan 11, 2024

fixes: #11116

Screenshot from 2024-01-11 16-51-38

Check header for proxy instance, and check content-type for non json. If it's not a json payload, the json error is almost completely useless.

I think this could be formatted better, but it has the helpful information, which is enough for now imo.

Copy link
Member Author

Emyrk commented Jan 11, 2024

In this stack: 🐛 Fix wsproxy error with primary proxyurl(?)

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @Emyrk and the rest of your teammates on Graphite Graphite

Base automatically changed from stevenmasley/wsproxy_errors to main January 11, 2024 22:55
@Emyrk Emyrk force-pushed the stevenmasley/wsproxy_no_json_error branch from 7c82247 to 9656c7a Compare January 11, 2024 22:57
Comment on lines 279 to 307
isCoderErr := fmt.Errorf("proxy url %q is not a coder proxy instance, verify the url is correct", reqURL)
if resp.Header.Get(codersdk.BuildVersionHeader) != "" {
isCoderErr = fmt.Errorf("proxy url %q is a coder instance, but unable to decode the response payload. Could this be a primary coderd and not a proxy?", reqURL)
}

// If the response is not json, then the user likely input a bad url that returns status code 200.
// This is very common, since most webpages do return a 200. So let's improve the error message.
if notJsonErr := codersdk.ExpectJSONMime(resp); notJsonErr != nil {

err = errors.Join(
isCoderErr,
fmt.Errorf("attempted to query health at %q but got back the incorrect content type: %w", reqURL, notJsonErr),
)

status.Report.Errors = []string{
err.Error(),
}
status.Status = Unhealthy
break
}

// If we cannot read the report, mark the proxy as unhealthy.
status.Report.Errors = []string{fmt.Sprintf("failed to decode health report: %s", err.Error())}
status.Report.Errors = []string{
errors.Join(
isCoderErr,
fmt.Errorf("received a status code 200, but failed to decode health report body: %w", err.Error()),
).Error(),
}
status.Status = Unhealthy
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The json decode error is usually absolute garbage. So this should improve it.

It also does a header check to instantly tell the user if they are not even pointed at a coder instance at all (proxy or otherwise)

@Emyrk Emyrk requested review from sreya and bpmct January 11, 2024 22:58
@Emyrk Emyrk enabled auto-merge (squash) January 12, 2024 14:56
@Emyrk Emyrk merged commit 9052920 into main Jan 12, 2024
@Emyrk Emyrk deleted the stevenmasley/wsproxy_no_json_error branch January 12, 2024 20:32
@github-actions github-actions bot locked and limited conversation to collaborators Jan 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

workspace proxies: unique health check error if being treated as a subdomain app
2 participants