Skip to content

Commit

Permalink
use the new canary endpoint response from incident commander
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Aug 2, 2023
1 parent bda21d9 commit 5c72f6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions pkg/jobs/canary/sync_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func ReconcileCanaryResults() {
}
}

type CanaryPullResponse struct {
Before time.Time `json:"before"`
Canaries []models.Canary `json:"canaries,omitempty"`
}

// UpstreamPullJob pulls canaries from the upstream
type UpstreamPullJob struct {
lastRuntime time.Time
Expand Down Expand Up @@ -88,23 +93,23 @@ func (t *UpstreamPullJob) pull(config upstream.UpstreamConfig) error {
}
defer resp.Body.Close()

var canaries []models.Canary
if err := json.NewDecoder(resp.Body).Decode(&canaries); err != nil {
var response CanaryPullResponse
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
return fmt.Errorf("error decoding response: %w", err)
}

t.lastRuntime = time.Now()
t.lastRuntime = response.Before

if len(canaries) == 0 {
if len(response.Canaries) == 0 {
return nil
}

logger.Tracef("fetched %d canaries from upstream", len(canaries))
logger.Tracef("fetched %d canaries from upstream", len(response.Canaries))

return db.Gorm.Omit("agent_id").Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "id"}},
UpdateAll: true,
}).Create(&canaries).Error
}).Create(&response.Canaries).Error
}

type UpstreamPushJob struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var FuncScheduler = cron.New()

const (
PullCanaryFromUpstreamSchedule = "@every 2m"
PullCanaryFromUpstreamSchedule = "@every 30s"
PushCanaryToUpstreamSchedule = "@every 10s"
ReconcileCanaryToUpstreamSchedule = "@every 3h"
SyncCanaryJobsSchedule = "@every 2m"
Expand Down

0 comments on commit 5c72f6e

Please sign in to comment.