1

I have one question regarding the access log of envoy:

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

Or is there another fields which include the AUTHORITY and doesn't include the port?

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
JME
  • 881
  • 2
  • 11
  • 23

1 Answers1

1

First, the "%REQ(:AUTHORITY)%" field does not contain any information about the port. Look at this 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"

Field "%REQ(:AUTHORITY)%" shows value "locations" and field "%UPSTREAM_HOST%" shows "tcp://10.0.2.1:80".

You can customise your log format based on format keys.

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 to better understand.

I suppose you want to edit the field "%UPSTREAM_HOST%" It is impossible to remove the port from this field. You can find documentation with description of these fields here:

%UPSTREAM_HOST%

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

I haven't found any other field that returns just an IP address without a port.


Answering your question:

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

No, because this field does not return a port at all.

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

You can use %REQ(:AUTHORITY)% field without "%UPSTREAM_HOST%" field. You can do this by creating your custom log format. As far as I know it is impossible to have only IP adress without port in the logs.

Mikołaj Głodziak
  • 4,775
  • 7
  • 28
  • Thanks 1+ , I didnt see anything written about the authority field in the link that you have provided, can you send the specific section ? – JME Oct 25 '21 at 10:39
  • [This page](https://blog.getambassador.io/understanding-envoy-proxy-and-ambassador-http-access-logs-fee7802a2ec5) doesn't have sections. You need to find `Authority` word by yourself. It is `Host (or Authority)` in this document. – Mikołaj Głodziak Oct 25 '21 at 10:42
  • Thanks, I didnt find anything related to the port...my concern is this https://stackoverflow.com/a/20950626/11154975 WDYT? – JME Oct 25 '21 at 10:46
  • maybe im wrong here but the second option show the port if the port is provided ... – JME Oct 25 '21 at 10:46
  • Personally, I don't see a connection between the questions. I refer to the official envoyproxy documentation, which explains how specific fields work and what they contain.Perhaps you can somehow set these values differently, but the question was about displaying information in the logs.And at this point it cannot be changed, as I wrote in the answer. ;) – Mikołaj Głodziak Oct 25 '21 at 10:52
  • Sorry I dont understand how its not related :) , my question is quite simple does the field `%REQ(:AUTHORITY)%` contain port, you said not which is good, but the links show example about AUTHORITY values which can have port, does the link I've provided is talk about different AUTHORITY? , sorry as Im a bit confused ... – JME Oct 25 '21 at 10:58
  • Unfortunately I am not a C# expert and I am not able to tell if these fields mean the same thing. I cited envoyproxy's documentation, because that was what the question was about. In any case, even if the `AUTHORITY` field contains a port, you are not able to delete the port at the display / log creation stage. I also did not find any other field that would show the address only, without the port. – Mikołaj Głodziak Oct 25 '21 at 11:08
  • thanks, I found the following, https://www.rfc-editor.org/rfc/rfc3986#section-3.2 , the port can be added to the authority – JME Oct 25 '21 at 11:21
  • 1
    Now it's all clear. Okay, the port can be added, but in the logs you will display the value that was given earlier. If there was a port, there will be a port in the logs. If not - it won't. It is not possible to cut a port from the logs if it was given. – Mikołaj Głodziak Oct 26 '21 at 10:46