Add debug logging settings for common automation API operations
This commit is contained in:
parent
7e3d69a53a
commit
458c53df44
36
sdk/go/x/auto/debug/debuglogging.go
Normal file
36
sdk/go/x/auto/debug/debuglogging.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package debug
|
||||
|
||||
import "fmt"
|
||||
|
||||
type LoggingOptions struct {
|
||||
// LogLevel - choose verbosity level between 1 (least verbose) to 9 (most verbose).
|
||||
// If not specified, reverts to default log level.
|
||||
// Note - These logs may include sensitive information that is provided from your
|
||||
// execution environment to your cloud provider (and which Pulumi may not even
|
||||
// itself be aware of).
|
||||
LogLevel *uint
|
||||
// LogToStdErr specifies that all logs should be sent directly to stderr - making it
|
||||
// more accessible and avoiding OS level buffering.
|
||||
LogToStdErr bool
|
||||
// FlowToPlugins reflects the logging settings to plugins as well.
|
||||
FlowToPlugins bool
|
||||
}
|
||||
|
||||
func AddArgs(debugLogOpts *LoggingOptions, sharedArgs []string) []string {
|
||||
if debugLogOpts.LogToStdErr {
|
||||
sharedArgs = append(sharedArgs, "--logtostderr")
|
||||
}
|
||||
if debugLogOpts.LogLevel != nil {
|
||||
if *debugLogOpts.LogLevel > 9 {
|
||||
*debugLogOpts.LogLevel = 9
|
||||
}
|
||||
if *debugLogOpts.LogLevel == 0 {
|
||||
*debugLogOpts.LogLevel = 1
|
||||
}
|
||||
sharedArgs = append(sharedArgs, fmt.Sprintf("-v=%d", *debugLogOpts.LogLevel))
|
||||
}
|
||||
if debugLogOpts.FlowToPlugins {
|
||||
sharedArgs = append(sharedArgs, "--logflow")
|
||||
}
|
||||
return sharedArgs
|
||||
}
|
|
@ -25,7 +25,6 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pulumi/pulumi/sdk/v2/go/common/apitype"
|
||||
"github.com/pulumi/pulumi/sdk/v2/go/common/tokens"
|
||||
"github.com/pulumi/pulumi/sdk/v2/go/common/workspace"
|
||||
|
@ -36,7 +35,7 @@ import (
|
|||
"github.com/pulumi/pulumi/sdk/v2/go/x/auto/optup"
|
||||
)
|
||||
|
||||
func Example() error {
|
||||
func Example() {
|
||||
ctx := context.Background()
|
||||
|
||||
// This stack creates an output
|
||||
|
@ -47,12 +46,12 @@ func Example() error {
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create stackA")
|
||||
// return errors.Wrap(err, "failed to create stackA")
|
||||
}
|
||||
// deploy the stack
|
||||
aRes, err := stackA.Up(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update bucket stackA")
|
||||
// return errors.Wrap(err, "failed to update bucket stackA")
|
||||
}
|
||||
|
||||
// this stack creates an uses stackA's output to create a new output
|
||||
|
@ -70,17 +69,16 @@ func Example() error {
|
|||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create object stackB")
|
||||
// return errors.Wrap(err, "failed to create object stackB")
|
||||
}
|
||||
// deploy the stack
|
||||
bRes, err := stackB.Up(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update stackB")
|
||||
// return errors.Wrap(err, "failed to update stackB")
|
||||
}
|
||||
|
||||
// Success!
|
||||
fmt.Println(bRes.Summary.Result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExampleFullyQualifiedStackName() {
|
||||
|
@ -631,7 +629,7 @@ func ExampleSetupFn() {
|
|||
NewStackRemoteSource(ctx, stackName, repo)
|
||||
}
|
||||
|
||||
func ExampleStack() error {
|
||||
func ExampleStack() {
|
||||
ctx := context.Background()
|
||||
stackName := FullyQualifiedStackName("org", "project", "dev_stack")
|
||||
cfg := ConfigMap{
|
||||
|
@ -648,7 +646,7 @@ func ExampleStack() error {
|
|||
pDir := filepath.Join(".", "project")
|
||||
s, err := NewStackLocalSource(ctx, stackName, pDir)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle failure creating stack.
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
@ -659,13 +657,13 @@ func ExampleStack() error {
|
|||
|
||||
err = s.SetAllConfig(ctx, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle failure setting configurations.
|
||||
}
|
||||
|
||||
// -- pulumi up --
|
||||
res, err := s.Up(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle failure updating stack.
|
||||
}
|
||||
fmt.Println(len(res.Outputs))
|
||||
|
||||
|
@ -673,7 +671,7 @@ func ExampleStack() error {
|
|||
|
||||
prev, err := s.Preview(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle failure previewing stack.
|
||||
}
|
||||
// no changes after the update
|
||||
fmt.Println(prev.ChangeSummary["same"])
|
||||
|
@ -681,9 +679,8 @@ func ExampleStack() error {
|
|||
// -- pulumi refresh --
|
||||
|
||||
ref, err := s.Refresh(ctx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle error during refresh.
|
||||
}
|
||||
// Success!
|
||||
fmt.Println(ref.Summary.Result)
|
||||
|
@ -692,41 +689,44 @@ func ExampleStack() error {
|
|||
|
||||
_, err = s.Destroy(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle error during destroy.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExampleNewStack() error {
|
||||
func ExampleNewStack() {
|
||||
ctx := context.Background()
|
||||
w, err := NewLocalWorkspace(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle error creating workspace.
|
||||
}
|
||||
|
||||
stackName := FullyQualifiedStackName("org", "proj", "stack")
|
||||
stack, err := NewStack(ctx, stackName, w)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle error creating stack.
|
||||
}
|
||||
_, err = stack.Up(ctx)
|
||||
return err
|
||||
if err != nil {
|
||||
// Handle error updating stack.
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleUpsertStack() error {
|
||||
func ExampleUpsertStack() {
|
||||
ctx := context.Background()
|
||||
w, err := NewLocalWorkspace(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle error creating workspace.
|
||||
}
|
||||
|
||||
stackName := FullyQualifiedStackName("org", "proj", "stack")
|
||||
stack, err := UpsertStack(ctx, stackName, w)
|
||||
if err != nil {
|
||||
return err
|
||||
// Handle error creating/updating stack.
|
||||
}
|
||||
_, err = stack.Up(ctx)
|
||||
return err
|
||||
if err != nil {
|
||||
// Handle error during update.
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleNewStackInlineSource() {
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
// github.com/sdk/v2/go/x/auto Stack.Destroy(...optdestroy.Option)
|
||||
package optdestroy
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"github.com/pulumi/pulumi/sdk/v2/go/x/auto/debug"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Parallel is the number of resource operations to run in parallel at once during the destroy
|
||||
// (1 for no parallelism). Defaults to unbounded. (default 2147483647)
|
||||
|
@ -54,6 +57,12 @@ func ProgressStreams(writers ...io.Writer) Option {
|
|||
})
|
||||
}
|
||||
|
||||
func DebugLogging(debugOpts debug.LoggingOptions) Option {
|
||||
return optionFunc(func(opts *Options) {
|
||||
opts.DebugLogOpts = debugOpts
|
||||
})
|
||||
}
|
||||
|
||||
// Option is a parameter to be applied to a Stack.Destroy() operation
|
||||
type Option interface {
|
||||
ApplyOption(*Options)
|
||||
|
@ -74,6 +83,8 @@ type Options struct {
|
|||
TargetDependents bool
|
||||
// ProgressStreams allows specifying one or more io.Writers to redirect incremental destroy output
|
||||
ProgressStreams []io.Writer
|
||||
// DebugLogOpts specifies additional settings for debug logging
|
||||
DebugLogOpts debug.LoggingOptions
|
||||
}
|
||||
|
||||
type optionFunc func(*Options)
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
// github.com/sdk/v2/go/x/auto Stack.Preview(...optpreview.Option)
|
||||
package optpreview
|
||||
|
||||
import (
|
||||
"github.com/pulumi/pulumi/sdk/v2/go/x/auto/debug"
|
||||
)
|
||||
|
||||
// Parallel is the number of resource operations to run in parallel at once during the update
|
||||
// (1 for no parallelism). Defaults to unbounded. (default 2147483647)
|
||||
func Parallel(n int) Option {
|
||||
|
@ -59,6 +63,12 @@ func TargetDependents() Option {
|
|||
})
|
||||
}
|
||||
|
||||
func DebugLogging(debugOpts debug.LoggingOptions) Option {
|
||||
return optionFunc(func(opts *Options) {
|
||||
opts.DebugLogOpts = debugOpts
|
||||
})
|
||||
}
|
||||
|
||||
// Option is a parameter to be applied to a Stack.Preview() operation
|
||||
type Option interface {
|
||||
ApplyOption(*Options)
|
||||
|
@ -81,6 +91,8 @@ type Options struct {
|
|||
Target []string
|
||||
// Allows updating of dependent targets discovered but not specified in the Target list
|
||||
TargetDependents bool
|
||||
// DebugLogOpts specifies additional settings for debug logging
|
||||
DebugLogOpts debug.LoggingOptions
|
||||
}
|
||||
|
||||
type optionFunc func(*Options)
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
// github.com/sdk/v2/go/x/auto Stack.Refresh(...optrefresh.Option)
|
||||
package optrefresh
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"github.com/pulumi/pulumi/sdk/v2/go/x/auto/debug"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Parallel is the number of resource operations to run in parallel at once during the refresh
|
||||
// (1 for no parallelism). Defaults to unbounded. (default 2147483647)
|
||||
|
@ -54,6 +57,12 @@ func ProgressStreams(writers ...io.Writer) Option {
|
|||
})
|
||||
}
|
||||
|
||||
func DebugLogging(debugOpts debug.LoggingOptions) Option {
|
||||
return optionFunc(func(opts *Options) {
|
||||
opts.DebugLogOpts = debugOpts
|
||||
})
|
||||
}
|
||||
|
||||
// Option is a parameter to be applied to a Stack.Refresh() operation
|
||||
type Option interface {
|
||||
ApplyOption(*Options)
|
||||
|
@ -74,6 +83,8 @@ type Options struct {
|
|||
Target []string
|
||||
// ProgressStreams allows specifying one or more io.Writers to redirect incremental refresh output
|
||||
ProgressStreams []io.Writer
|
||||
// DebugLogOpts specifies additional settings for debug logging
|
||||
DebugLogOpts debug.LoggingOptions
|
||||
}
|
||||
|
||||
type optionFunc func(*Options)
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
// github.com/sdk/v2/go/x/auto Stack.Up(...optup.Option)
|
||||
package optup
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"github.com/pulumi/pulumi/sdk/v2/go/x/auto/debug"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Parallel is the number of resource operations to run in parallel at once during the update
|
||||
// (1 for no parallelism). Defaults to unbounded. (default 2147483647)
|
||||
|
@ -68,6 +71,12 @@ func ProgressStreams(writers ...io.Writer) Option {
|
|||
})
|
||||
}
|
||||
|
||||
func DebugLogging(debugOpts debug.LoggingOptions) Option {
|
||||
return optionFunc(func(opts *Options) {
|
||||
opts.DebugLogOpts = debugOpts
|
||||
})
|
||||
}
|
||||
|
||||
// Option is a parameter to be applied to a Stack.Up() operation
|
||||
type Option interface {
|
||||
ApplyOption(*Options)
|
||||
|
@ -92,6 +101,8 @@ type Options struct {
|
|||
TargetDependents bool
|
||||
// ProgressStreams allows specifying one or more io.Writers to redirect incremental update output
|
||||
ProgressStreams []io.Writer
|
||||
// DebugLogOpts specifies additional settings for debug logging
|
||||
DebugLogOpts debug.LoggingOptions
|
||||
}
|
||||
|
||||
type optionFunc func(*Options)
|
||||
|
|
|
@ -91,6 +91,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pulumi/pulumi/sdk/v2/go/x/auto/debug"
|
||||
"io"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
@ -216,6 +217,8 @@ func (s *Stack) Preview(ctx context.Context, opts ...optpreview.Option) (Preview
|
|||
}
|
||||
|
||||
var sharedArgs []string
|
||||
|
||||
sharedArgs = debug.AddArgs(&preOpts.DebugLogOpts, sharedArgs)
|
||||
if preOpts.Message != "" {
|
||||
sharedArgs = append(sharedArgs, fmt.Sprintf("--message=%q", preOpts.Message))
|
||||
}
|
||||
|
@ -276,6 +279,8 @@ func (s *Stack) Up(ctx context.Context, opts ...optup.Option) (UpResult, error)
|
|||
}
|
||||
|
||||
var sharedArgs []string
|
||||
|
||||
sharedArgs = debug.AddArgs(&upOpts.DebugLogOpts, sharedArgs)
|
||||
if upOpts.Message != "" {
|
||||
sharedArgs = append(sharedArgs, fmt.Sprintf("--message=%q", upOpts.Message))
|
||||
}
|
||||
|
@ -351,7 +356,10 @@ func (s *Stack) Refresh(ctx context.Context, opts ...optrefresh.Option) (Refresh
|
|||
o.ApplyOption(refreshOpts)
|
||||
}
|
||||
|
||||
args := []string{"refresh", "--yes", "--skip-preview"}
|
||||
var args []string
|
||||
|
||||
args = debug.AddArgs(&refreshOpts.DebugLogOpts, args)
|
||||
args = append(args, "refresh", "--yes", "--skip-preview")
|
||||
if refreshOpts.Message != "" {
|
||||
args = append(args, fmt.Sprintf("--message=%q", refreshOpts.Message))
|
||||
}
|
||||
|
@ -408,7 +416,10 @@ func (s *Stack) Destroy(ctx context.Context, opts ...optdestroy.Option) (Destroy
|
|||
o.ApplyOption(destroyOpts)
|
||||
}
|
||||
|
||||
args := []string{"destroy", "--yes", "--skip-preview"}
|
||||
var args []string
|
||||
|
||||
args = debug.AddArgs(&destroyOpts.DebugLogOpts, args)
|
||||
args = append(args, "destroy", "--yes", "--skip-preview")
|
||||
if destroyOpts.Message != "" {
|
||||
args = append(args, fmt.Sprintf("--message=%q", destroyOpts.Message))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue