Commit Graph

16 Commits

Author SHA1 Message Date
Paul C. Roberts ad4bec1b46
Use the Depth variants in glog calls ()
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

This allows pulumi's log output to contain the location of where the log
call was made from, rather than it always reporting the line in `log.go`
where the glog call was made.
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

This changes

```
I0124 20:53:35.244319  169013 log.go:81] skipping update check
I0124 20:53:36.262079  169013 log.go:81] found username for access token
```
to

```
I0129 14:08:42.918230   38925 pulumi.go:231] skipping update check
I0129 14:08:45.056866   38925 backend.go:615] found username for access token
```

## Checklist

- [X] I have run `make tidy` to update any new dependencies
- [X] I have run `make lint` to verify my code passes the lint check
  - [X] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
- This is hard to test because it is difficult to reliably intercept
stderr from within go tests
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->

Co-authored-by: Paul Roberts <proberts@pulumi.com>
2024-01-29 22:51:45 +00:00
Fraser Waters 571fadae3f Use slice.Prealloc instead of make([]T, 0, ...)
Fixes https://github.com/pulumi/pulumi/issues/12738

https://github.com/pulumi/pulumi/pull/11834 turned on the prealloc
linter and changed a load of slice uses from just `var x T[]` to `x :=
make([]T, 0, preallocSize)`. This was good for performance but it turns
out there are a number of places in the codebase that treat a `nil`
slice as semnatically different to an empty slice.

Trying to test that, or even reason that through for every callsite is
untractable, so this PR replaces all expressions of the form `make([]T,
0, size)` with a call to `slice.Prealloc[T](size)`. When size is 0 that
returns a nil array, rather than an empty array.
2023-06-29 11:27:50 +01:00
Pat Gavlin 864da4bdf9 [logging] Guard verbose logs on glog.Verbose
`glog.Verbose(int)` returns a bool that indicates whether or not
logging is enabled at the given level. Check that result prior to
actually calling the logger in order to avoid extra work when verbose
logging is disabled.
2023-05-25 16:37:06 -07:00
Abhinav Gupta 7aa5b77a0c
all: Reformat with gofumpt
Per team discussion, switching to gofumpt.

[gofumpt][1] is an alternative, stricter alternative to gofmt.
It addresses other stylistic concerns that gofmt doesn't yet cover.

  [1]: https://github.com/mvdan/gofumpt

See the full list of [Added rules][2], but it includes:

- Dropping empty lines around function bodies
- Dropping unnecessary variable grouping when there's only one variable
- Ensuring an empty line between multi-line functions
- simplification (`-s` in gofmt) is always enabled
- Ensuring multi-line function signatures end with
  `) {` on a separate line.

  [2]: https://github.com/mvdan/gofumpt#Added-rules

gofumpt is stricter, but there's no lock-in.
All gofumpt output is valid gofmt output,
so if we decide we don't like it, it's easy to switch back
without any code changes.

gofumpt support is built into the tooling we use for development
so this won't change development workflows.

- golangci-lint includes a gofumpt check (enabled in this PR)
- gopls, the LSP for Go, includes a gofumpt option
  (see [installation instrutions][3])

  [3]: https://github.com/mvdan/gofumpt#installation

This change was generated by running:

```bash
gofumpt -w $(rg --files -g '*.go' | rg -v testdata | rg -v compilation_error)
```

The following files were manually tweaked afterwards:

- pkg/cmd/pulumi/stack_change_secrets_provider.go:
  one of the lines overflowed and had comments in an inconvenient place
- pkg/cmd/pulumi/destroy.go:
  `var x T = y` where `T` wasn't necessary
- pkg/cmd/pulumi/policy_new.go:
  long line because of error message
- pkg/backend/snapshot_test.go:
  long line trying to assign three variables in the same assignment

I have included mention of gofumpt in the CONTRIBUTING.md.
2023-03-03 09:00:24 -08:00
Kyle Dixler fb57480011
Fix 'TestFilter' error where expected and actual are swapped. 2023-02-10 13:26:49 -08:00
Kyle Dixler 75b4df1cf4
Fixes and masks secrets that are JSON encoded such as '\n' and '\t'. 2023-02-10 13:26:49 -08:00
Fraser Waters 8d7e8c44cf Fix V logging to also filter out secrets
We use a small logging wrapper around glog for most of our logging. The
global Errorf/Warningf/Infof methods in that module format the string
and args passed in then filter out any secrets before calling into glog
with the final string.

The wrapper also exposed a `V` method to only log if verbosity was set,
but that directly returned a glog.Verbose which mean the Infof calls to
that didn't run our secret filtering code.

This changes the logging wrapper to return a `VerboseShim` (Not a great
name, but `Verbose` was already taken in this module) which is simply a
new type over `glog.Verbose` with the same methods but it calls
`FilterString` on the inputs.

Technically a breaking change, but I think the uses of this will be
source compatible.
2023-02-07 22:22:22 +00:00
Robbie McKinstry 4959522a53
Repair tests expecting nil slices 2023-01-11 21:53:04 -08:00
Robbie McKinstry 1f78baae71
Preallocate slices with a known capacity.
Enable the prealloc linter, which identifies slices
with a known capacity, but are not preallocated, which
results in unnecessary allocations and memcpys.
2023-01-11 12:52:51 -08:00
Aaron Friel ed2923653c ci: radical idea - what if slow tests & no stdout makes GH consider runner dead? 2022-03-06 14:52:13 -08:00
Pat Gavlin d3e49ecb65
[cli, testing, github] Gather code coverage data in CI. ()
These changes add support for gathering code coverage data during tests.

For tests that do not involve the Pulumi CLI, this is straightforward: all of
the ecosystems we target already support gathering coverage data, and we follow
the rules accordingly. Support for each language is broken out into its own
commit.

For tests that do involve the Pulumi CLI, the picture is a bit more complicated.
Go does not make it trivial to perform a coverage-instrumented build (go build
does not have a -cover flag, for example). In lieu of official support, we abuse
go test -c and TestMain to produce a build of the CLI that supports collecting
and reporting coverage data.
2021-11-30 17:24:01 -08:00
Evan Boyle 80f1989600
Removing the need for vendoring () 2020-03-25 15:57:46 -07:00
evanboyle 163444bce6 disable logging test 2020-03-19 14:45:03 -07:00
evanboyle 31d8f79f35 fix klog initialization 2020-03-19 10:01:10 -07:00
evanboyle 4e44854308 replace glog with klog 2020-03-19 08:56:44 -07:00
evanboyle c3f6ae2451 move pkg/util/logging -> sdk/go/common/util/logging 2020-03-18 15:34:58 -07:00