Skip to content

Commit

Permalink
Merge branch 'main' into task/CAPPL-100/consensus-cap-beholder-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzaldysanchez authored Nov 13, 2024
2 parents dbe7368 + c220622 commit aaee172
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
15 changes: 14 additions & 1 deletion observability-lib/grafana/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type DeployOptions struct {

func alertRuleExist(alerts []alerting.Rule, alert alerting.Rule) bool {
for _, a := range alerts {
if reflect.DeepEqual(a, alert) {
if reflect.DeepEqual(a.Title, alert.Title) {
return true
}
}
Expand Down Expand Up @@ -212,6 +212,19 @@ func DeleteDashboard(options *DeleteOptions) error {
return errGetDashboard
}

alertsRule, errGetAlertRules := grafanaClient.GetAlertRulesByDashboardUID(*db.UID)
if errGetAlertRules != nil {
return errGetAlertRules
}

// delete existing alert rules for the dashboard if alerts are disabled
for _, rule := range alertsRule {
_, _, errDeleteAlertRule := grafanaClient.DeleteAlertRule(*rule.Uid)
if errDeleteAlertRule != nil {
return errDeleteAlertRule
}
}

_, errDelete := grafanaClient.DeleteDashboardByUID(*db.UID)
if errDelete != nil {
return errDelete
Expand Down
36 changes: 31 additions & 5 deletions pkg/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ type Engine struct {

wg sync.WaitGroup

emitHealthErr func(error)
conds map[string]error
condsMu sync.RWMutex
serviceMethods interface {
emitHealthErr(error)
ifStarted(func() error) error
ifNotStopped(func() error) error
}
conds map[string]error
condsMu sync.RWMutex
}

// Go runs fn in a tracked goroutine that will block closing the service.
Expand Down Expand Up @@ -101,7 +105,13 @@ func (e *Engine) Tracer() trace.Tracer {
}

// EmitHealthErr records an error to be reported via the next call to Healthy().
func (e *Engine) EmitHealthErr(err error) { e.emitHealthErr(err) }
func (e *Engine) EmitHealthErr(err error) { e.serviceMethods.emitHealthErr(err) }

// IfStarted calls fn only if the service is started.
func (e *Engine) IfStarted(fn func() error) error { return e.serviceMethods.ifStarted(fn) }

// IfNotStopped calls fn only if the service is not stopped.
func (e *Engine) IfNotStopped(fn func() error) error { return e.serviceMethods.ifNotStopped(fn) }

// SetHealthCond records a condition key and an error, which causes an unhealthy report, until ClearHealthCond(condition) is called.
// condition keys are for internal use only, and do not show up in the health report.
Expand Down Expand Up @@ -189,7 +199,7 @@ func (c Config) new(lggr logger.SugaredLogger) *service {
conds: make(map[string]error),
},
}
s.eng.emitHealthErr = s.StateMachine.SvcErrBuffer.Append
s.eng.serviceMethods = s // give Engine access to some service methods
if c.NewSubServices != nil {
s.subs = c.NewSubServices(lggr)
}
Expand Down Expand Up @@ -280,3 +290,19 @@ func (s *service) Close() error {
return
})
}

func (s *service) emitHealthErr(err error) { s.StateMachine.SvcErrBuffer.Append(err) }

func (s *service) ifStarted(fn func() error) (err error) {
if !s.IfStarted(func() { err = fn() }) {
return fmt.Errorf("service is %s, not started", s.State())
}
return
}

func (s *service) ifNotStopped(fn func() error) (err error) {
if !s.IfNotStopped(func() { err = fn() }) {
return errors.New("service is stopped")
}
return
}

0 comments on commit aaee172

Please sign in to comment.