Skip to content
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

Problem fixing logging policy tests #841

Closed
xbauquet opened this issue Jun 19, 2020 · 1 comment
Closed

Problem fixing logging policy tests #841

xbauquet opened this issue Jun 19, 2020 · 1 comment

Comments

@xbauquet
Copy link
Contributor

This issue is linked to the PR #820.

Steps To Reproduce

Pull the PR code and run make test

The problem

I have tests with expected values. But in the result of the test the expected value is different than the on provided to the test.

Test file: pkg/xds/envoy/listeners/http_access_log_configurer_test.go

The new lines added in the format are not present in the result of the test.

Code and Result of one test

The test code:

Entry("basic http_connection_manager with file access log", testCase{
			listenerName:    "outbound:127.0.0.1:27070",
			listenerAddress: "127.0.0.1",
			listenerPort:    27070,
			statsName:       "backend",
			routeName:       "outbound:backend",
			backend: &mesh_proto.LoggingBackend{
				Name: "file",
				Type: mesh_proto.LoggingFileType,
				Conf: util_proto.MustToStruct(&mesh_proto.FileLoggingBackendConfig{
					Path: "/tmp/log",
				}),
			},
			expected: `
            name: outbound:127.0.0.1:27070
            address:
              socketAddress:
                address: 127.0.0.1
                portValue: 27070
            filterChains:
            - filters:
              - name: envoy.http_connection_manager
                typedConfig:
                  '@type': type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
                  accessLog:
                  - name: envoy.file_access_log
                    typedConfig:
                      '@type': type.googleapis.com/envoy.config.accesslog.v2.FileAccessLog
                      format: |
                        [%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.router
                  rds:
                    configSource:
                      ads: {}
                    routeConfigName: outbound:backend
                  statPrefix: backend
            trafficDirection: OUTBOUND
`,
		})

Test result:

HttpAccessLogConfigurer
�[90m/Users/xavierbauquet/Github/kuma/pkg/xds/envoy/listeners/http_access_log_configurer_test.go:17�[0m
  should generate proper Envoy config
  �[90m/Users/xavierbauquet/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/extensions/table/table.go:92�[0m
    �[91m�[1mbasic http_connection_manager with file access log [It]�[0m
    �[90m/Users/xavierbauquet/go/pkg/mod/github.com/onsi/ginkgo@v1.12.0/extensions/table/table_entry.go:43�[0m

    �[91mExpected
        <string>: address:
          socketAddress:
            address: 127.0.0.1
            portValue: 27070
        filterChains:
        - filters:
          - name: envoy.http_connection_manager
            typedConfig:
              '@type': type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
              accessLog:
              - name: envoy.file_access_log
                typedConfig:
                  '@type': type.googleapis.com/envoy.config.accesslog.v2.FileAccessLog
                  format: |+
                    [%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.router
              rds:
                configSource:
                  ads: {}
                routeConfigName: outbound:backend
              statPrefix: backend
        name: outbound:127.0.0.1:27070
        trafficDirection: OUTBOUND
    to match YAML of
        <string>: address:
          socketAddress:
            address: 127.0.0.1
            portValue: 27070
        filterChains:
        - filters:
          - name: envoy.http_connection_manager
            typedConfig:
              '@type': type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
              accessLog:
              - name: envoy.file_access_log
                typedConfig:
                  '@type': type.googleapis.com/envoy.config.accesslog.v2.FileAccessLog
                  format: |
                    [%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.router
              rds:
                configSource:
                  ads: {}
                routeConfigName: outbound:backend
              statPrefix: backend
        name: outbound:127.0.0.1:27070
        trafficDirection: OUTBOUND
    
    first mismatched key: "filterChains"[0]."filters"[0]."typedConfig"."accessLog"[0]."typedConfig"."format"�[0m

    /Users/xavierbauquet/Github/kuma/pkg/xds/envoy/listeners/http_access_log_configurer_test.go:75
@xbauquet
Copy link
Contributor Author

It seems like I found a solution:

'@type': type.googleapis.com/envoy.config.accesslog.v2.FileAccessLog
format: |+
[%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

Adding the + seems to be keeping the empty line at the end of format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant