forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
access log formatter: use new formatter context rather than multiple …
…parameters (1/3) (envoyproxy#30734) access log formatter: use new formatter context rather than multiple parameters (1/3) Additional Description: Part of templated formatter and access log support. HttpFormatterContext is used by the formatter to extract information of HTTP stream, like headers, trailers, etc. And now, this patchs will update the API of logger to take HttpFormatterContext rather than multiple independent parameters. NOTE 1: to ensure these changes could get reasonable review, I split it to three sub-patches. This is the first one and only update the emitLog(). NOTE 2: this PR won't change any logic or behavior be may effect building of third party folks. Sorry for that. :( NOTE3: this PR moved HttpFormatterContext to separated header file to avoid cycle dependency. NOTE4: this PR moved AccessLogInstanceFactory from envoy/server/access_log_config.h to envoy/access_log/access_log_config.h. Because this factory should be replaced by template finally and moved it in this patch could avoid further updates to loggers in following PRs. Risk Level: low. No logic update. Testing: n/a. Docs Changes: n/a. Release Notes: n/a. Platform Specific Features: n/a. Signed-off-by: wbpcode <wbphub@live.com>
- Loading branch information
code
authored
Nov 7, 2023
1 parent
a9d8eb3
commit cefd660
Showing
49 changed files
with
302 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#pragma once | ||
|
||
#include "envoy/data/accesslog/v3/accesslog.pb.h" | ||
#include "envoy/http/header_map.h" | ||
|
||
namespace Envoy { | ||
namespace Formatter { | ||
|
||
using AccessLogType = envoy::data::accesslog::v3::AccessLogType; | ||
|
||
/** | ||
* HTTP specific substitution formatter context for HTTP access logs or formatters. | ||
* TODO(wbpcode): maybe we should move this class to envoy/http folder and rename it | ||
* for more general usage. | ||
*/ | ||
class HttpFormatterContext { | ||
public: | ||
/** | ||
* Constructor that uses the provided request/response headers, response trailers, local reply | ||
* body, and access log type. Any of the parameters can be nullptr/empty. | ||
* | ||
* @param request_headers supplies the request headers. | ||
* @param response_headers supplies the response headers. | ||
* @param response_trailers supplies the response trailers. | ||
* @param local_reply_body supplies the local reply body. | ||
* @param log_type supplies the access log type. | ||
*/ | ||
HttpFormatterContext(const Http::RequestHeaderMap* request_headers = nullptr, | ||
const Http::ResponseHeaderMap* response_headers = nullptr, | ||
const Http::ResponseTrailerMap* response_trailers = nullptr, | ||
absl::string_view local_reply_body = {}, | ||
AccessLogType log_type = AccessLogType::NotSet); | ||
/** | ||
* Set or overwrite the request headers. | ||
* @param request_headers supplies the request headers. | ||
*/ | ||
HttpFormatterContext& setRequestHeaders(const Http::RequestHeaderMap& request_headers) { | ||
request_headers_ = &request_headers; | ||
return *this; | ||
} | ||
/** | ||
* Set or overwrite the response headers. | ||
* @param response_headers supplies the response headers. | ||
*/ | ||
HttpFormatterContext& setResponseHeaders(const Http::ResponseHeaderMap& response_headers) { | ||
response_headers_ = &response_headers; | ||
return *this; | ||
} | ||
|
||
/** | ||
* Set or overwrite the response trailers. | ||
* @param response_trailers supplies the response trailers. | ||
*/ | ||
HttpFormatterContext& setResponseTrailers(const Http::ResponseTrailerMap& response_trailers) { | ||
response_trailers_ = &response_trailers; | ||
return *this; | ||
} | ||
|
||
/** | ||
* Set or overwrite the local reply body. | ||
* @param local_reply_body supplies the local reply body. | ||
*/ | ||
HttpFormatterContext& setLocalReplyBody(absl::string_view local_reply_body) { | ||
local_reply_body_ = local_reply_body; | ||
return *this; | ||
} | ||
|
||
/** | ||
* Set or overwrite the access log type. | ||
* @param log_type supplies the access log type. | ||
*/ | ||
HttpFormatterContext& setAccessLogType(AccessLogType log_type) { | ||
log_type_ = log_type; | ||
return *this; | ||
} | ||
|
||
/** | ||
* @return const Http::RequestHeaderMap& the request headers. Empty request header map if no | ||
* request headers are available. | ||
*/ | ||
const Http::RequestHeaderMap& requestHeaders() const; | ||
|
||
/** | ||
* @return const Http::ResponseHeaderMap& the response headers. Empty respnose header map if | ||
* no response headers are available. | ||
*/ | ||
const Http::ResponseHeaderMap& responseHeaders() const; | ||
|
||
/** | ||
* @return const Http::ResponseTrailerMap& the response trailers. Empty response trailer map | ||
* if no response trailers are available. | ||
*/ | ||
const Http::ResponseTrailerMap& responseTrailers() const; | ||
|
||
/** | ||
* @return absl::string_view the local reply body. Empty if no local reply body. | ||
*/ | ||
absl::string_view localReplyBody() const; | ||
|
||
/** | ||
* @return AccessLog::AccessLogType the type of access log. NotSet if this is not used for | ||
* access logging. | ||
*/ | ||
AccessLogType accessLogType() const; | ||
|
||
private: | ||
const Http::RequestHeaderMap* request_headers_{}; | ||
const Http::ResponseHeaderMap* response_headers_{}; | ||
const Http::ResponseTrailerMap* response_trailers_{}; | ||
absl::string_view local_reply_body_{}; | ||
AccessLogType log_type_{AccessLogType::NotSet}; | ||
}; | ||
|
||
} // namespace Formatter | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.