From 9699985e73db79433b64933319e14a774113000e Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Thu, 18 Jun 2020 16:36:42 +0900 Subject: [PATCH] :recycle: stop all exporters & profilers if initialize failed Signed-off-by: Rintaro Okamura --- internal/observability/observability.go | 17 +++++++++++++++-- internal/observability/profiler/profiler.go | 1 + .../profiler/stackdriver/stackdriver.go | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/internal/observability/observability.go b/internal/observability/observability.go index 512afb9885..c6e3ed7468 100644 --- a/internal/observability/observability.go +++ b/internal/observability/observability.go @@ -212,16 +212,25 @@ func (o *observability) PreStart(ctx context.Context) (err error) { return err } - for _, ex := range o.exporters { + for i, ex := range o.exporters { err = ex.Start(ctx) if err != nil { + for _, ex = range o.exporters[:i] { + ex.Stop(ctx) + } return err } } - for _, prof := range o.profilers { + for i, prof := range o.profilers { err = prof.Start(ctx) if err != nil { + for _, ex := range o.exporters { + ex.Stop(ctx) + } + for _, prof = range o.profilers[:i] { + prof.Stop(ctx) + } return err } } @@ -264,4 +273,8 @@ func (o *observability) Stop(ctx context.Context) { for _, ex := range o.exporters { ex.Stop(ctx) } + + for _, prof := range o.profilers { + prof.Stop(ctx) + } } diff --git a/internal/observability/profiler/profiler.go b/internal/observability/profiler/profiler.go index 9ef622f26c..7d4abf1998 100644 --- a/internal/observability/profiler/profiler.go +++ b/internal/observability/profiler/profiler.go @@ -23,4 +23,5 @@ import ( type Profiler interface { Start(ctx context.Context) error + Stop(ctx context.Context) } diff --git a/internal/observability/profiler/stackdriver/stackdriver.go b/internal/observability/profiler/stackdriver/stackdriver.go index 1d71fe0503..454b511c02 100644 --- a/internal/observability/profiler/stackdriver/stackdriver.go +++ b/internal/observability/profiler/stackdriver/stackdriver.go @@ -51,3 +51,6 @@ func New(opts ...Option) (s Stackdriver, err error) { func (p *prof) Start(ctx context.Context) (err error) { return profiler.Start(*p.Config, p.clientOpts...) } + +func (p *prof) Stop(ctx context.Context) { +}