From 186e2f059ec633c34eb414b3a9391a850cda2941 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Tue, 13 Oct 2020 13:09:29 +0100 Subject: [PATCH] Respect logging verbosity as part of pulumi plugin install (#5549) Fixes: #4427 By default, there is no indepth logging: ``` pulumi plugin install resource azure-nextgen v0.2.1 [resource plugin azure-nextgen-0.2.1] installing Downloading plugin: 17.82 MiB / 17.82 MiB [=========================] 100.00% 2s Moving plugin... done. ``` We can increase the logging verosity get more detailed logging: ``` pulumi plugin install resource azure-nextgen v0.2.1 -v=1 --logtostderr [resource plugin azure-nextgen-0.2.1] installing I1010 19:30:58.472772 7128 plugins.go:201] azure-nextgen downloading from https://get.pulumi.com/releases/plugins Downloading plugin: 0 B / 17.82 MiB [----------------------------------] 0.00%I1010 19:30:58.704168 7128 plugin_install.go:136] [resource plugin azure-nextgen-0.2.1] installing tarball ... Downloading plugin: 17.82 MiB / 17.82 MiB [=========================] 100.00% 3s Moving plugin...I1010 19:31:01.874427 7128 plugins.go:304] moving plugin from "/Users/myuser/.pulumi/plugins/resource-azure-nextgen-v0.2.1.tmp884796935" to "/Users/myuser/.pulumi/plugins/resource-azure-nextgen-v0.2.1" done. ``` The most verbose logging level will log the request and response headers ``` pulumi plugin install resource azure-nextgen v0.2.1 -v=9 --logtostderr I1010 19:29:46.989150 7089 sink.go:146] defaultSink::Infoerr([resource plugin azure-nextgen-0.2.1] installing) [resource plugin azure-nextgen-0.2.1] installing I1010 19:29:46.989295 7089 plugins.go:591] SelectCompatiblePlugin(..., azure-nextgen): beginning I1010 19:29:46.989300 7089 plugins.go:630] SelectCompatiblePlugin(..., azure-nextgen): failed to find match I1010 19:29:46.989323 7089 plugins.go:201] azure-nextgen downloading from https://get.pulumi.com/releases/plugins I1010 19:29:46.989333 7089 plugins.go:208] full plugin download url: https://get.pulumi.com/releases/plugins/pulumi-resource-azure-nextgen-v0.2.1-darwin-amd64.tar.gz I1010 19:29:46.989360 7089 plugins.go:218] plugin install request headers: map[User-Agent:[pulumi-cli/1 (; darwin)]] I1010 19:29:47.242941 7089 plugins.go:225] plugin install response headers: map[Accept-Ranges:[bytes] Age:[370098] Content-Disposition:[attachment; filename=pulumi-resource-azure-nextgen-v0.2.1-darwin-amd64.tar.gz] Content-Length:[18684382] Content-Type:[application/x-gzip] Date:[Tue, 06 Oct 2020 11:41:30 GMT] Etag:["518f2e7efd46fe5b7be9508dc785b9c9-4"] Last-Modified:[Sat, 03 Oct 2020 20:57:45 GMT] Server:[AmazonS3] Via:[1.1 198b7d1bb217783eef010e6636984c9f.cloudfront.net (CloudFront)] X-Amz-Cf-Id:[aaC3Q0WcecspsFbWROLxXnD6iF7sYoAfShQKYiS2xkFKAWlFRBu-1Q==] X-Amz-Cf-Pop:[MAN50-C2] X-Cache:[Hit from cloudfront]] Downloading plugin: 0 B / 17.82 MiB [----------------------------------] 0.00%I1010 19:29:47.243189 7089 plugin_install.go:136] [resource plugin azure-nextgen-0.2.1] installing tarball ... Downloading plugin: 17.82 MiB / 17.82 MiB [=========================] 100.00% 2s Moving plugin...I1010 19:29:50.031099 7089 plugins.go:304] moving plugin from "/Users/myuser/.pulumi/plugins/resource-azure-nextgen-v0.2.1.tmp960784076" to "/Users/myuser/.pulumi/plugins/resource-azure-nextgen-v0.2.1" done. ``` --- CHANGELOG.md | 3 +++ pkg/cmd/pulumi/plugin_install.go | 28 +++++----------------------- sdk/go/common/workspace/plugins.go | 9 +++++++++ 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e7f3b25e..38616e60d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,9 @@ CHANGELOG - [cli] Ensure old secret provider variables are cleaned up when changing between secret providers [#5545](https://github.com/pulumi/pulumi/pull/5545) + +- [cli] Respect logging verbosity as part of pulumi plugin install commands + [#5549](https://github.com/pulumi/pulumi/pull/5549) - [cli] Accept `-f` as a shorthand for `--skip-preview` on `pulumi up`, `pulumi refresh` and `pulumi destroy` operations [#5556](https://github.com/pulumi/pulumi/pull/5556) diff --git a/pkg/cmd/pulumi/plugin_install.go b/pkg/cmd/pulumi/plugin_install.go index 5d65ffd37..7950d0a1c 100644 --- a/pkg/cmd/pulumi/plugin_install.go +++ b/pkg/cmd/pulumi/plugin_install.go @@ -16,6 +16,7 @@ package main import ( "fmt" + "github.com/pulumi/pulumi/sdk/v2/go/common/util/logging" "io" "os" @@ -34,7 +35,6 @@ func newPluginInstallCmd() *cobra.Command { var exact bool var file string var reinstall bool - var verbose bool var cmd = &cobra.Command{ Use: "install [KIND NAME VERSION]", @@ -104,18 +104,12 @@ func newPluginInstallCmd() *cobra.Command { if !reinstall { if exact { if workspace.HasPlugin(install) { - if verbose { - cmdutil.Diag().Infoerrf( - diag.Message("", "%s skipping install (existing == match)"), label) - } + logging.V(1).Infof("%s skipping install (existing == match)", label) continue } } else { if has, _ := workspace.HasPluginGTE(install); has { - if verbose { - cmdutil.Diag().Infoerrf( - diag.Message("", "%s skipping install (existing >= match)"), label) - } + logging.V(1).Infof("%s skipping install (existing >= match)", label) continue } } @@ -126,10 +120,6 @@ func newPluginInstallCmd() *cobra.Command { var tarball io.ReadCloser var err error if file == "" { - if verbose { - cmdutil.Diag().Infoerrf( - diag.Message("", "%s downloading from %s"), label, install.ServerURL) - } var size int64 if tarball, size, err = install.Download(); err != nil { return errors.Wrapf(err, "%s downloading from %s", label, install.ServerURL) @@ -137,18 +127,12 @@ func newPluginInstallCmd() *cobra.Command { tarball = workspace.ReadCloserProgressBar(tarball, size, "Downloading plugin", displayOpts.Color) } else { source = file - if verbose { - cmdutil.Diag().Infoerrf( - diag.Message("", "%s opening tarball from %s"), label, file) - } + logging.V(1).Infof("%s opening tarball from %s", label, file) if tarball, err = os.Open(file); err != nil { return errors.Wrapf(err, "opening file %s", source) } } - if verbose { - cmdutil.Diag().Infoerrf( - diag.Message("", "%s installing tarball ..."), label) - } + logging.V(1).Infof("%s installing tarball ...", label) if err = install.Install(tarball); err != nil { return errors.Wrapf(err, "installing %s from %s", label, source) } @@ -166,8 +150,6 @@ func newPluginInstallCmd() *cobra.Command { "file", "f", "", "Install a plugin from a tarball file, instead of downloading it") cmd.PersistentFlags().BoolVar(&reinstall, "reinstall", false, "Reinstall a plugin even if it already exists") - cmd.PersistentFlags().BoolVar(&verbose, - "verbose", false, "Print detailed information about the installation steps") return cmd } diff --git a/sdk/go/common/workspace/plugins.go b/sdk/go/common/workspace/plugins.go index 75a706fac..71cd9f6bb 100644 --- a/sdk/go/common/workspace/plugins.go +++ b/sdk/go/common/workspace/plugins.go @@ -198,11 +198,15 @@ func (info PluginInfo) Download() (io.ReadCloser, int64, error) { } serverURL = strings.TrimSuffix(serverURL, "/") + logging.V(1).Infof("%s downloading from %s", info.Name, serverURL) + // URL escape the path value to ensure we have the correct path for S3/CloudFront. endpoint := fmt.Sprintf("%s/%s", serverURL, url.QueryEscape(fmt.Sprintf("pulumi-%s-%s-v%s-%s-%s.tar.gz", info.Kind, info.Name, info.Version, os, arch))) + logging.V(9).Infof("full plugin download url: %s", endpoint) + req, err := http.NewRequest("GET", endpoint, nil) if err != nil { return nil, -1, err @@ -211,11 +215,15 @@ func (info PluginInfo) Download() (io.ReadCloser, int64, error) { userAgent := fmt.Sprintf("pulumi-cli/1 (%s; %s)", version.Version, runtime.GOOS) req.Header.Set("User-Agent", userAgent) + logging.V(9).Infof("plugin install request headers: %v", req.Header) + resp, err := httputil.DoWithRetry(req, http.DefaultClient) if err != nil { return nil, -1, err } + logging.V(9).Infof("plugin install response headers: %v", resp.Header) + if resp.StatusCode < 200 || resp.StatusCode > 299 { return nil, -1, errors.Errorf("%d HTTP error fetching plugin from %s", resp.StatusCode, endpoint) } @@ -293,6 +301,7 @@ func installPlugin(finalDir string, tarball io.ReadCloser) error { // the directory. That's OK, just ignore the error. The temp directory created as part of the install will be // cleaned up when we exit by the defer above. fmt.Print("Moving plugin...") + logging.V(1).Infof("moving plugin from %q to %q", tempDir, finalDir) if err := os.Rename(tempDir, finalDir); err != nil && !os.IsExist(err) { switch err.(type) { case *os.LinkError: