Skip to content

Commit

Permalink
cache disabled checks
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jul 19, 2023
1 parent 4519fcd commit c4af34b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions checks/runchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"github.com/flanksource/canary-checker/pkg"
"github.com/flanksource/canary-checker/pkg/db"
"github.com/flanksource/commons/logger"
"github.com/patrickmn/go-cache"
)

// A list of check types that are permanently disabled.
var disabledChecks map[string]struct{}
var checksCache = cache.New(5*time.Minute, 5*time.Minute)

func getDisabledChecks(ctx *context.Context) (map[string]struct{}, error) {
if disabledChecks != nil {
return disabledChecks, nil
if val, ok := checksCache.Get("disabledChecks"); ok {
return val.(map[string]struct{}), nil
}

result := make(map[string]struct{})
Expand All @@ -45,8 +45,8 @@ func getDisabledChecks(ctx *context.Context) (map[string]struct{}, error) {
return nil, rows.Err()
}

disabledChecks = result
return disabledChecks, nil
checksCache.SetDefault("disabledChecks", result)
return result, nil
}

func RunChecks(ctx *context.Context) ([]*pkg.CheckResult, error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
github.com/onsi/gomega v1.27.6
github.com/opensearch-project/opensearch-go/v2 v2.3.0
github.com/orcaman/concurrent-map v1.0.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.5
Expand Down Expand Up @@ -221,7 +222,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pegasus-kv/thrift v0.13.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
Expand Down

0 comments on commit c4af34b

Please sign in to comment.