These changes enable tracing of Pulumi API calls. The span with which to associate an API call is passed via a `context.Context` parameter. This required plumbing a `context.Context` parameter through a rather large number of APIs, especially in the backend. In general, all API calls are associated with a new root span that exists for essentially the entire lifetime of an invocation of the Pulumi CLI. There were a few places where the plumbing got a bit hairier than I was willing to address with these changes; I've used `context.Background()` in these instances. API calls that receive this context will create new root spans, but will still be traced.
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
|
|
|
package cloud
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pulumi/pulumi/pkg/backend"
|
|
"github.com/pulumi/pulumi/pkg/backend/cloud/client"
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
|
"github.com/pulumi/pulumi/pkg/resource/stack"
|
|
)
|
|
|
|
// cloudSnapshotPersister persists snapshots to the Pulumi service.
|
|
type cloudSnapshotPersister struct {
|
|
context context.Context // The context to use for client requests.
|
|
update client.UpdateIdentifier // The UpdateIdentifier for this update sequence.
|
|
tokenSource *tokenSource // A token source for interacting with the service.
|
|
backend *cloudBackend // A backend for communicating with the service
|
|
}
|
|
|
|
func (persister *cloudSnapshotPersister) Invalidate() error {
|
|
token, err := persister.tokenSource.GetToken()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return persister.backend.client.InvalidateUpdateCheckpoint(persister.context, persister.update, token)
|
|
}
|
|
|
|
func (persister *cloudSnapshotPersister) Save(snapshot *deploy.Snapshot) error {
|
|
token, err := persister.tokenSource.GetToken()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
deployment := stack.SerializeDeployment(snapshot)
|
|
return persister.backend.client.PatchUpdateCheckpoint(persister.context, persister.update, deployment, token)
|
|
}
|
|
|
|
var _ backend.SnapshotPersister = (*cloudSnapshotPersister)(nil)
|
|
|
|
func (cb *cloudBackend) newSnapshotPersister(ctx context.Context, update client.UpdateIdentifier,
|
|
tokenSource *tokenSource) *cloudSnapshotPersister {
|
|
return &cloudSnapshotPersister{
|
|
context: ctx,
|
|
update: update,
|
|
tokenSource: tokenSource,
|
|
backend: cb,
|
|
}
|
|
}
|