特使访问日志字段主机

Envoy access logs fields host

我有一个关于 access log of envoy 的问题:

或者是否有其他字段包含 AUTHORITY 但不包含端口?

首先,"%REQ(:AUTHORITY)%"字段不包含任何关于端口的信息。看看这个official documentation:

Format strings are plain strings, specified using the format key. They may contain 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 default format for an example.

If custom format string is not specified, Envoy uses the following default format:

[%START_TIME%] "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%"
%RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION%
%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%"
"%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%UPSTREAM_HOST%"\n

Example of the default Envoy access log format:

[2016-04-15T20:17:00.310Z] "POST /api/v1/locations HTTP/2" 204 - 154 0 226 100 "10.0.35.28"
"nsq2http" "cc21d9b0-cf5c-432b-8c7e-98aeb7988cd2" "locations" "tcp://10.0.2.1:80"

字段 "%REQ(:AUTHORITY)%" 显示值 "locations",字段 "%UPSTREAM_HOST%" 显示 "tcp://10.0.2.1:80".

您可以根据格式键自定义日志格式。

Here you can find good article about understanding these logs. Field "%REQ(:AUTHORITY)%" is value of the Host (HTTP/1.1) or Authority (HTTP/2) header. Look at this picture 更好地理解。

我想你想编辑字段 "%UPSTREAM_HOST%" 从这个字段中删除端口是不可能的。您可以找到包含这些字段描述的文档 here:

%UPSTREAM_HOST%

Upstream host URL (e.g., tcp://ip:port for TCP connections).

我还没有发现 return 只是一个没有端口的 IP 地址的任何其他字段。


回答您的问题:

  • I use the field host: %REQ(:AUTHORITY)% , can I remove the port ?

不,因为这个字段 return 根本不是端口。

is there another fields which include the AUTHORITY and doesnt include the port?

您可以使用 %REQ(:AUTHORITY)% 字段而不使用 "%UPSTREAM_HOST%" 字段。您可以通过创建自定义日志格式来做到这一点。据我所知,在日志中不可能只有 IP 地址而没有端口。