-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add access logging to tcp_proxy #1953
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
Changes from 13 commits
b96200a
6061b5d
297a108
334f48c
71c3717
45967ae
a8b2b4c
4b09518
2cc065f
359666e
9c64eb5
9fc8128
a8e807e
63cf792
0a37b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| .. _config_http_conn_man_access_log: | ||
| .. _config_access_log: | ||
|
|
||
| Access logging | ||
| ============== | ||
|
|
@@ -7,7 +7,7 @@ Configuration | |
| ------------------------- | ||
|
|
||
| Access logs are configured as part of the :ref:`HTTP connection manager config | ||
| <config_http_conn_man>`. | ||
| <config_http_conn_man>` or :ref:`TCP Proxy <config_network_filters_tcp_proxy>`. | ||
|
|
||
| .. code-block:: json | ||
|
|
||
|
|
@@ -21,71 +21,102 @@ Access logs are configured as part of the :ref:`HTTP connection manager config | |
| ] | ||
| } | ||
|
|
||
| .. _config_http_conn_man_access_log_path_param: | ||
| .. _config_access_log_path_param: | ||
|
|
||
| path | ||
| *(required, string)* Path the access log is written to. | ||
|
|
||
| .. _config_http_conn_man_access_log_format_param: | ||
| .. _config_access_log_format_param: | ||
|
|
||
| format | ||
| *(optional, string)* Access log format. Envoy supports :ref:`custom access log formats | ||
| <config_http_con_manager_access_log_format>` as well as a :ref:`default format | ||
| <config_http_con_manager_access_log_default_format>`. | ||
| <config_access_log_format>` as well as a :ref:`default format | ||
| <config_access_log_default_format>`. | ||
|
|
||
| .. _config_http_conn_man_access_log_filter_param: | ||
| .. _config_access_log_filter_param: | ||
|
|
||
| filter | ||
| *(optional, object)* :ref:`Filter <config_http_con_manager_access_log_filters>` which is used to | ||
| determine if the access log needs to be written. | ||
|
|
||
| .. _config_http_con_manager_access_log_format: | ||
| .. _config_access_log_format: | ||
|
|
||
| Format rules | ||
| ------------ | ||
|
|
||
| The access log format string contains either command operators or other characters interpreted as a | ||
| plain string. The access log formatter does not make any assumptions about a new line separator, so one | ||
| has to specified as part of the format string. | ||
| See the :ref:`default format <config_http_con_manager_access_log_default_format>` for an example. | ||
| See the :ref:`default format <config_access_log_default_format>` for an example. | ||
| Note that the access log line will contain a '-' character for every not set/empty value. | ||
|
|
||
| The same format strings are used by different types of access logs (such as HTTP and TCP). Some | ||
| fields may have slightly different meanings, depending on what type of log it is. Differences | ||
| are noted. | ||
|
|
||
| The following command operators are supported: | ||
|
|
||
| %START_TIME% | ||
| Request start time including milliseconds. | ||
| HTTP | ||
| Request start time including milliseconds. | ||
|
|
||
| TCP | ||
| Downstream connection start time including milliseconds. | ||
|
|
||
| %BYTES_RECEIVED% | ||
| Body bytes received. | ||
| HTTP | ||
| Body bytes received. | ||
|
|
||
| TCP | ||
| Downstream bytes received on connection. | ||
|
|
||
| %PROTOCOL% | ||
| Protocol. Currently either *HTTP/1.1* or *HTTP/2*. | ||
| HTTP | ||
| Protocol. Currently either *HTTP/1.1* or *HTTP/2*. | ||
|
|
||
| TCP | ||
| Not implemented ("-"). | ||
|
|
||
| %RESPONSE_CODE% | ||
| HTTP response code. Note that a response code of '0' means that the server never sent the | ||
| beginning of a response. This generally means that the (downstream) client disconnected. | ||
| HTTP | ||
| HTTP response code. Note that a response code of '0' means that the server never sent the | ||
| beginning of a response. This generally means that the (downstream) client disconnected. | ||
|
|
||
| TCP | ||
| Not implemented ("-"). | ||
|
|
||
| %BYTES_SENT% | ||
| Body bytes sent. | ||
| HTTP | ||
| Body bytes sent. | ||
|
|
||
| TCP | ||
| Downstream bytes sent on connection. | ||
|
|
||
| %DURATION% | ||
| Total duration in milliseconds of the request from the start time to the last byte out. | ||
| HTTP | ||
| Total duration in milliseconds of the request from the start time to the last byte out. | ||
|
|
||
| TCP | ||
| Total duration of the downstream connection. | ||
|
|
||
| %RESPONSE_FLAGS% | ||
| Additional details about the response, if any. Possible values are: | ||
|
|
||
| * **LH**: Local service failed :ref:`health check request <arch_overview_health_checking>` in addition to 503 response code. | ||
| * **UH**: No healthy upstream hosts in upstream cluster in addition to 503 response code. | ||
| * **UT**: Upstream request timeout in addition to 504 response code. | ||
| * **LR**: Connection local reset in addition to 503 response code. | ||
| * **UR**: Upstream remote reset in addition to 503 response code. | ||
| * **UF**: Upstream connection failure in addition to 503 response code. | ||
| * **UC**: Upstream connection termination in addition to 503 response code. | ||
| * **UO**: Upstream overflow (:ref:`circuit breaking <arch_overview_circuit_break>`) in addition to 503 response code. | ||
| * **NR**: No :ref:`route configured <arch_overview_http_routing>` for a given request in addition to 404 response code. | ||
| * **DI**: The request processing was delayed for a period specified via :ref:`fault injection <config_http_filters_fault_injection>`. | ||
| * **FI**: The request was aborted with a response code specified via :ref:`fault injection <config_http_filters_fault_injection>`. | ||
| * **RL**: The request was ratelimited locally by the :ref:`HTTP rate limit filter <config_http_filters_rate_limit>` in addition to 429 response code. | ||
| Additional details about the response or connection, if any. For TCP connections, the specified response code | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "For TCP connections, the specified response code does not apply" is a bit confusing. I think you mean to say something like all codes don't apply, etc. |
||
| does not apply. Possible values are: | ||
|
|
||
| HTTP and TCP | ||
| * **UH**: No healthy upstream hosts in upstream cluster in addition to 503 response code. | ||
| * **UF**: Upstream connection failure in addition to 503 response code. | ||
| * **UO**: Upstream overflow (:ref:`circuit breaking <arch_overview_circuit_break>`) in addition to 503 response code. | ||
| * **NR**: No :ref:`route configured <arch_overview_http_routing>` for a given request in addition to 404 response code. | ||
| HTTP only | ||
| * **LH**: Local service failed :ref:`health check request <arch_overview_health_checking>` in addition to 503 response code. | ||
| * **UT**: Upstream request timeout in addition to 504 response code. | ||
| * **LR**: Connection local reset in addition to 503 response code. | ||
| * **UR**: Upstream remote reset in addition to 503 response code. | ||
| * **UC**: Upstream connection termination in addition to 503 response code. | ||
| * **DI**: The request processing was delayed for a period specified via :ref:`fault injection <config_http_filters_fault_injection>`. | ||
| * **FI**: The request was aborted with a response code specified via :ref:`fault injection <config_http_filters_fault_injection>`. | ||
| * **RL**: The request was ratelimited locally by the :ref:`HTTP rate limit filter <config_http_filters_rate_limit>` in addition to 429 response code. | ||
|
|
||
| %UPSTREAM_HOST% | ||
| Upstream host URL (e.g., tcp://ip:port for TCP connections). | ||
|
|
@@ -94,15 +125,24 @@ The following command operators are supported: | |
| Upstream cluster to which the upstream host belongs to. | ||
|
|
||
| %REQ(X?Y):Z% | ||
| An HTTP request header where X is the main HTTP header, Y is the alternative one, and Z is an | ||
| optional parameter denoting string truncation up to Z characters long. The value is taken from the | ||
| HTTP request header named X first and if it's not set, then request header Y is used. If none of | ||
| the headers are present '-' symbol will be in the log. | ||
| HTTP | ||
| An HTTP request header where X is the main HTTP header, Y is the alternative one, and Z is an | ||
| optional parameter denoting string truncation up to Z characters long. The value is taken from | ||
| the HTTP request header named X first and if it's not set, then request header Y is used. If | ||
| none of the headers are present '-' symbol will be in the log. | ||
|
|
||
| TCP | ||
| Not implemented ("-"). | ||
|
|
||
| %RESP(X?Y):Z% | ||
| Same as **%REQ(X?Y):Z%** but taken from HTTP response headers. | ||
| HTTP | ||
| Same as **%REQ(X?Y):Z%** but taken from HTTP response headers. | ||
|
|
||
| TCP | ||
| Not implemented ("-"). | ||
|
|
||
|
|
||
| .. _config_http_con_manager_access_log_default_format: | ||
| .. _config_access_log_default_format: | ||
|
|
||
| Default format | ||
| -------------- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| .. _arch_overview_access_logs: | ||
|
|
||
| Access logging | ||
| =================== | ||
|
|
||
| The HTTP connection manager and tcp proxy supports extensible access logging with the following | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: x-link to filters. |
||
| features: | ||
|
|
||
| * Any number of access logs per connection manager or tcp proxy. | ||
| * Asynchronous IO flushing architecture. Access logging will never block the main network processing | ||
| threads. | ||
| * Customizable access log formats using predefined fields as well as arbitrary HTTP request and | ||
| response headers. | ||
| * Customizable access log filters that allow different types of requests and responses to be written | ||
| to different access logs. | ||
|
|
||
| Access log :ref:`configuration <config_access_log>`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ Architecture overview | |
| runtime | ||
| tracing | ||
| tcp_proxy | ||
| access_logging | ||
| mongo | ||
| dynamo | ||
| redis | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,7 +88,7 @@ class RequestInfo { | |
| * @return duration from request start to when the entire request was received from the | ||
| * downstream client in microseconds. Note: if unset, will return 0 microseconds. | ||
| */ | ||
| virtual std::chrono::microseconds requestReceivedDuration() const PURE; | ||
| virtual Optional<std::chrono::microseconds> requestReceivedDuration() const PURE; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can use |
||
|
|
||
| /** | ||
| * Set the duration from request start to when the entire request was received from the | ||
|
|
@@ -101,7 +101,7 @@ class RequestInfo { | |
| * @return the duration from request start to when the entire response was received from the | ||
| * upstream host in microseconds. Note: if unset, will return 0 microseconds. | ||
| */ | ||
| virtual std::chrono::microseconds responseReceivedDuration() const PURE; | ||
| virtual Optional<std::chrono::microseconds> responseReceivedDuration() const PURE; | ||
|
|
||
| /** | ||
| * Set the duration from request start to when the entire response was received from the | ||
|
|
@@ -118,7 +118,7 @@ class RequestInfo { | |
| /** | ||
| * @return the protocol of the request. | ||
| */ | ||
| virtual Http::Protocol protocol() const PURE; | ||
| virtual Optional<Http::Protocol> protocol() const PURE; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ultimately I think we will need this to be an enum specific to access logs if we don't split this apart later. On this topic, should this potentially print "TCP" ? (We could have it print "UDP" for example once we support UDP proxy). NBD, just a thought.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think we'll want that eventually. I wanted to limit the scope of this PR where I could. |
||
|
|
||
| /** | ||
| * Set the request's protocol. | ||
|
|
||
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.
nit: unit? milliseconds?