-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Ultimate Access log filter #2988
Conversation
7136639
to
49b0e13
Compare
ff84671
to
6fba2e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
types/logs.go
Outdated
func (f *FieldsHeadersNames) Set(value string) error { | ||
fields := strings.Fields(value) | ||
|
||
//f = make(FieldsHeadersNames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete comment?
RetryAttempts | ||
``` | ||
|
||
Deprecated way (before 1.4): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe adding a DANGER
for the deprecated fields, as described here
types/logs.go
Outdated
// Set's argument is a string to be parsed to set the flag. | ||
// It's a comma-separated list, so we split it. | ||
func (f *FieldsHeadersNames) Set(value string) error { | ||
fields := strings.Fields(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings.Fields
splits on white spaces and not a comma-separated list
middlewares/accesslog/parser.go
Outdated
submatch := regex.FindStringSubmatch(data) | ||
result := make(map[string]string) | ||
|
||
if len(submatch) > 13 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left mostly minor nit-picks and improvement suggestions. 👍 for the PR!
One thing I'm still convinced that we should do is to remove "redundant" fields from the access logs as described in #2875 (comment)
docs/configuration/logs.md
Outdated
|
||
[accessLog.filters] | ||
|
||
# statusCodes keep on only access logs with status code in the range |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could write it like: "keep only access logs with status codes in the specified range". I find it a bit easier to read.
docs/configuration/logs.md
Outdated
# Optional | ||
# Default: "keep" | ||
# | ||
defaultMode = "keep|drop" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should try to provide working examples, so probably just showing "keep" as example. WDYT?
docs/configuration/logs.md
Outdated
|
||
[accessLog.filters] | ||
|
||
# statusCodes keep on only access logs with status code in the range |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as comment below.
docs/configuration/logs.md
Outdated
# Optional | ||
# Default: "keep" | ||
# | ||
defaultMode = "drop|keep|redact" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in the comment above.
integration/access_log_test.go
Outdated
c.Assert(tokens[13], checker.Matches, `^\d+ms$`) | ||
c.Assert(results[accesslog.OriginStatus], checker.Equals, v.code) | ||
c.Assert(results[accesslog.RequestCount], checker.Equals, fmt.Sprintf("%d", i+1)) | ||
c.Assert(results[accesslog.FrontendName], checker.Matches, `^"?`+v.value+`.*$`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the frontend name stored in .value
?
types/logs.go
Outdated
} | ||
|
||
// FieldsHeadersNames holds maps of fields with specific mode | ||
type FieldsHeadersNames map[string]string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with the pluar form: FieldHeaderNames
types/logs.go
Outdated
defaultKeep := true | ||
if f != nil { | ||
defaultKeep = checkFieldValue(f.DefaultMode, defaultKeep) | ||
v, ok := f.Names[field] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could merge this line with the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An oversight here or do you disagree?
types/logs.go
Outdated
} | ||
} | ||
|
||
// KeepHeader check if header need to be keep, drop or redact and return the status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some grammar mistakes here, I think it should be: "KeepHeader checks if the headers need to be kept, dropped or redacted and returns the status".
expected StatusCodes | ||
}{ | ||
{ | ||
desc: "One value should return StatusCodes of size 1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "should return StatusCodes ..." stuff can be dropped from the test descriptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super hot about this one, I just think it's good to decrease optical "noise" and redundant explanations.
} | ||
} | ||
|
||
func TestStatusCodesGet(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to test the Getter? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, this won't block my approval but adding ~30 lines of code to test one line that it is in fact super trivial and always does the same doesn't seem worth it.
@marco-jantke Thanks for your review. I just push some fixes :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments on the open points from my review, but they don't block my approval. Proceed with them as you think it's best.
So giving my approval, noice work! :-)
7030deb
to
7d3e9fd
Compare
@mmatur one thing I just missed/forgot again. What do you think about the comment I brought up now two times to drop redundant fields? See #2988 (review) |
@marco-jantke I am in favor. Seems like that would be follow-up PR, right? |
@marco-jantke @danieladams456 we think this be breaking for people who parse the log output. I added the need in this issue #2212 |
What does this PR do?
This PR is an implementation of #2875.
Motivation
Be able to customize accesslog like it was asked over PRs #2853 and #2397
Closes #2853, #2397, #2875
More