Skip to content

Commit

Permalink
chore: fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Dec 20, 2023
1 parent a031985 commit 336d60a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
11 changes: 5 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ var Root = &cobra.Command{
}

var (
httpPort = 8080
publicEndpoint = "http://localhost:8080"
pushServers, pullServers []string
sharedLibrary []string
exposeEnv bool
logPass, logFail bool
httpPort = 8080
publicEndpoint = "http://localhost:8080"
sharedLibrary []string
exposeEnv bool
logPass, logFail bool

otelcollectorURL string
otelServiceName string
Expand Down
1 change: 0 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func setup() {
if err := duty.UpdatePropertiesFromFile(apicontext.DefaultContext, propertiesFile); err != nil {
logger.Fatalf("Error setting properties in database: %v", err)
}

}

func postgrestResponseModifier(r *http.Response) error {
Expand Down
4 changes: 0 additions & 4 deletions pkg/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
embeddedpostgres "github.com/fergusstrange/embedded-postgres"
"github.com/flanksource/commons/logger"
"github.com/flanksource/duty"
dutyContext "github.com/flanksource/duty/context"
"github.com/flanksource/duty/migrate"
"github.com/jackc/pgx/v5/pgxpool"
"gorm.io/gorm"
Expand All @@ -26,7 +25,6 @@ var RunMigrations bool
var DBMetrics bool
var PostgresServer *embeddedpostgres.EmbeddedPostgres
var HTTPEndpoint = "http://localhost:8080/db"
var defaultCtx dutyContext.Context

func Start(ctx context.Context) error {
if err := Init(); err != nil {
Expand Down Expand Up @@ -104,8 +102,6 @@ func Init() error {
return err
}

defaultCtx = dutyContext.Context{}.WithDB(Gorm, Pool)

if DBMetrics {
go func() {
if err := Gorm.Use(prometheus.New(prometheus.Config{
Expand Down
16 changes: 8 additions & 8 deletions pkg/jobs/canary/sync_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var PullUpstreamCanaries = job.Job{
Singleton: true,
Schedule: "@every 10m",
Fn: func(ctx job.JobRuntime) error {
err, count := pull(ctx, UpstreamConf)
count, err := pull(ctx, UpstreamConf)
ctx.History.SuccessCount = count
return err
},
Expand All @@ -71,36 +71,36 @@ type CanaryPullResponse struct {
Canaries []models.Canary `json:"canaries,omitempty"`
}

func pull(ctx gocontext.Context, config upstream.UpstreamConfig) (error, int) {
func pull(ctx gocontext.Context, config upstream.UpstreamConfig) (int, error) {
logger.Tracef("pulling canaries from upstream since: %v", lastRuntime)

client := upstream.NewUpstreamClient(config)
req := client.Client.R(ctx).QueryParam("since", lastRuntime.Format(time.RFC3339))
resp, err := req.Get(fmt.Sprintf("canary/pull/%s", config.AgentName))
if err != nil {
return fmt.Errorf("error making request: %w", err), 0
return 0, fmt.Errorf("error making request: %w", err)
}
defer resp.Body.Close()

if !resp.IsOK() {
return fmt.Errorf("upstream responded with status: %s", resp.Status), 0
return 0, fmt.Errorf("upstream responded with status: %s", resp.Status)
}

var response CanaryPullResponse
if err := resp.Into(&response); err != nil {
return fmt.Errorf("error decoding response: %w", err), 0
return 0, fmt.Errorf("error decoding response: %w", err)
}

lastRuntime = response.Before

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

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

var UpstreamJobs = []job.Job{
Expand Down
4 changes: 1 addition & 3 deletions pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
v1 "github.com/flanksource/canary-checker/api/v1"

"github.com/flanksource/canary-checker/pkg/db"
"github.com/flanksource/canary-checker/pkg/jobs/canary"
canaryJobs "github.com/flanksource/canary-checker/pkg/jobs/canary"
systemJobs "github.com/flanksource/canary-checker/pkg/jobs/system"
"github.com/flanksource/canary-checker/pkg/topology"
Expand Down Expand Up @@ -45,13 +44,12 @@ func Start() {
FuncScheduler.Start()

if canaryJobs.UpstreamConf.Valid() {

// Push checks to upstream in real-time
if err := canaryJobs.StartUpstreamEventQueueConsumer(context.New(nil, nil, db.Gorm, db.Pool, v1.Canary{})); err != nil {
logger.Fatalf("Failed to start upstream event queue consumer: %v", err)
}

for _, job := range canary.UpstreamJobs {
for _, job := range canaryJobs.UpstreamJobs {
job.Context = context.DefaultContext
if err := job.AddToScheduler(FuncScheduler); err != nil {
logger.Errorf(err.Error())
Expand Down

0 comments on commit 336d60a

Please sign in to comment.