Skip to content

Commit

Permalink
Merge pull request #1082 from flanksource/check-deleted-at
Browse files Browse the repository at this point in the history
fix: check deleted_at before running canaries and update cron management
  • Loading branch information
moshloop authored Jun 19, 2023
2 parents 27fe7cc + cde3b6d commit 8763b85
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion checks/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ func (c *NamespaceChecker) getHTTP(url string, timeout int64, deadline time.Time
hardDeadline = softTimeoutDeadline
}

ctx, _ := gocontext.WithDeadline(gocontext.Background(), hardDeadline) // nolint: govet
ctx, cancelFunc := gocontext.WithDeadline(gocontext.Background(), hardDeadline)
defer cancelFunc()

req, err := http.NewRequest("GET", url, nil)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion checks/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ func (c *PodChecker) getHTTP(url string, timeout int64, deadline time.Time) (str
hardDeadline = softTimeoutDeadline
}

ctx, _ := gocontext.WithDeadline(gocontext.Background(), hardDeadline) // nolint: govet
ctx, cancelFunc := gocontext.WithDeadline(gocontext.Background(), hardDeadline)
defer cancelFunc()

req, err := http.NewRequest("GET", url, nil)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions checks/runchecks.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package checks

import (
"database/sql"
"time"

"github.com/flanksource/canary-checker/api/context"
v1 "github.com/flanksource/canary-checker/api/v1"
"github.com/flanksource/canary-checker/pkg"
"github.com/flanksource/canary-checker/pkg/db"
"github.com/flanksource/commons/logger"
)

func RunChecks(ctx *context.Context) []*pkg.CheckResult {
var results []*pkg.CheckResult

// Check if canary is not marked deleted in DB
if db.Gorm != nil {
var deletedAt sql.NullTime
err := db.Gorm.Table("canaries").Select("deleted_at").Where("id = ?", ctx.Canary.GetPersistedID()).Scan(&deletedAt).Error
if err == nil && deletedAt.Valid {
return results
}
}

checks := ctx.Canary.Spec.GetAllChecks()
ctx.Debugf("[%s] checking %d checks", ctx.Canary.Name, len(checks))
for _, c := range All {
Expand Down
9 changes: 1 addition & 8 deletions pkg/jobs/canary/canary_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package canary
import (
"fmt"
"path"
"reflect"
"sync"
"time"

Expand Down Expand Up @@ -243,13 +242,7 @@ func SyncCanaryJob(canary v1.Canary) error {

entry := findCronEntry(canary)
if entry != nil {
job := entry.Job.(CanaryJob)
if !reflect.DeepEqual(job.Canary.Spec, canary.Spec) {
logger.Infof("Rescheduling %s canary with updated specs", canary)
CanaryScheduler.Remove(entry.ID)
} else {
return nil
}
CanaryScheduler.Remove(entry.ID)
}

job := CanaryJob{
Expand Down

0 comments on commit 8763b85

Please sign in to comment.