From 89e4e3d5344501077d1f9db80ea5ebf8b9b49f1f Mon Sep 17 00:00:00 2001 From: "R.B. Boyer" <4903+rboyer@users.noreply.github.com> Date: Wed, 7 Apr 2021 15:00:33 -0500 Subject: [PATCH] [1.8.x] command: when generating envoy bootstrap configs to stdout do not mix informational logs into the json (#9985) Backport of #9980 to `1.8.x` Conflicts: - just the generated golden command/ files - envoy.go and envoy_test.go --- .changelog/9980.txt | 3 +++ command/connect/envoy/envoy.go | 16 ++++++---------- command/connect/envoy/envoy_test.go | 12 +++++------- ...TTP_ADDR-with-https-scheme-enables-tls.golden | 1 + .../envoy/testdata/access-log-path.golden | 1 + .../envoy/testdata/custom-bootstrap.golden | 2 +- command/connect/envoy/testdata/defaults.golden | 1 + .../envoy/testdata/existing-ca-file.golden | 1 + .../envoy/testdata/existing-ca-path.golden | 1 + .../envoy/testdata/extra_-multiple.golden | 1 + .../connect/envoy/testdata/extra_-single.golden | 1 + .../envoy/testdata/grpc-addr-config.golden | 1 + .../connect/envoy/testdata/grpc-addr-env.golden | 1 + .../connect/envoy/testdata/grpc-addr-flag.golden | 1 + .../connect/envoy/testdata/grpc-addr-unix.golden | 1 + .../ingress-gateway-address-specified.golden | 1 + .../ingress-gateway-no-auto-register.golden | 1 + ...way-register-with-service-and-proxy-id.golden | 1 + ...register-with-service-without-proxy-id.golden | 1 + .../envoy/testdata/ingress-gateway.golden | 1 + .../envoy/testdata/stats-config-override.golden | 1 + command/connect/envoy/testdata/token-arg.golden | 1 + command/connect/envoy/testdata/token-env.golden | 1 + .../connect/envoy/testdata/token-file-arg.golden | 1 + .../connect/envoy/testdata/token-file-env.golden | 1 + .../envoy/testdata/zipkin-tracing-config.golden | 1 + 26 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 .changelog/9980.txt diff --git a/.changelog/9980.txt b/.changelog/9980.txt new file mode 100644 index 0000000000..9a5d7b3e58 --- /dev/null +++ b/.changelog/9980.txt @@ -0,0 +1,3 @@ +```release-note:bug +command: when generating envoy bootstrap configs to stdout do not mix informational logs into the json +``` diff --git a/command/connect/envoy/envoy.go b/command/connect/envoy/envoy.go index 67530f0ec6..c6c1dcff6a 100644 --- a/command/connect/envoy/envoy.go +++ b/command/connect/envoy/envoy.go @@ -23,13 +23,6 @@ import ( ) func New(ui cli.Ui) *cmd { - ui = &cli.PrefixedUi{ - OutputPrefix: "==> ", - InfoPrefix: " ", - ErrorPrefix: "==> ", - Ui: ui, - } - c := &cmd{UI: ui} c.init() return c @@ -352,7 +345,11 @@ func (c *cmd) run(args []string) int { return 1 } - c.UI.Output(fmt.Sprintf("Registered service: %s", svc.Name)) + if !c.bootstrap { + // We need stdout to be reserved exclusively for the JSON blob, so + // we omit logging this to Info which also writes to stdout. + c.UI.Info(fmt.Sprintf("Registered service: %s", svc.Name)) + } } // Generate config @@ -364,7 +361,7 @@ func (c *cmd) run(args []string) int { if c.bootstrap { // Just output it and we are done - os.Stdout.Write(bootstrapJson) + c.UI.Output(string(bootstrapJson)) return 0 } @@ -523,7 +520,6 @@ func (c *cmd) grpcAddress(httpCfg *api.Config) (GRPC, error) { // This is the dev mode default and recommended production setting if // enabled. port = 8502 - c.UI.Info(fmt.Sprintf("Defaulting to grpc port = %d", port)) } addr = fmt.Sprintf("localhost:%v", port) } diff --git a/command/connect/envoy/envoy_test.go b/command/connect/envoy/envoy_test.go index eb35af6451..5ad85d8d51 100644 --- a/command/connect/envoy/envoy_test.go +++ b/command/connect/envoy/envoy_test.go @@ -3,7 +3,6 @@ package envoy import ( "encoding/json" "flag" - "github.com/stretchr/testify/assert" "io/ioutil" "net" "net/http" @@ -13,12 +12,14 @@ import ( "strings" "testing" + "github.com/mitchellh/cli" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/agent/xds" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/sdk/testutil" - "github.com/mitchellh/cli" - "github.com/stretchr/testify/require" ) var update = flag.Bool("update", false, "update golden files") @@ -770,10 +771,7 @@ func TestGenerateConfig(t *testing.T) { require.NoError(err) // Error cases should have returned above require.Equal(&tc.WantArgs, got) - // Actual template output goes to stdout direct to avoid prefix in UI, so - // generate it again here to assert on. - actual, err := c.generateConfig() - require.NoError(err) + actual := ui.OutputWriter.Bytes() // If we got the arg handling write, verify output golden := filepath.Join("testdata", tc.Name+".golden") diff --git a/command/connect/envoy/testdata/CONSUL_HTTP_ADDR-with-https-scheme-enables-tls.golden b/command/connect/envoy/testdata/CONSUL_HTTP_ADDR-with-https-scheme-enables-tls.golden index 900bca148d..4c41536a73 100644 --- a/command/connect/envoy/testdata/CONSUL_HTTP_ADDR-with-https-scheme-enables-tls.golden +++ b/command/connect/envoy/testdata/CONSUL_HTTP_ADDR-with-https-scheme-enables-tls.golden @@ -123,3 +123,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/access-log-path.golden b/command/connect/envoy/testdata/access-log-path.golden index 2692027ec4..342f95e6b0 100644 --- a/command/connect/envoy/testdata/access-log-path.golden +++ b/command/connect/envoy/testdata/access-log-path.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/custom-bootstrap.golden b/command/connect/envoy/testdata/custom-bootstrap.golden index 98746ead1e..fa7e553988 100644 --- a/command/connect/envoy/testdata/custom-bootstrap.golden +++ b/command/connect/envoy/testdata/custom-bootstrap.golden @@ -13,4 +13,4 @@ "id": "test-proxy" }, "custom_field": "foo" -} \ No newline at end of file +} diff --git a/command/connect/envoy/testdata/defaults.golden b/command/connect/envoy/testdata/defaults.golden index cf1597123b..308c9517b1 100644 --- a/command/connect/envoy/testdata/defaults.golden +++ b/command/connect/envoy/testdata/defaults.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/existing-ca-file.golden b/command/connect/envoy/testdata/existing-ca-file.golden index 871fdd7d27..d0d5255295 100644 --- a/command/connect/envoy/testdata/existing-ca-file.golden +++ b/command/connect/envoy/testdata/existing-ca-file.golden @@ -123,3 +123,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/existing-ca-path.golden b/command/connect/envoy/testdata/existing-ca-path.golden index 2c85c99805..29810fbaac 100644 --- a/command/connect/envoy/testdata/existing-ca-path.golden +++ b/command/connect/envoy/testdata/existing-ca-path.golden @@ -123,3 +123,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/extra_-multiple.golden b/command/connect/envoy/testdata/extra_-multiple.golden index f9efb9e0cf..3c654e90ec 100644 --- a/command/connect/envoy/testdata/extra_-multiple.golden +++ b/command/connect/envoy/testdata/extra_-multiple.golden @@ -136,3 +136,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/extra_-single.golden b/command/connect/envoy/testdata/extra_-single.golden index 1f979ab1f7..be7f639fb8 100644 --- a/command/connect/envoy/testdata/extra_-single.golden +++ b/command/connect/envoy/testdata/extra_-single.golden @@ -127,3 +127,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/grpc-addr-config.golden b/command/connect/envoy/testdata/grpc-addr-config.golden index 285e89f360..a452eae769 100644 --- a/command/connect/envoy/testdata/grpc-addr-config.golden +++ b/command/connect/envoy/testdata/grpc-addr-config.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/grpc-addr-env.golden b/command/connect/envoy/testdata/grpc-addr-env.golden index 285e89f360..a452eae769 100644 --- a/command/connect/envoy/testdata/grpc-addr-env.golden +++ b/command/connect/envoy/testdata/grpc-addr-env.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/grpc-addr-flag.golden b/command/connect/envoy/testdata/grpc-addr-flag.golden index 285e89f360..a452eae769 100644 --- a/command/connect/envoy/testdata/grpc-addr-flag.golden +++ b/command/connect/envoy/testdata/grpc-addr-flag.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/grpc-addr-unix.golden b/command/connect/envoy/testdata/grpc-addr-unix.golden index 794fc4726f..ec7863a653 100644 --- a/command/connect/envoy/testdata/grpc-addr-unix.golden +++ b/command/connect/envoy/testdata/grpc-addr-unix.golden @@ -113,3 +113,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/ingress-gateway-address-specified.golden b/command/connect/envoy/testdata/ingress-gateway-address-specified.golden index 7e2d943052..5491310f04 100644 --- a/command/connect/envoy/testdata/ingress-gateway-address-specified.golden +++ b/command/connect/envoy/testdata/ingress-gateway-address-specified.golden @@ -187,3 +187,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/ingress-gateway-no-auto-register.golden b/command/connect/envoy/testdata/ingress-gateway-no-auto-register.golden index 13380aeb99..baa6c5c2dc 100644 --- a/command/connect/envoy/testdata/ingress-gateway-no-auto-register.golden +++ b/command/connect/envoy/testdata/ingress-gateway-no-auto-register.golden @@ -187,3 +187,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/ingress-gateway-register-with-service-and-proxy-id.golden b/command/connect/envoy/testdata/ingress-gateway-register-with-service-and-proxy-id.golden index a802ae135f..464a66c384 100644 --- a/command/connect/envoy/testdata/ingress-gateway-register-with-service-and-proxy-id.golden +++ b/command/connect/envoy/testdata/ingress-gateway-register-with-service-and-proxy-id.golden @@ -187,3 +187,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/ingress-gateway-register-with-service-without-proxy-id.golden b/command/connect/envoy/testdata/ingress-gateway-register-with-service-without-proxy-id.golden index c08947d257..1ceb07f3a6 100644 --- a/command/connect/envoy/testdata/ingress-gateway-register-with-service-without-proxy-id.golden +++ b/command/connect/envoy/testdata/ingress-gateway-register-with-service-without-proxy-id.golden @@ -187,3 +187,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/ingress-gateway.golden b/command/connect/envoy/testdata/ingress-gateway.golden index a3eccec1d1..772e425060 100644 --- a/command/connect/envoy/testdata/ingress-gateway.golden +++ b/command/connect/envoy/testdata/ingress-gateway.golden @@ -187,3 +187,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/stats-config-override.golden b/command/connect/envoy/testdata/stats-config-override.golden index 990a45b9f1..500ecbb90d 100644 --- a/command/connect/envoy/testdata/stats-config-override.golden +++ b/command/connect/envoy/testdata/stats-config-override.golden @@ -72,3 +72,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/token-arg.golden b/command/connect/envoy/testdata/token-arg.golden index 5122051175..df44fc6200 100644 --- a/command/connect/envoy/testdata/token-arg.golden +++ b/command/connect/envoy/testdata/token-arg.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/token-env.golden b/command/connect/envoy/testdata/token-env.golden index 5122051175..df44fc6200 100644 --- a/command/connect/envoy/testdata/token-env.golden +++ b/command/connect/envoy/testdata/token-env.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/token-file-arg.golden b/command/connect/envoy/testdata/token-file-arg.golden index 5122051175..df44fc6200 100644 --- a/command/connect/envoy/testdata/token-file-arg.golden +++ b/command/connect/envoy/testdata/token-file-arg.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/token-file-env.golden b/command/connect/envoy/testdata/token-file-env.golden index 5122051175..df44fc6200 100644 --- a/command/connect/envoy/testdata/token-file-env.golden +++ b/command/connect/envoy/testdata/token-file-env.golden @@ -114,3 +114,4 @@ ] } } + diff --git a/command/connect/envoy/testdata/zipkin-tracing-config.golden b/command/connect/envoy/testdata/zipkin-tracing-config.golden index b1f1a18ce5..ff84fb8209 100644 --- a/command/connect/envoy/testdata/zipkin-tracing-config.golden +++ b/command/connect/envoy/testdata/zipkin-tracing-config.golden @@ -147,3 +147,4 @@ ] } } +