Skip to content

access log: add response flag filter#3536

Merged
mattklein123 merged 19 commits intomasterfrom
response-flag-log-filter
Jul 2, 2018
Merged

access log: add response flag filter#3536
mattklein123 merged 19 commits intomasterfrom
response-flag-log-filter

Conversation

@junr03
Copy link
Member

@junr03 junr03 commented Jun 4, 2018

access log: add response flag filter

After #3299 merged log lines for gRPC requests that would have resulted in non-200 HTTP status codes in the past (for instance an unroutable request 404 and NR response flag), now result in a 200 HTTP status code. This can potentially filter out log lines that were previously being logged.

This PR adds an access log filter, that prints log lines if an Envoy response flag is set.

Testing: unit tests for the access log filter, and a new API call for the request info class.

Docs Changes:
Added documentation to the filter. And release notes.

Release Notes:
Added release notes.

Jose Nino added 6 commits June 1, 2018 16:42
Signed-off-by: Jose Nino <jnino@lyft.com>
fmt
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
fmt
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
// A list of the response flags can be found
// in the access log formatter :ref:`documentation<config_access_log_format_response_flags>`.
message ResponseFlagFilter {
}
Copy link
Member Author

Choose a reason for hiding this comment

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

alternatively I thought about adding an option to specify the flags you care about. But I think that response flags are important, and infrequent enough to have the filter filter on all of them. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

One way to achieve both settings is have an array field that will specify which response flags to log on and if that field is empty default to all response flags? (or have an enum that says all)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah +1 to what @ccaraman said. I would do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that is what I thought, will add.

@junr03
Copy link
Member Author

junr03 commented Jun 4, 2018

@zuercher can you do a first pass?

@junr03 junr03 requested a review from zuercher June 4, 2018 18:56
@zuercher
Copy link
Member

zuercher commented Jun 5, 2018

Nothing jumps out -- I'll have another look when you update with the requested change.

@junr03
Copy link
Member Author

junr03 commented Jun 8, 2018

quick update here: taking a bit longer because I needed to take a wide detour to protoc-gen-validate. I want to add a rule to the flags field like:
repeated string flags = 1 [(validate.rules).repeated.items.string = {in: ["foo", "bar"]}];
but there is a bug in protoc-gen-validate that is generating incorrect code. Will update here once I fix there.

PR in pgv fixing https://github.com/lyft/protoc-gen-validate/pull/78

wip
Signed-off-by: Jose Nino <jnino@lyft.com>
@stale
Copy link

stale bot commented Jun 18, 2018

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label Jun 18, 2018
Jose Nino added 3 commits June 20, 2018 14:34
wip
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Jun 21, 2018
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Member Author

junr03 commented Jun 21, 2018

@zuercher sorry for the delay here. PR is now up to date.

Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

I think it needs some extra testing but otherwise looks good.

/**
* @return whether any response flag is set or not.
*/
virtual bool getResponseFlag() const PURE;
Copy link
Member

Choose a reason for hiding this comment

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

nit: should this be hasResponseFlag()?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I think that is a better name, and also a better name for the other function getResponseFlag(ResponseFlag response_flag). I wanted to preserve naming. But now that you brought it up again I think it is probably better for clarity to change both names.

absl::optional<RequestInfo::ResponseFlag> response_flag =
RequestInfo::ResponseFlagUtils::toResponseFlag(config.flags(i));
// The config has been validated. Therefore, every flag in the config will have a mapping.
RELEASE_ASSERT(response_flag.has_value());
Copy link
Member

Choose a reason for hiding this comment

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

At this point the set of flags is reproduced in a few places:

  • RequestInfo::ResponseFlag
  • ResponseFlagUtils
  • the ResponseFlagFilter proto message's validation

I think it would be good to have a test that validates each response flag to prove that the list in the validation is correct, and a similar test for toResponseFlag to prove that each flag is in the static map there.

Copy link
Member Author

Choose a reason for hiding this comment

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

👌 will add

Copy link
Member

Choose a reason for hiding this comment

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

nit, would probably switch this to normal ASSERT

Signed-off-by: Jose Nino <jnino@lyft.com>
@zuercher
Copy link
Member

Looks good. I'll approve once the merge conflict is fixed.

Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Member Author

junr03 commented Jun 25, 2018

@zuercher thanks. The conflict has been resolved but the build is going to fail because I moved the PGV sha, and we haven't merged the necessary fix yet (https://github.com/lyft/protoc-gen-validate/pull/78). I'll ping you when that gets merged.

Signed-off-by: Jose Nino <jnino@lyft.com>
zuercher
zuercher previously approved these changes Jun 26, 2018
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM, just a few small comments. Nice!

// in the access log formatter :ref:`documentation<config_access_log_format_response_flags>`.
message ResponseFlagFilter {
// Only responses with the any of the flags listed in this field will be logged.
// This field is optional if it is not specified, then any response flag will pass
Copy link
Member

Choose a reason for hiding this comment

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

nit: "This field is optional. If it ..."

* access log: added ability to format START_TIME.
* access log: added DYNAMIC_METADATA :ref:`access log formatter <config_access_log_format>`.
* access log: added :ref:`HeaderFilter <envoy_api_msg_config.filter.accesslog.v2.HeaderFilter>`
to filter logs based on request headers
Copy link
Member

Choose a reason for hiding this comment

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

Move to 1.8.0 section.

absl::optional<RequestInfo::ResponseFlag> response_flag =
RequestInfo::ResponseFlagUtils::toResponseFlag(config.flags(i));
// The config has been validated. Therefore, every flag in the config will have a mapping.
RELEASE_ASSERT(response_flag.has_value());
Copy link
Member

Choose a reason for hiding this comment

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

nit, would probably switch this to normal ASSERT

const Http::HeaderMap& request_headers) override;

private:
RequestInfo::RequestInfoImpl info_;
Copy link
Member

Choose a reason for hiding this comment

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

nit: It seems a little odd to me to have a full request info here, but it's probably fine. Just throwing that out there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it is a little clunky. I guess I could just maintain the uint64_t for the flags and instead of using the setResponseFlag abstraction do the |= myself.

That way I also can get rid of the currentResponseFlags() method and add less stuff to that api.

wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

yeah I would probably do that...

Jose Nino added 2 commits June 28, 2018 11:00
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
Jose Nino added 2 commits June 28, 2018 12:37
Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Member Author

junr03 commented Jun 28, 2018

@mattklein123 comments are addressed.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM, small comments.

1.8.0 (Pending)
===============
* access log: added :ref:`response flag filter <envoy_api_msg_config.filter.accesslog.v2.ResponseFlagFilter>` to filter based on the presence of Envoy response flags.
to filter logs based on request headers.
Copy link
Member

Choose a reason for hiding this comment

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

duplicated text / please break on 100 chars


#include "common/http/header_utility.h"
#include "common/protobuf/protobuf.h"
#include "common/request_info/request_info_impl.h"
Copy link
Member

Choose a reason for hiding this comment

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

This header change can be reverted I believe here and above.

/**
* @return whether any response flag is set or not.
*/
virtual bool hasResponseFlag() const PURE;
Copy link
Member

Choose a reason for hiding this comment

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

IMO this function name is a little strange given the other overload of same name Can we call it hasAnyResponseFlag() or something similar?

Signed-off-by: Jose Nino <jnino@lyft.com>
@junr03
Copy link
Member Author

junr03 commented Jun 29, 2018

@mattklein123 updated

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

nice

@mattklein123 mattklein123 merged commit 9365720 into master Jul 2, 2018
@mattklein123 mattklein123 deleted the response-flag-log-filter branch July 2, 2018 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants