Skip to content

Commit

Permalink
chore: remove "caching" of results and simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Clément Nussbaumer <[email protected]>
  • Loading branch information
clementnuss committed Feb 6, 2024
1 parent 7b1edea commit 92b4922
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 43 deletions.
8 changes: 4 additions & 4 deletions internal/kubenurse/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ func (s *Server) aliveHandler() func(w http.ResponseWriter, r *http.Request) {
Neighbourhood []servicecheck.Neighbour `json:"neighbourhood"`
}

// Run checks now
res, haserr := s.checker.Run()
if haserr {
res := s.checker.LastCheckResult
if res == nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

// Add additional data
out := Output{
Result: res,
Result: *res,
Headers: r.Header,
UserAgent: r.UserAgent(),
RequestURI: r.RequestURI,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/kubenurse/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func New(ctx context.Context, c client.Client) (*Server, error) { //nolint:funle
}

// setup checker
chk, err := servicecheck.New(ctx, c, promRegistry, server.allowUnschedulable, 3*time.Second, histogramBuckets)
chk, err := servicecheck.New(ctx, c, promRegistry, server.allowUnschedulable, 1*time.Second, histogramBuckets)
if err != nil {
return nil, err
}
Expand Down
22 changes: 0 additions & 22 deletions internal/servicecheck/cache.go

This file was deleted.

10 changes: 2 additions & 8 deletions internal/servicecheck/servicecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ func (c *Checker) Run() (Result, bool) {
err error
)

// Check if a result is cached and return it
cacheRes := c.retrieveResultFromCache()
if cacheRes != nil {
return *cacheRes, false
}

// Run Checks
res := Result{}

Expand Down Expand Up @@ -134,8 +128,8 @@ func (c *Checker) Run() (Result, bool) {
}
}

// Cache result
c.cacheResult(&res)
// Cache result (used for /alive handler)
c.LastCheckResult = &res

return res, haserr
}
Expand Down
10 changes: 2 additions & 8 deletions internal/servicecheck/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type Checker struct {
// Http Client for https requests
httpClient *http.Client

// cachedResult represents a cached check result
cachedResult *CachedResult
// LastCheckResult represents a cached check result
LastCheckResult *Result

// cacheTTL defines the TTL of how long a cached result is valid
cacheTTL time.Duration
Expand All @@ -67,9 +67,3 @@ type Result struct {

// Check is the signature used by all checks that the checker can execute.
type Check func(ctx context.Context) (string, error)

// CachedResult represents a cached check result that is valid until the expiration.
type CachedResult struct {
result *Result
expiration time.Time
}

0 comments on commit 92b4922

Please sign in to comment.