Skip to content

Commit

Permalink
fix: set global http client for checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lvlcn-t committed Dec 6, 2023
1 parent acd489b commit 650368c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/sparrow/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package sparrow
import (
"context"
"fmt"
"net/http"

"github.com/caas-team/sparrow/internal/logger"
"github.com/caas-team/sparrow/pkg/api"
Expand All @@ -36,6 +37,7 @@ type Sparrow struct {
db db.DB
// the existing checks
checks map[string]checks.Check
client *http.Client

resultFanIn map[string]chan checks.Result
cResult chan checks.ResultDTO
Expand All @@ -51,14 +53,15 @@ type Sparrow struct {
// New creates a new sparrow from a given configfile
func New(cfg *config.Config) *Sparrow {
sparrow := &Sparrow{
router: chi.NewRouter(),
routingTree: api.NewRoutingTree(),
db: db.NewInMemory(),
checks: make(map[string]checks.Check),
cResult: make(chan checks.ResultDTO, 1),
client: &http.Client{},
resultFanIn: make(map[string]chan checks.Result),
cResult: make(chan checks.ResultDTO, 1),
cfg: cfg,
cCfgChecks: make(chan map[string]any, 1),
db: db.NewInMemory(),
routingTree: api.NewRoutingTree(),
router: chi.NewRouter(),
}

sparrow.loader = config.NewLoader(cfg, sparrow.cCfgChecks)
Expand Down Expand Up @@ -125,6 +128,7 @@ func (s *Sparrow) ReconcileChecks(ctx context.Context) {
checkChan := make(chan checks.Result, 1)
s.resultFanIn[name] = checkChan

check.SetClient(s.client)
err := check.SetConfig(ctx, checkCfg)
if err != nil {
log.ErrorContext(ctx, "Failed to set config for check", "name", name, "error", err)
Expand All @@ -137,6 +141,7 @@ func (s *Sparrow) ReconcileChecks(ctx context.Context) {
continue
}
check.RegisterHandler(ctx, s.routingTree)

go func() {
err := check.Run(ctx)
if err != nil {
Expand Down

0 comments on commit 650368c

Please sign in to comment.