envoyproxy/envoy

DOWNSTREAM_REMOTE_ADDRESS* and DOWNSTREAM_DIRECT_REMOTE_ADDRESS* support in upstream_log

Open

#10,595 opened on 2020年3月31日

GitHub で見る
 (5 comments) (0 reactions) (0 assignees)C++ (5,373 forks)batch import
area/access_logbughelp wanted

Repository metrics

Stars
 (27,997 stars)
PR merge metrics
 (平均マージ 8d) (30d で 378 merged PRs)

説明

Description: Using DOWNSTREAM_REMOTE_ADDRESS* and DOWNSTREAM_DIRECT_REMOTE_ADDRESS* fields in router's upstream_log does not work properly, but it is stated in docs that you can use there everything that access_log supports.

Envoy 1.12.x just segfaults on such attempts Envoy 1.13.x returns "-" instead of actual addresses

The reason for this is probably due to missing setDownstream*Address calls in upstream_request.cc for stream_info_.

Config:

admin:
  access_log_path: /tmp/admin.log
  address:
    socket_address: { address: 0.0.0.0, port_value: 9901 }

static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address: { address: 0.0.0.0, port_value: 8080 }
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                route:
                  cluster: my_service
          http_filters:
          - name: envoy.router
            config:
              upstream_log:
                name: envoy.file_access_log
                config:
                  path: /tmp/upstream.log
                  json_format:
                    downstream_addr: "%DOWNSTREAM_DIRECT_REMOTE_ADDRESS%"
  - name: listener_1
    address:
      socket_address: { address: 0.0.0.0, port_value: 8081 }
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                direct_response:
                  status: 200
                  body:
                    inline_string: "OK.\n"
          http_filters:
          - name: envoy.router
  clusters:
  - name: my_service
    connect_timeout: 1.25s
    type: static
    hosts:
    - socket_address:
        address: 127.0.0.1
        port_value: 8081

Repro steps: Run curl 127.0.0.1:8080 and watch /tmp/upstream.log for 1.13.x or stdout for 1.12.x.

Logs: Upstream log for 1.13.x:

{"downstream_addr":"-"}

Stacktrace for 1.12.x:

Caught Segmentation fault, suspect faulting address 0x0
Backtrace (use tools/stack_decode.py to get line numbers):
Envoy version: e5a97a116046e5c57cf01adf07f3acba65324f55/1.12.2/Clean/RELEASE/BoringSSL
#0: __restore_rt [0x7f3426f7a890]
#1: std::_Function_handler<>::_M_invoke() [0x55ffd845cdd0]
#2: _ZNK5Envoy9AccessLog19StreamInfoFormatter6formatB5cxx11ERKNS_4Http9HeaderMapES5_S5_RKNS_10StreamInfo10StreamInfoE [0x55ffd845c970]
#3: _ZNK5Envoy9AccessLog13FormatterImpl6formatB5cxx11ERKNS_4Http9HeaderMapES5_S5_RKNS_10StreamInfo10StreamInfoE [0x55ffd845c8c3]
#4: _ZNK5Envoy9AccessLog17JsonFormatterImpl5toMapB5cxx11ERKNS_4Http9HeaderMapES5_S5_RKNS_10StreamInfo10StreamInfoE [0x55ffd845e8e5]
#5: _ZNK5Envoy9AccessLog17JsonFormatterImpl6formatB5cxx11ERKNS_4Http9HeaderMapES5_S5_RKNS_10StreamInfo10StreamInfoE [0x55ffd8463cc0]
#6: Envoy::Extensions::AccessLoggers::File::FileAccessLog::emitLog() [0x55ffd83e6488]
#7: Envoy::Router::Filter::UpstreamRequest::~UpstreamRequest() [0x55ffd835281f]
#8: Envoy::Router::Filter::UpstreamRequest::~UpstreamRequest() [0x55ffd83529d1]
#9: Envoy::Router::Filter::onUpstreamReset() [0x55ffd834f9ca]
#10: Envoy::Router::Filter::UpstreamRequest::onResetStream() [0x55ffd834ff0c]
#11: Envoy::Http::Http2::ConnectionImpl::StreamImpl::resetStream() [0x55ffd83b16bd]
#12: Envoy::Http::CodecClient::onEvent() [0x55ffd832e047]
#13: Envoy::Network::ConnectionImpl::raiseEvent() [0x55ffd8186495]
#14: Envoy::Network::ConnectionImpl::closeSocket() [0x55ffd8185999]
#15: Envoy::Network::ConnectionImpl::onReadReady() [0x55ffd8185df2]
#16: Envoy::Network::ConnectionImpl::onFileEvent() [0x55ffd81865ca]
#17: Envoy::Event::FileEventImpl::assignEvents()::{lambda()#1}::_FUN() [0x55ffd817fc9a]
#18: event_process_active_single_queue.isra.33 [0x55ffd849eb30]
#19: event_base_loop [0x55ffd849f1af]
#20: Envoy::Server::WorkerImpl::threadRoutine() [0x55ffd81781ca]
#21: Envoy::Thread::ThreadImplPosix::ThreadImplPosix()::{lambda()#1}::_FUN() [0x55ffd86183a5]
#22: start_thread [0x7f3426f6f6db]

コントリビューターガイド