-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
health-checks: zero route availability improvements (#5111)
- Loading branch information
Showing
5 changed files
with
168 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package healthcheck | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff/v4" | ||
) | ||
|
||
const ( | ||
runHealthChecksMaxInterval = time.Minute * 30 | ||
runHealthCheckMinInterval = time.Minute | ||
) | ||
|
||
func (c *checker) Scheduler(ctx context.Context) { | ||
bo := backoff.NewExponentialBackOff() | ||
bo.MaxElapsedTime = 0 | ||
bo.MaxInterval = runHealthChecksMaxInterval | ||
bo.InitialInterval = runHealthCheckMinInterval | ||
bo.Reset() | ||
|
||
tm := time.NewTimer(runHealthCheckMinInterval) | ||
defer tm.Stop() | ||
|
||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-tm.C: | ||
} | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-c.forceCheck: | ||
case <-tm.C: | ||
} | ||
|
||
next := runHealthChecksMaxInterval | ||
err := c.CheckRoutes(ctx) | ||
if err != nil { | ||
next = bo.NextBackOff() | ||
} else { | ||
bo.Reset() | ||
} | ||
if !tm.Stop() { | ||
select { | ||
case <-tm.C: | ||
default: | ||
} | ||
} | ||
tm.Reset(next) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package healthcheck | ||
|
||
import ( | ||
"context" | ||
|
||
configpb "github.com/pomerium/pomerium/pkg/grpc/config" | ||
"github.com/pomerium/pomerium/pkg/grpc/databroker" | ||
"github.com/pomerium/pomerium/pkg/health" | ||
"github.com/pomerium/pomerium/pkg/protoutil" | ||
) | ||
|
||
func (c *checker) ConfigSyncer(ctx context.Context) error { | ||
syncer := databroker.NewSyncer("zero-health-check", c, databroker.WithTypeURL(protoutil.GetTypeURL(new(configpb.Config)))) | ||
return syncer.Run(ctx) | ||
} | ||
|
||
func (c *checker) GetConfigs() []*configpb.Config { | ||
configs := c.configs.Load() | ||
if configs == nil { | ||
return nil | ||
} | ||
return configs.([]*configpb.Config) | ||
} | ||
|
||
// ClearRecords implements databroker.Syncer interface | ||
func (c *checker) ClearRecords(_ context.Context) { | ||
c.configs.Store([]*configpb.Config{}) | ||
} | ||
|
||
// UpdateRecords implements databroker.Syncer interface | ||
func (c *checker) UpdateRecords(_ context.Context, _ uint64, records []*databroker.Record) { | ||
if len(records) == 0 { | ||
return | ||
} | ||
|
||
cfgs, err := getConfig(records) | ||
if err != nil { | ||
health.ReportInternalError(health.RoutesReachable, err) | ||
return | ||
} | ||
c.configs.Store(cfgs) | ||
select { | ||
case c.forceCheck <- struct{}{}: | ||
default: | ||
} | ||
} | ||
|
||
// GetDataBrokerServiceClient implements databroker.Syncer interface | ||
func (c *checker) GetDataBrokerServiceClient() databroker.DataBrokerServiceClient { | ||
return c.databrokerClient | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters