Skip to content

Commit

Permalink
connect: provide -admin-access-log-path for envoy (#5858)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshasselberg authored Jun 7, 2019
1 parent cef378b commit 4d9116d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
7 changes: 6 additions & 1 deletion command/connect/envoy/bootstrap_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ type BootstrapTplArgs struct {
// TLS is enabled.
AgentCAFile string

// AdminAccessLogPath The path to write the access log for the
// administration server. If no access log is desired specify
// "/dev/null". By default it will use "/dev/null".
AdminAccessLogPath string

// AdminBindAddress is the address the Envoy admin server should bind to.
AdminBindAddress string

Expand Down Expand Up @@ -86,7 +91,7 @@ type BootstrapTplArgs struct {

const bootstrapTemplate = `{
"admin": {
"access_log_path": "/dev/null",
"access_log_path": "{{ .AdminAccessLogPath }}",
"address": {
"socket_address": {
"address": "{{ .AdminBindAddress }}",
Expand Down
14 changes: 14 additions & 0 deletions command/connect/envoy/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func New(ui cli.Ui) *cmd {
return c
}

const DefaultAdminAccessLogPath = "/dev/null"

type cmd struct {
UI cli.Ui
flags *flag.FlagSet
Expand All @@ -44,6 +46,7 @@ type cmd struct {
// flags
proxyID string
sidecarFor string
adminAccessLogPath string
adminBind string
envoyBin string
bootstrap bool
Expand All @@ -67,6 +70,11 @@ func (c *cmd) init() {
"The full path to the envoy binary to run. By default will just search "+
"$PATH. Ignored if -bootstrap is used.")

c.flags.StringVar(&c.adminAccessLogPath, "admin-access-log-path", DefaultAdminAccessLogPath,
fmt.Sprintf("The path to write the access log for the administration server. If no access "+
"log is desired specify %q. By default it will use %q.",
DefaultAdminAccessLogPath, DefaultAdminAccessLogPath))

c.flags.StringVar(&c.adminBind, "admin-bind", "localhost:19000",
"The address:port to start envoy's admin server on. Envoy requires this "+
"but care must be taken to ensure it's not exposed to an untrusted network "+
Expand Down Expand Up @@ -258,13 +266,19 @@ func (c *cmd) templateArgs() (*BootstrapTplArgs, error) {
cluster = c.sidecarFor
}

adminAccessLogPath := c.adminAccessLogPath
if adminAccessLogPath == "" {
adminAccessLogPath = DefaultAdminAccessLogPath
}

return &BootstrapTplArgs{
ProxyCluster: cluster,
ProxyID: c.proxyID,
AgentAddress: agentIP.String(),
AgentPort: agentPort,
AgentTLS: useTLS,
AgentCAFile: httpCfg.TLSConfig.CAFile,
AdminAccessLogPath: adminAccessLogPath,
AdminBindAddress: adminBindIP.String(),
AdminBindPort: adminPort,
Token: httpCfg.Token,
Expand Down
30 changes: 30 additions & 0 deletions command/connect/envoy/envoy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502", // Note this is the gRPC port
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand All @@ -99,6 +100,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502", // Note this is the gRPC port
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand All @@ -116,6 +118,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502", // Note this is the gRPC port
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand All @@ -136,6 +139,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502", // Note this is the gRPC port
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand All @@ -156,6 +160,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502", // Note this is the gRPC port
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand All @@ -175,6 +180,7 @@ func TestGenerateConfig(t *testing.T) {
// to do.
AgentAddress: "127.0.0.1",
AgentPort: "9999",
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand All @@ -194,6 +200,25 @@ func TestGenerateConfig(t *testing.T) {
// to do.
AgentAddress: "127.0.0.1",
AgentPort: "9999",
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
},
},
{
Name: "access-log-path",
Flags: []string{"-proxy-id", "test-proxy", "-admin-access-log-path", "/some/path/access.log"},
Env: []string{},
WantArgs: BootstrapTplArgs{
ProxyCluster: "test-proxy",
ProxyID: "test-proxy",
// Should resolve IP, note this might not resolve the same way
// everywhere which might make this test brittle but not sure what else
// to do.
AgentAddress: "127.0.0.1",
AgentPort: "8502",
AdminAccessLogPath: "/some/path/access.log",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand Down Expand Up @@ -230,6 +255,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502",
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand Down Expand Up @@ -261,6 +287,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502",
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand Down Expand Up @@ -297,6 +324,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502",
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand All @@ -320,6 +348,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502",
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand Down Expand Up @@ -373,6 +402,7 @@ func TestGenerateConfig(t *testing.T) {
ProxyID: "test-proxy",
AgentAddress: "127.0.0.1",
AgentPort: "8502",
AdminAccessLogPath: "/dev/null",
AdminBindAddress: "127.0.0.1",
AdminBindPort: "19000",
LocalAgentClusterName: xds.LocalAgentClusterName,
Expand Down
60 changes: 60 additions & 0 deletions command/connect/envoy/testdata/access-log-path.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"admin": {
"access_log_path": "/some/path/access.log",
"address": {
"socket_address": {
"address": "127.0.0.1",
"port_value": 19000
}
}
},
"node": {
"cluster": "test-proxy",
"id": "test-proxy"
},
"static_resources": {
"clusters": [
{
"name": "local_agent",
"connect_timeout": "1s",
"type": "STATIC",
"http2_protocol_options": {},
"hosts": [
{
"socket_address": {
"address": "127.0.0.1",
"port_value": 8502
}
}
]
}
]
},
"stats_config": {
"stats_tags": [
{
"tag_name": "local_cluster",
"fixed_value": "test-proxy"
}
],
"use_all_default_tags": true
},
"dynamic_resources": {
"lds_config": { "ads": {} },
"cds_config": { "ads": {} },
"ads_config": {
"api_type": "GRPC",
"grpc_services": {
"initial_metadata": [
{
"key": "x-consul-token",
"value": ""
}
],
"envoy_grpc": {
"cluster_name": "local_agent"
}
}
}
}
}

0 comments on commit 4d9116d

Please sign in to comment.