2020-01-15 19:00:31 +00:00
|
|
|
package pkger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-04-30 04:50:52 +00:00
|
|
|
"github.com/opentracing/opentracing-go/log"
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
"github.com/influxdata/influxdb/v2/kit/tracing"
|
2020-01-15 19:00:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type traceMW struct {
|
|
|
|
next SVC
|
|
|
|
}
|
|
|
|
|
|
|
|
// MWTracing adds tracing functionality for the service.
|
|
|
|
func MWTracing() SVCMiddleware {
|
|
|
|
return func(svc SVC) SVC {
|
|
|
|
return &traceMW{next: svc}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ SVC = (*traceMW)(nil)
|
|
|
|
|
2020-03-20 23:20:53 +00:00
|
|
|
func (s *traceMW) InitStack(ctx context.Context, userID influxdb.ID, newStack Stack) (Stack, error) {
|
2020-03-20 02:08:35 +00:00
|
|
|
span, ctx := tracing.StartSpanFromContextWithOperationName(ctx, "InitStack")
|
|
|
|
defer span.Finish()
|
2020-03-20 23:20:53 +00:00
|
|
|
return s.next.InitStack(ctx, userID, newStack)
|
2020-03-20 02:08:35 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 04:50:52 +00:00
|
|
|
func (s *traceMW) ListStacks(ctx context.Context, orgID influxdb.ID, f ListFilter) ([]Stack, error) {
|
|
|
|
span, ctx := tracing.StartSpanFromContextWithOperationName(ctx, "ListStacks")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
stacks, err := s.next.ListStacks(ctx, orgID, f)
|
|
|
|
span.LogFields(
|
|
|
|
log.String("org_id", orgID.String()),
|
|
|
|
log.Int("num_stacks", len(stacks)),
|
|
|
|
)
|
|
|
|
return stacks, err
|
|
|
|
}
|
|
|
|
|
2020-01-15 19:00:31 +00:00
|
|
|
func (s *traceMW) CreatePkg(ctx context.Context, setters ...CreatePkgSetFn) (pkg *Pkg, err error) {
|
|
|
|
span, ctx := tracing.StartSpanFromContextWithOperationName(ctx, "CreatePkg")
|
|
|
|
defer span.Finish()
|
|
|
|
return s.next.CreatePkg(ctx, setters...)
|
|
|
|
}
|
|
|
|
|
2020-02-06 05:42:01 +00:00
|
|
|
func (s *traceMW) DryRun(ctx context.Context, orgID, userID influxdb.ID, pkg *Pkg, opts ...ApplyOptFn) (sum Summary, diff Diff, err error) {
|
2020-01-15 19:00:31 +00:00
|
|
|
span, ctx := tracing.StartSpanFromContextWithOperationName(ctx, "DryRun")
|
|
|
|
span.LogKV("orgID", orgID.String(), "userID", userID.String())
|
|
|
|
defer span.Finish()
|
2020-02-06 05:42:01 +00:00
|
|
|
return s.next.DryRun(ctx, orgID, userID, pkg, opts...)
|
2020-01-15 19:00:31 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 04:51:13 +00:00
|
|
|
func (s *traceMW) Apply(ctx context.Context, orgID, userID influxdb.ID, pkg *Pkg, opts ...ApplyOptFn) (sum Summary, diff Diff, err error) {
|
2020-01-15 19:00:31 +00:00
|
|
|
span, ctx := tracing.StartSpanFromContextWithOperationName(ctx, "Apply")
|
|
|
|
span.LogKV("orgID", orgID.String(), "userID", userID.String())
|
|
|
|
defer span.Finish()
|
|
|
|
return s.next.Apply(ctx, orgID, userID, pkg, opts...)
|
|
|
|
}
|