Skip to content

Commit

Permalink
Merge pull request #2564 from carolynvs/reconcile-tracing
Browse files Browse the repository at this point in the history
Improve trace data when reconciling an installation
  • Loading branch information
carolynvs authored Feb 13, 2023
2 parents 601b373 + bef1c1a commit b712702
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions pkg/porter/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ReconcileOptions struct {
// to an installation. For uninstall or invoke, you should call those directly.
func (p *Porter) ReconcileInstallation(ctx context.Context, opts ReconcileOptions) error {
ctx, log := tracing.StartSpan(ctx)
defer log.EndSpan()
log.Debugf("Reconciling %s/%s installation", opts.Namespace, opts.Name)

// Get the last run of the installation, if available
Expand Down
14 changes: 8 additions & 6 deletions pkg/secrets/pluginstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"get.porter.sh/porter/pkg/plugins/pluggable"
"get.porter.sh/porter/pkg/secrets/plugins"
"get.porter.sh/porter/pkg/tracing"
"go.opentelemetry.io/otel/attribute"
)

var _ plugins.SecretsProtocol = &Store{}
Expand Down Expand Up @@ -49,7 +50,9 @@ func NewSecretsPluginConfig() pluggable.PluginTypeConfig {
}

func (s *Store) Resolve(ctx context.Context, keyName string, keyValue string) (string, error) {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
attribute.String("keyName", keyName),
attribute.String("keyValue", keyValue))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand All @@ -64,7 +67,9 @@ func (s *Store) Resolve(ctx context.Context, keyName string, keyValue string) (s
}

func (s *Store) Create(ctx context.Context, keyName string, keyValue string, value string) error {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
attribute.String("keyName", keyName),
attribute.String("keyValue", keyValue))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand All @@ -73,10 +78,7 @@ func (s *Store) Create(ctx context.Context, keyName string, keyValue string, val

err := s.plugin.Create(ctx, keyName, keyValue, value)
if errors.Is(err, plugins.ErrNotImplemented) {
//TODO: add the doc page link once it exists
return span.Error(fmt.Errorf(`the current secrets plugin does not support persisting secrets. You need to edit your porter configuration file and configure a different secrets plugin.
If you are just testing out Porter, and are not working with production secrets, you can edit your config file and set default-storage-plugin to "filesystem" to use the insecure filesystem plugin. Do not use the filesystem plugin for production data.: %w`, err))
return span.Error(fmt.Errorf(`the current secrets plugin does not support persisting secrets. You need to edit your porter configuration file and configure a different secrets plugin. See https://getporter.org/end-users/configuration/#change-the-default-secrets-plugin for details: %w`, err))
}

return span.Error(err)
Expand Down
27 changes: 19 additions & 8 deletions pkg/storage/pluginstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"get.porter.sh/porter/pkg/storage/plugins"
"get.porter.sh/porter/pkg/tracing"
"go.mongodb.org/mongo-driver/bson"
"go.opentelemetry.io/otel/attribute"
)

var _ io.Closer = &Store{}
Expand Down Expand Up @@ -90,7 +91,8 @@ func (s *Store) Close() error {
}

func (s *Store) EnsureIndex(ctx context.Context, opts plugins.EnsureIndexOptions) error {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("options", opts))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand All @@ -102,7 +104,8 @@ func (s *Store) EnsureIndex(ctx context.Context, opts plugins.EnsureIndexOptions
}

func (s *Store) Aggregate(ctx context.Context, opts plugins.AggregateOptions) ([]bson.Raw, error) {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("options", opts))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand All @@ -118,7 +121,8 @@ func (s *Store) Aggregate(ctx context.Context, opts plugins.AggregateOptions) ([
}

func (s *Store) Count(ctx context.Context, opts plugins.CountOptions) (int64, error) {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("options", opts))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand All @@ -129,23 +133,27 @@ func (s *Store) Count(ctx context.Context, opts plugins.CountOptions) (int64, er
if err != nil {
return 0, span.Error(err)
}
span.SetAttributes(attribute.Int64("result", count))
return count, nil
}

func (s *Store) Find(ctx context.Context, opts plugins.FindOptions) ([]bson.Raw, error) {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("options", opts))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
return nil, err
}

results, err := s.plugin.Find(ctx, opts)
span.SetAttributes(attribute.Int("results", len(results)))
return results, span.Error(err)
}

func (s *Store) Insert(ctx context.Context, opts plugins.InsertOptions) error {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("options", opts))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand All @@ -157,7 +165,8 @@ func (s *Store) Insert(ctx context.Context, opts plugins.InsertOptions) error {
}

func (s *Store) Patch(ctx context.Context, opts plugins.PatchOptions) error {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("options", opts))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand All @@ -169,7 +178,8 @@ func (s *Store) Patch(ctx context.Context, opts plugins.PatchOptions) error {
}

func (s *Store) Remove(ctx context.Context, opts plugins.RemoveOptions) error {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("options", opts))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand All @@ -181,7 +191,8 @@ func (s *Store) Remove(ctx context.Context, opts plugins.RemoveOptions) error {
}

func (s *Store) Update(ctx context.Context, opts plugins.UpdateOptions) error {
ctx, span := tracing.StartSpan(ctx)
ctx, span := tracing.StartSpan(ctx,
tracing.ObjectAttribute("options", opts))
defer span.EndSpan()

if err := s.Connect(ctx); err != nil {
Expand Down

0 comments on commit b712702

Please sign in to comment.