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

provide -admin-access-log-path #5858

Merged
merged 4 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just make /dev/null be the default so specifying empty is also valid? This is kinda internal only but we do a bunch of default setting before the template already so this seems like a reasonable approach here too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it so that it can also be left empty and then the default would be picked up.

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
11 changes: 11 additions & 0 deletions command/connect/envoy/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type cmd struct {
// flags
proxyID string
sidecarFor string
adminAccessLogPath string
adminBind string
envoyBin string
bootstrap bool
Expand All @@ -67,6 +68,10 @@ 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", "/dev/null",
"The path to write the access log for the administration server. If no access "+
"log is desired specify \"/dev/null\".")

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 +263,19 @@ func (c *cmd) templateArgs() (*BootstrapTplArgs, error) {
cluster = c.sidecarFor
}

adminAccessLogPath := c.adminAccessLogPath
if len(adminAccessLogPath) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be a little clearer with if adminAccessLogPath == ""? Since it's a string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always wonder about the same thing and I read the first answer of https://stackoverflow.com/questions/18594330/what-is-the-best-way-to-test-for-an-empty-string-in-go. If you find == "" better, I would be happy to change it. I don't have an opinion on this one.

Copy link
Contributor

@freddygv freddygv May 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think == "" would be clearer and more consistent. I did a search through the Consul repo and found that len(x) == 0 didn't seem to ever be used with strings.

Thanks!

adminAccessLogPath = "/dev/null"
}

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"
}
}
}
}
}