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

Iwahbe/2715/add pulumi about command #7817

Merged
merged 50 commits into from
Aug 31, 2021

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Aug 20, 2021

Description

Adds a new command: pulumi about which should print out the information necessary to debug a failure in the pulumi CLI
Fixes #2715

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

This will make it easier to submit debug information to those who work
on pulumi.
Now it's time for a design review.
@iwahbe iwahbe added the kind/enhancement Improvements or new features label Aug 20, 2021
@iwahbe iwahbe requested a review from emiliza August 20, 2021 19:30
@iwahbe iwahbe self-assigned this Aug 20, 2021
@iwahbe iwahbe marked this pull request as draft August 20, 2021 19:33
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
@iwahbe iwahbe requested a review from justinvp August 23, 2021 20:45
@iwahbe iwahbe requested a review from emiliza August 23, 2021 22:24
Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

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

Some comments/questions, but otherwise LGTM!

For future PRs, it'd be nice to show some example output of running the command in the PR description.

It might be fun to add some color to the output when in interactive mode, but we can always do that later.

I ran pulumi about -j in an empty dir and got this:

$ pulumi about -j
{
  "plugins": null,
  "host": {
    "os": "darwin",
    "version": "11.4",
    "arch": "x86_64"
  },
  "backend": {
    "name": "pulumi.com",
    "url": "https://app.pulumi.com/justinvp",
    "user": "justinvp"
  },
  "currentStack": null,
  "cliAbout": {
    "version": "3.11.0-alpha.1629745492+784c661c",
    "goVersion": "go1.17",
    "goCompiler": "gc"
  },
  "runtime": null,
  "errors": [
    {},
    {},
    {}
  ]
}

Two questions:

  1. Should we omit empty/nil values from the JSON output (e.g. "plugins", "currentStack", "runtime") via omitempty in the json struct tags?
  2. What's up with the errors array showing three empty objects? Should these just be strings?

The non-JSON output is:

$ pulumi about
CLI          
Version      3.11.0-alpha.1629745492+784c661c
Go Version   go1.17
Go Compiler  gc

Host     
OS       darwin
Version  11.4
Arch     x86_64

Backend  
Name     pulumi.com
URL      https://app.pulumi.com/justinvp
User     justinvp

Pulumi locates its logs in /var/folders/4q/8cmjgthn18x9gwgq4fvf4q7w0000gn/T/ by default
warning: Failed to get information about the plugin: no Pulumi.yaml project file found (searching upwards from /Users/justin/Desktop/2021/08/23/empty). If you have not created a project yet, use `pulumi new` to do so
warning: Failed to read project: no Pulumi.yaml project file found (searching upwards from /Users/justin/Desktop/2021/08/23/empty). If you have not created a project yet, use `pulumi new` to do so
warning: Failed to get information about the current stack: no Pulumi.yaml project file found (searching upwards from /Users/justin/Desktop/2021/08/23/empty). If you have not created a project yet, use `pulumi new` to do so

pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
var depInfo string
switch language {
case langNodejs:
depInfo = "package.json"
Copy link
Member

Choose a reason for hiding this comment

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

This is fine, but it's often useful to see what was actually installed by looking at package-lock.json or yarn.lock because package.json often includes version ranges. Should we mention those files?

Alternatively, we could consider showing a command to run (similar to what's currently being done for .NET) like npm ls or yarn list, or just run those commands on behalf of the user.

pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about_test.go Outdated Show resolved Hide resolved
"github.com/stretchr/testify/assert"
)

func TestCLI(t *testing.T) {
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 add some integration tests (i.e. add a new tests/about_test.go file similar to the files for the config, stack, history, etc. commands) that actually runs pulumi about and compares some of its output to expected values? (That's what I thought you meant when you were asking me about the tests).

pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about_test.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Show resolved Hide resolved
@iwahbe
Copy link
Member Author

iwahbe commented Aug 24, 2021

I assumed that error would serialize to string. That was my bad. I included the empty lists and null values because I find it simpler to read. If I see currentStack: null then I know that this is the correct printout for the current stack, I just didn't find such a stack this run. Likewise errors: [] tells me that there are no errors, which is different from not noticing any errors.

I'm open to discussion on this decision.

@iwahbe iwahbe marked this pull request as ready for review August 25, 2021 22:12
func TestBackend(t *testing.T) {
stats, err := host.Info()
if err != nil {
t.Skipf("Underlying stats call failed: %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

When can this fail? Should we assert.NoError(t, err) instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

It fails on architectures that Pulumi probably isn't used on. The library I'm using to be generic over platform doesn't support all os/arch pairs that Go supports (less common BSD variations for example).

pkg/cmd/pulumi/about_test.go Outdated Show resolved Hide resolved
tests/about_test.go Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
binDir = "Scripts"
}
// venv makes the link to "python", so this works on windows and mac.
ex := path.Join(rootDir, "venv", binDir, "python")
Copy link
Member

Choose a reason for hiding this comment

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

filepath.Join (applies throughout)

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 just looked up the difference. Is is ever correct to use path.Join? I assumed (incorrectly) that the reason it existed was to be language agnostic.

pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
if err != nil {
return nil, err
}
cmd := exec.Command(ex, "list", "package")
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should include --include-transitive like we do in the runtime host to get the full set of dependencies?

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 intentionally printed only direct dependencies. I thought it made the input too hard to parse otherwise. I can add a flag to include transitive dependencies.

pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
"github.com/stretchr/testify/assert"
)

func TestAboutCommands(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add basic sanity tests for each language?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we can

Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 1 to 4
// Copyright 2016-2021, Pulumi Corporation.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
Copy link
Member

Choose a reason for hiding this comment

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

Nit: There's still an extra line in here:

Suggested change
// Copyright 2016-2021, Pulumi Corporation.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");

tests/about_test.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/about.go Outdated Show resolved Hide resolved
@iwahbe iwahbe merged commit e0a2310 into master Aug 31, 2021
@pulumi-bot pulumi-bot deleted the iwahbe/2715/add-pulumi-about-command branch August 31, 2021 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add command to output information for support
4 participants