Skip to content
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

Add ability to suppress Linkerd error response body and header #2201

Open
1 of 2 tasks
chrismikehogan opened this issue Jan 8, 2019 · 7 comments
Open
1 of 2 tasks

Comments

@chrismikehogan
Copy link

Issue Type:

  • Bug report
  • Feature request

Problem

We are trying to use Linkerd's dtab feature to build very large, dynamic routing tables. The goal to use Linkerd (instead of, e.g. Consul) to control which versions of which applications get routed to when a a request for a particular service is received.

This requires us to dynamically build most of our dtab, and requires that the dtab have an explicit dentry for every service in our eco system. E.g.:

...
/svc/cool-thing => /tagged/ver-1.3/cool-thing;
/svc/lame-thing => 0.1 * /tagged/ver-2.0/lame-thing & 0.9 * /tagged/ver-1.8/lame-thing;
...

This means that our dtab will get very large! The example I'm working with at the moment is 1811 lines long, and 143kb.

When linkerd errors in some way (say when a requested service is not found), it currently 502s and sends back an error message that contains, among other things, the entire dtab in both the body and a response header.

Fortunately, Linkerd appears to truncate the response header field instead of blowing up. But I think it would be useful to be able to suppress this verbose response by default, exposing it only if the client provided a debug header.

Possible solution

Provide a configuration option to suppress verbose error responses by default.
Add support for a debug header that results in the verbose error response.

@dadjeibaah
Copy link
Contributor

👋 @chrismikehogan, Thanks for filing this. FWIW, there is a config parameter called clearContext that can be set at the router level of the config. It's a server side configuration so you won't have the ability to dynamically turn it on or off per request.

@chrismikehogan
Copy link
Author

I saw that flag in the configuration docs, but it wasn't obvious to me that it would do what I wanted, in addition to what the docs said it does:

if true, all headers that set Linkerd contexts are removed from inbound requests. Useful for servers exposed on untrusted networks.

We definitely don't wan't the behavior described in the docs, even if it got us the suppressed error responses.

@dadjeibaah
Copy link
Contributor

Ah, that's right, it also gets applied to inbound requests as well so that wouldn't work.

@dadjeibaah
Copy link
Contributor

Thinking about this a little bit more, do you think it would be better to mimic what Linkerd does to the l5d-err header? So instead of sending back the entire dtab, Linkerd would truncate the dtab sent in the body if it is more than a specific number of lines?

The config parameter could definitely help but I feel that adding more implicit behavior through a header might increase the complexity of Linkerd's per-request handler. I am thinking that an error response with that much verbosity might not be as useful anyway and so it might be better to just truncate it. WDYT?

/cc @adleong

@adleong
Copy link
Member

adleong commented Jan 14, 2019

Truncating the response sounds great to me

@chrismikehogan
Copy link
Author

Truncating would work perfectly for us as well, even more so if the level of truncation could be controlled.

We could take or leave the concept debug header adding additional info.

@andrii-minchekov
Copy link

It's a great idea to truncate a response body in case of a mesh error (request timeout or bad routing, etc) or just unify all errors to have a generic error body for all cases. It will much simplify client side because now it's a headache to handle all this different structures of a response body for each error.
Looking forward to this important fix.

adleong pushed a commit that referenced this issue Aug 20, 2019
…KB, which can be used to limit the body of a http error response. This is different from the already existing maxResponseKB which limits the body of any http response, error or not. By default maxErrResponseKB has the same value as maxResponseKB which is 5MB. (#2291)

Here https://api.linkerd.io/1.6.1/linkerd/index.html#http-1-1-protocol, I've found two http config options here which can be used to truncate large headers or response bodies as requested for #2201:
maxHeadersKB | 8 | The maximum size of all headers in an HTTP message.
maxResponseKB | 5120 | The maximum size of a non-chunked HTTP response payload.

maxHeadersKB was already implemented and supported for l5d-err headers, I've done some tests with large dtabs and the l5d-err headers are truncated to the size specified by maxHeadersKB.

maxResponseKB was only parsed by HttpConfig.scala but was not implemented/supported by the rest of the Linderd code. This pull request adds support for maxResponseKB limit when constructing responses containing l5d-err header, what it does it just truncates the error response body to the limit specified by the maxResponseKB. The option name is somehow misleading, as one might expected the truncation to be done for the http response packet size instead of the http response body size, more precisely for error response body size. 

With this fix someone setting the config maxResponseKB / hparam.MaxResponseSize to a value lower than the 5120 default, will obtain truncation of the err response body size.

IMO A better approach would be to have two new config options specific to err headers and err response bodies, called maxErrHeadersKB and maxErrResponseKB. In this way users would benefit by the standard limits for headers and reponses and also have a much finer control over err headers and err responses.

Signed-off-by: dst4096 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

4 participants