-
Notifications
You must be signed in to change notification settings - Fork 619
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
Access logging fails in combination with proxy gzipping #460
Comments
No idea. Let me have a look. |
After looking at golang/go#19895 I think there could be an issue with the way your service responds to health checks. It seems to be sending data after it has responded to the health check. |
True, I see that response on a HEAD request, where it shouldn't return that. However, would that block all logging? I don't see any other log besides those health checks that produce invalid logs, while fabio is routing a lot of traffic. Running fabio locally (against the production Consul) I get:
which was 1 GET and 1 HEAD request. So then they both show up. Also, the healtch checks that occur are actually GET requests (generated by Nomad), so I don't think the HEAD part is the problem? |
The access log should go to The leveled logger looks at the first two bytes of the log line to determine the level and if that isn't in the right format prints |
Okay, found the culprit! Removing that makes it work :). Tried other regexes but that didn't make a difference. Renamed the issue. Ps. thanks for making fabio start so fast, tried a lot of different configs 😊 |
Cool. Is this the default regex from the properties file?
I’m glad you like it 🙂
—
Frank Schröder
… On 6. Mar 2018, at 16:53, Tino de Bruijn ***@***.***> wrote:
Okay, found the culprit!
FABIO_proxy_gzip_contenttype = "^(text/.*|application/(javascript|json|font-woff|xml)|.*\+(json|xml))(;.*)?$"
Removing that makes it work :). Tried other regexes but that didn't make a difference.
Ps. thanks for making fabio start so fast, tried a lot of different configs 😊
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Yes, it is. But |
Okay, I'm getting somewhere. If I apply this patch, it still doesn't log (so this doesn't change the handler, but just wraps it): diff --git a/proxy/gzip/gzip_handler.go b/proxy/gzip/gzip_handler.go
index 9cdf70d..0bc6ad3 100644
--- a/proxy/gzip/gzip_handler.go
+++ b/proxy/gzip/gzip_handler.go
@@ -11,6 +11,7 @@ import (
"bufio"
"compress/gzip"
"errors"
+ "fmt"
"io"
"net"
"net/http"
@@ -36,17 +37,23 @@ var gzipWriterPool = sync.Pool{
// body if the client supports it (via the Accept-Encoding header) and the
// response Content-Type matches the contentTypes expression.
func NewGzipHandler(h http.Handler, contentTypes *regexp.Regexp) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Header().Add(headerVary, headerAcceptEncoding)
+ fmt.Printf("Old handler: %z\n", h)
+ nh := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ // w.Header().Add(headerVary, headerAcceptEncoding)
if acceptsGzip(r) {
- gzWriter := NewGzipResponseWriter(w, contentTypes)
- defer gzWriter.Close()
- h.ServeHTTP(gzWriter, r)
+ fmt.Println("GZIPPED")
+ // gzWriter := NewGzipResponseWriter(w, contentTypes)
+ // defer gzWriter.Close()
+ h.ServeHTTP(w, r)
+ // fmt.Printf("GZIPPED", )
} else {
+ fmt.Println("NOT GZIPPED")
h.ServeHTTP(w, r)
}
})
+ fmt.Printf("New handler: %z\n", nh)
+ return nh
}
type GzipResponseWriter struct { Output:
If I just make
Any suggestions on how to tackle this? |
Ah, damn. The ugly hack for getting the response rears its head... I'll comment on the PR. That's a good catch. Thanks a lot for finding this! |
The code that captured the content length and the status code for the access logger depended on the http.Handler to be of a certain type. Wrapping the handler in a gzip handler broke this silently. This fix removes that dependency and instead wraps the response writer directly to capture the values required for access logging. Fixes #460
Issue #460: Fix access logging when gzip is enabled
👍 Works like a charm. Thanks! |
With fabio 1.5.8 I've set:
and can see that fabio uses that after restart.
The only logs it output (besides route changes and errors are like this):
The json you see in there is the response of one of my service
/status/
urls, which is used for health checking, also remotely through fabio.It does work when I run it locally like:
docker run --rm -it -p 9999:9999 -p 9998:9998 -e FABIO_registry_consul_addr=10.0.0.12:8500 -e FABIO_log_access_target="stdout" fabiolb/fabio
.Any idea what the culprit could be?
The text was updated successfully, but these errors were encountered: