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

Ultimate Access log filter #2988

Merged
merged 17 commits into from
Mar 14, 2018
Merged

Conversation

mmatur
Copy link
Member

@mmatur mmatur commented Mar 9, 2018

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

  • Added/updated tests
  • Added/updated documentation

@mmatur mmatur added this to the 1.6 milestone Mar 9, 2018
@mmatur mmatur force-pushed the feature/utimate-accesslogs branch from 7136639 to 49b0e13 Compare March 12, 2018 09:45
@mmatur mmatur force-pushed the feature/utimate-accesslogs branch from ff84671 to 6fba2e5 Compare March 13, 2018 14:28
Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@nmengin nmengin left a 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)
Copy link
Contributor

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):
Copy link
Contributor

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)
Copy link
Contributor

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

submatch := regex.FindStringSubmatch(data)
result := make(map[string]string)

if len(submatch) > 13 {
Copy link
Contributor

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?

Copy link
Contributor

@m3co-code m3co-code left a 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)


[accessLog.filters]

# statusCodes keep on only access logs with status code in the range
Copy link
Contributor

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.

# Optional
# Default: "keep"
#
defaultMode = "keep|drop"
Copy link
Contributor

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?


[accessLog.filters]

# statusCodes keep on only access logs with status code in the range
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as comment below.

# Optional
# Default: "keep"
#
defaultMode = "drop|keep|redact"
Copy link
Contributor

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.

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+`.*$`)
Copy link
Contributor

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
Copy link
Contributor

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]
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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",
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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) {
Copy link
Contributor

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? :)

Copy link
Contributor

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.

@mmatur
Copy link
Member Author

mmatur commented Mar 14, 2018

@marco-jantke Thanks for your review. I just push some fixes :)

Copy link
Contributor

@m3co-code m3co-code left a 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! :-)

@traefiker traefiker force-pushed the feature/utimate-accesslogs branch from 7030deb to 7d3e9fd Compare March 14, 2018 12:56
@traefiker traefiker merged commit 8d46892 into traefik:master Mar 14, 2018
@mmatur mmatur deleted the feature/utimate-accesslogs branch March 14, 2018 13:16
@m3co-code
Copy link
Contributor

@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)

@danieladams456
Copy link
Contributor

@marco-jantke I am in favor. Seems like that would be follow-up PR, right?

@ldez
Copy link
Contributor

ldez commented Mar 14, 2018

@marco-jantke @danieladams456 we think this be breaking for people who parse the log output.
For now, we will not change fields.

I added the need in this issue #2212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants