Repository: kumahq/kuma
Pull request #2514 (2021-08-06 15:45:46)

Fix(traffic-log): remove extra endline in traffic log default template
We were adding a new line twice. Once in the default template and once in
`convertLoggingBackend` this was introducing empty lines in log files


lahabana: @jakubdyszkiewicz I've checked an it also introduces empty lines and the empty lines are removed with this patch

Patch:
diff --git a/pkg/xds/envoy/listeners/v3/http_access_log_configurer.go b/pkg/xds/envoy/listeners/v3/http_access_log_configurer.go
index d43b9e973..8009328d7 100644
--- a/pkg/xds/envoy/listeners/v3/http_access_log_configurer.go
+++ b/pkg/xds/envoy/listeners/v3/http_access_log_configurer.go
@@ -5,8 +5,7 @@ import (
 	envoy_hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
 )
 
-const defaultHttpAccessLogFormat = `[%START_TIME%] %KUMA_MESH% "%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)%" "%KUMA_SOURCE_SERVICE%" "%KUMA_DESTINATION_SERVICE%" "%KUMA_SOURCE_ADDRESS_WITHOUT_PORT%" "%UPSTREAM_HOST%"
-` // intentional newline at the end
+const defaultHttpAccessLogFormat = `[%START_TIME%] %KUMA_MESH% "%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)%" "%KUMA_SOURCE_SERVICE%" "%KUMA_DESTINATION_SERVICE%" "%KUMA_SOURCE_ADDRESS_WITHOUT_PORT%" "%UPSTREAM_HOST%"`
 
 type HttpAccessLogConfigurer struct {
 	AccessLogConfigurer
diff --git a/pkg/xds/envoy/listeners/v3/network_access_log_configurer.go b/pkg/xds/envoy/listeners/v3/network_access_log_configurer.go
index b1004619a..bfd6add9a 100644
--- a/pkg/xds/envoy/listeners/v3/network_access_log_configurer.go
+++ b/pkg/xds/envoy/listeners/v3/network_access_log_configurer.go
@@ -5,8 +5,7 @@ import (
 	envoy_tcp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3"
 )
 
-const defaultNetworkAccessLogFormat = `[%START_TIME%] %RESPONSE_FLAGS% %KUMA_MESH% %KUMA_SOURCE_ADDRESS_WITHOUT_PORT%(%KUMA_SOURCE_SERVICE%)->%UPSTREAM_HOST%(%KUMA_DESTINATION_SERVICE%) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes
-` // intentional newline at the end
+const defaultNetworkAccessLogFormat = `[%START_TIME%] %RESPONSE_FLAGS% %KUMA_MESH% %KUMA_SOURCE_ADDRESS_WITHOUT_PORT%(%KUMA_SOURCE_SERVICE%)->%UPSTREAM_HOST%(%KUMA_DESTINATION_SERVICE%) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes`
 
 type NetworkAccessLogConfigurer struct {
 	AccessLogConfigurer


Test patch:
diff --git a/pkg/xds/envoy/listeners/v3/http_access_log_configurer_test.go b/pkg/xds/envoy/listeners/v3/http_access_log_configurer_test.go
index 101f8c628..c1900558c 100644
--- a/pkg/xds/envoy/listeners/v3/http_access_log_configurer_test.go
+++ b/pkg/xds/envoy/listeners/v3/http_access_log_configurer_test.go
@@ -125,7 +125,6 @@ var _ = Describe("HttpAccessLogConfigurer", func() {
                         textFormatSource:
                           inlineString: |+
                             [%START_TIME%] demo "%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)%" "web" "backend" "192.168.0.1" "%UPSTREAM_HOST%"
-            
                       path: /tmp/log
                   httpFilters:
                   - name: envoy.filters.http.router
@@ -142,7 +141,6 @@ var _ = Describe("HttpAccessLogConfigurer", func() {
 			backend: &mesh_proto.LoggingBackend{
 				Name: "tcp",
 				Format: `[%START_TIME%] "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%REQ(ORIGIN)%" "%REQ(CONTENT-TYPE)%" "%KUMA_SOURCE_SERVICE%" "%KUMA_DESTINATION_SERVICE%" "%KUMA_SOURCE_ADDRESS%" "%KUMA_SOURCE_ADDRESS_WITHOUT_PORT%" "%UPSTREAM_HOST%"
-
 "%RESP(SERVER):5%" "%TRAILER(GRPC-MESSAGE):7%" "DYNAMIC_METADATA(namespace:object:key):9" "FILTER_STATE(filter.state.key):12"
 `, // intentional newline at the end
 				Type: mesh_proto.LoggingTcpType,
@@ -177,9 +175,8 @@ var _ = Describe("HttpAccessLogConfigurer", func() {
                             clusterName: access_log_sink
                         logName: |+
                           127.0.0.1:1234;[%START_TIME%] "%REQ(x-request-id)%" "%REQ(:authority)%" "%REQ(origin)%" "%REQ(content-type)%" "web" "backend" "192.168.0.1:0" "192.168.0.1" "%UPSTREAM_HOST%"
-            
                           "%RESP(server):5%" "%TRAILER(grpc-message):7%" "DYNAMIC_METADATA(namespace:object:key):9" "FILTER_STATE(filter.state.key):12"
-            
+
                         transportApiVersion: V3
                   httpFilters:
                   - name: envoy.filters.http.router
diff --git a/pkg/xds/envoy/listeners/v3/network_access_log_configurer_test.go b/pkg/xds/envoy/listeners/v3/network_access_log_configurer_test.go
index a1ed1437f..ae55e3ebb 100644
--- a/pkg/xds/envoy/listeners/v3/network_access_log_configurer_test.go
+++ b/pkg/xds/envoy/listeners/v3/network_access_log_configurer_test.go
@@ -130,7 +130,6 @@ var _ = Describe("NetworkAccessLogConfigurer", func() {
                         textFormatSource:
                           inlineString: |+
                             [%START_TIME%] %RESPONSE_FLAGS% demo 192.168.0.1(backend)->%UPSTREAM_HOST%(db) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes
-            
                       path: /tmp/log
                   cluster: db
                   statPrefix: db
@@ -149,7 +148,6 @@ var _ = Describe("NetworkAccessLogConfigurer", func() {
 			backend: &mesh_proto.LoggingBackend{
 				Name: "tcp",
 				Format: `[%START_TIME%] "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%REQ(ORIGIN)%" "%REQ(CONTENT-TYPE)%" "%KUMA_SOURCE_SERVICE%" "%KUMA_DESTINATION_SERVICE%" "%KUMA_SOURCE_ADDRESS%" "%KUMA_SOURCE_ADDRESS_WITHOUT_PORT%" "%UPSTREAM_HOST%
-
 "%RESP(SERVER):5%" "%TRAILER(GRPC-MESSAGE):7%" "DYNAMIC_METADATA(namespace:object:key):9" "FILTER_STATE(filter.state.key):12"
 `, // intentional newline at the end
 				Type: mesh_proto.LoggingTcpType,
@@ -184,9 +182,8 @@ var _ = Describe("NetworkAccessLogConfigurer", func() {
                             clusterName: access_log_sink
                         logName: |+
                           127.0.0.1:1234;[%START_TIME%] "%REQ(x-request-id)%" "%REQ(:authority)%" "%REQ(origin)%" "%REQ(content-type)%" "backend" "db" "192.168.0.1:0" "192.168.0.1" "%UPSTREAM_HOST%
-            
                           "%RESP(server):5%" "%TRAILER(grpc-message):7%" "DYNAMIC_METADATA(namespace:object:key):9" "FILTER_STATE(filter.state.key):12"
-            
+
                         transportApiVersion: V3
                   cluster: db
                   statPrefix: db
diff --git a/pkg/xds/generator/testdata/outbound-proxy/03.envoy.golden.yaml b/pkg/xds/generator/testdata/outbound-proxy/03.envoy.golden.yaml
index 570ecb274..b85889dde 100644
--- a/pkg/xds/generator/testdata/outbound-proxy/03.envoy.golden.yaml
+++ b/pkg/xds/generator/testdata/outbound-proxy/03.envoy.golden.yaml
@@ -320,9 +320,8 @@ resources:
               '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
               logFormat:
                 textFormatSource:
-                  inlineString: |+
+                  inlineString: |
                     [%START_TIME%] mesh1 "%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)%" "gateway" "api-http" "10.0.0.1" "%UPSTREAM_HOST%"
-
               path: /var/log
           httpFilters:
           - name: envoy.filters.http.router
@@ -366,9 +365,8 @@ resources:
                 grpcService:
                   envoyGrpc:
                     clusterName: access_log_sink
-                logName: |+
+                logName: |
                   logstash:1234;[%START_TIME%] %RESPONSE_FLAGS% mesh1 10.0.0.1(gateway)->%UPSTREAM_HOST%(api-tcp) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes
-
                 transportApiVersion: V3
           cluster: api-tcp
           statPrefix: api-tcp
diff --git a/pkg/xds/generator/testdata/outbound-proxy/04.envoy.golden.yaml b/pkg/xds/generator/testdata/outbound-proxy/04.envoy.golden.yaml
index 57ef721bf..1956c2fee 100644
--- a/pkg/xds/generator/testdata/outbound-proxy/04.envoy.golden.yaml
+++ b/pkg/xds/generator/testdata/outbound-proxy/04.envoy.golden.yaml
@@ -358,9 +358,8 @@ resources:
               '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
               logFormat:
                 textFormatSource:
-                  inlineString: |+
+                  inlineString: |
                     [%START_TIME%] mesh1 "%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)%" "web" "api-http" "10.0.0.1" "%UPSTREAM_HOST%"
-
               path: /var/log
           httpFilters:
           - name: envoy.filters.http.router
@@ -405,9 +404,8 @@ resources:
                 grpcService:
                   envoyGrpc:
                     clusterName: access_log_sink
-                logName: |+
+                logName: |
                   logstash:1234;[%START_TIME%] %RESPONSE_FLAGS% mesh1 10.0.0.1(web)->%UPSTREAM_HOST%(api-tcp) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes
-
                 transportApiVersion: V3
           cluster: api-tcp
           statPrefix: api-tcp
diff --git a/pkg/xds/generator/testdata/transparent-proxy/03.envoy.golden.yaml b/pkg/xds/generator/testdata/transparent-proxy/03.envoy.golden.yaml
index ef157ead0..f46b186d3 100644
--- a/pkg/xds/generator/testdata/transparent-proxy/03.envoy.golden.yaml
+++ b/pkg/xds/generator/testdata/transparent-proxy/03.envoy.golden.yaml
@@ -54,9 +54,8 @@ resources:
               '@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
               logFormat:
                 textFormatSource:
-                  inlineString: |+
+                  inlineString: |
                     [%START_TIME%] %RESPONSE_FLAGS% default (unknown)->%UPSTREAM_HOST%(external) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes
-
               path: /var/log
           cluster: outbound:passthrough:ipv4
           statPrefix: outbound_passthrough_ipv4