Skip to content

Commit

Permalink
translator: add accesslog (#704)
Browse files Browse the repository at this point in the history
* translator: add accesslog

Signed-off-by: hejianpeng <hejianpeng2@huawei.com>
  • Loading branch information
zirain authored Nov 9, 2022
1 parent 6f800aa commit 0446430
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 8 deletions.
24 changes: 24 additions & 0 deletions internal/xds/translator/accesslog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package translator

import (
accesslog "github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3"
fileaccesslog "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/file/v3"
)

var (
stdoutFileAccessLog = &fileaccesslog.FileAccessLog{
Path: "/dev/stdout",
}

// for the case when a route does not exist to upstream, hcm logs will not be present
listenerAccessLogFilter = &accesslog.AccessLogFilter{
FilterSpecifier: &accesslog.AccessLogFilter_ResponseFlagFilter{
ResponseFlagFilter: &accesslog.ResponseFlagFilter{Flags: []string{"NR"}},
},
}
)
32 changes: 32 additions & 0 deletions internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package translator
import (
"errors"

accesslog "github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3"
core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
router "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3"
Expand All @@ -22,8 +23,16 @@ import (
)

func buildXdsListener(name, address string, port uint32) *listener.Listener {
accesslogAny, _ := anypb.New(stdoutFileAccessLog)
return &listener.Listener{
Name: name,
AccessLog: []*accesslog.AccessLog{
{
Name: wellknown.FileAccessLog,
ConfigType: &accesslog.AccessLog_TypedConfig{TypedConfig: accesslogAny},
Filter: listenerAccessLogFilter,
},
},
Address: &core.Address{
Address: &core.Address_SocketAddress{
SocketAddress: &core.SocketAddress{
Expand All @@ -44,6 +53,11 @@ func addXdsHTTPFilterChain(xdsListener *listener.Listener, irListener *ir.HTTPLi
return err
}

accesslogAny, err := anypb.New(stdoutFileAccessLog)
if err != nil {
return err
}

// HTTP filter configuration
var statPrefix string
if irListener.TLS != nil {
Expand All @@ -52,6 +66,12 @@ func addXdsHTTPFilterChain(xdsListener *listener.Listener, irListener *ir.HTTPLi
statPrefix = "http"
}
mgr := &hcm.HttpConnectionManager{
AccessLog: []*accesslog.AccessLog{
{
Name: wellknown.FileAccessLog,
ConfigType: &accesslog.AccessLog_TypedConfig{TypedConfig: accesslogAny},
},
},
CodecType: hcm.HttpConnectionManager_AUTO,
StatPrefix: statPrefix,
RouteSpecifier: &hcm.HttpConnectionManager_Rds{
Expand Down Expand Up @@ -153,7 +173,19 @@ func addXdsTCPFilterChain(xdsListener *listener.Listener, irListener *ir.TCPList
if irListener.TLS != nil {
statPrefix = "passthrough"
}

accesslogAny, err := anypb.New(stdoutFileAccessLog)
if err != nil {
return err
}

mgr := &tcp.TcpProxy{
AccessLog: []*accesslog.AccessLog{
{
Name: wellknown.FileAccessLog,
ConfigType: &accesslog.AccessLog_TypedConfig{TypedConfig: accesslogAny},
},
},
StatPrefix: statPrefix,
ClusterSpecifier: &tcp.TcpProxy_Cluster{
Cluster: clusterName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
- address:
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
Expand All @@ -7,6 +16,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
- address:
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
Expand All @@ -7,6 +16,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
- address:
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
Expand All @@ -7,6 +16,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
- address:
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
Expand All @@ -7,6 +16,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
- address:
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
Expand All @@ -7,6 +16,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
- address:
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
Expand All @@ -7,6 +16,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand All @@ -31,6 +45,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand Down Expand Up @@ -70,6 +89,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand Down Expand Up @@ -109,6 +133,11 @@
- name: envoy.filters.network.tcp_proxy
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
cluster: fifth-listener
statPrefix: passthrough
- filterChainMatch:
Expand All @@ -118,6 +147,11 @@
- name: envoy.filters.network.tcp_proxy
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
cluster: sixth-listener
statPrefix: passthrough
listenerFilters:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
- address:
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
Expand All @@ -7,6 +16,11 @@
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
- address:
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
Expand All @@ -10,6 +19,11 @@
- name: envoy.filters.network.tcp_proxy
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
cluster: tls-passthrough
statPrefix: passthrough
listenerFilters:
Expand Down

0 comments on commit 0446430

Please sign in to comment.