Skip to content

Commit

Permalink
use properties table for disabled checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jul 17, 2023
1 parent bf0a734 commit 437f081
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions api/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ type Context struct {
db *gorm.DB
}

func (ctx *Context) DB() *gorm.DB {
if ctx.db == nil {
return nil
}

return ctx.db.WithContext(ctx.Context)
}

func (ctx *Context) String() string {
return fmt.Sprintf("%s/%s", ctx.Canary.Namespace, ctx.Canary.Name)
}
Expand Down
12 changes: 8 additions & 4 deletions checks/runchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ import (
// A list of check types that are permanently disabled.
var disabledChecks map[string]struct{}

func getDisabledChecks() (map[string]struct{}, error) {
func getDisabledChecks(ctx *context.Context) (map[string]struct{}, error) {
if disabledChecks != nil {
return disabledChecks, nil
}

rows, err := db.Gorm.Raw("SELECT name FROM disabled_checks").Rows()
result := make(map[string]struct{})
if ctx.DB() == nil {
return result, nil
}

rows, err := ctx.DB().Raw("SELECT value FROM properties WHERE name = 'check'").Rows()
if err != nil {
return nil, err
}
defer rows.Close()

result := make(map[string]struct{})
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {
Expand All @@ -47,7 +51,7 @@ func getDisabledChecks() (map[string]struct{}, error) {
func RunChecks(ctx *context.Context) ([]*pkg.CheckResult, error) {
var results []*pkg.CheckResult

disabledChecks, err := getDisabledChecks()
disabledChecks, err := getDisabledChecks(ctx)
if err != nil {
return nil, fmt.Errorf("error getting disabled checks: %v", err)
}
Expand Down

0 comments on commit 437f081

Please sign in to comment.