Skip to content

Commit

Permalink
♻️ stop all exporters & profilers if initialize failed
Browse files Browse the repository at this point in the history
Signed-off-by: Rintaro Okamura <[email protected]>
  • Loading branch information
rinx committed Jun 18, 2020
1 parent 048c43e commit b7fe0ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions internal/observability/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
}
}
1 change: 1 addition & 0 deletions internal/observability/profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ import (

type Profiler interface {
Start(ctx context.Context) error
Stop(ctx context.Context)
}
3 changes: 3 additions & 0 deletions internal/observability/profiler/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

0 comments on commit b7fe0ed

Please sign in to comment.