Skip to content

Commit

Permalink
fix: properly validate zone health check config
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont committed Oct 9, 2023
1 parent 0e154d4 commit 8693e31
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
31 changes: 22 additions & 9 deletions pkg/config/multizone/kds.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ type KdsServerConfig struct {
ZoneHealthCheck ZoneHealthCheckConfig `json:"zoneHealthCheck"`
}

type ZoneHealthCheckConfig struct {
// PollInterval is the interval between the CP checking ZoneInsight for
// health check pings
PollInterval config_types.Duration `json:"pollInterval"`
// Timeout is the time after the last health check that a zone counts as
// no longer online
Timeout config_types.Duration `json:"timeout"`
}

var _ config.Config = &KdsServerConfig{}

func (c *KdsServerConfig) Sanitize() {
Expand Down Expand Up @@ -81,6 +72,9 @@ func (c *KdsServerConfig) Validate() error {
if _, err := config_types.TLSCiphers(c.TlsCipherSuites); err != nil {
errs = multierr.Append(errs, errors.New(".TlsCipherSuites"+err.Error()))
}
if err := c.ZoneHealthCheck.Validate(); err != nil {
errs = multierr.Append(errs, errors.Wrap(err, "invalid zoneHealthCheck config"))
}
return errs
}

Expand Down Expand Up @@ -109,3 +103,22 @@ func (k KdsClientConfig) Sanitize() {
func (k KdsClientConfig) Validate() error {
return nil
}

type ZoneHealthCheckConfig struct {
// PollInterval is the interval between the CP checking ZoneInsight for
// health check pings
PollInterval config_types.Duration `json:"pollInterval" envconfig:"kuma_multizone_global_kds_zone_health_check_poll_interval"`
// Timeout is the time after the last health check that a zone counts as
// no longer online
Timeout config_types.Duration `json:"timeout" envconfig:"kuma_multizone_global_kds_zone_health_check_timeout"`
}

func (c ZoneHealthCheckConfig) Sanitize() {
}

func (c ZoneHealthCheckConfig) Validate() error {
if (c.Timeout.Duration > 0) != (c.PollInterval.Duration > 0) {
return errors.New("timeout and pollInterval must both be either set or unset")
}
return nil
}
20 changes: 12 additions & 8 deletions pkg/kds/global/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/go-logr/logr"
"github.com/pkg/errors"
Expand Down Expand Up @@ -154,14 +155,17 @@ func Setup(rt runtime.Runtime) error {
for _, filter := range rt.KDSContext().GlobalServerFiltersV2 {
streamInterceptors = append(streamInterceptors, filter)
}
zwLog := kdsGlobalLog.WithName("zone-watch")
if err := rt.Add(component.NewResilientComponent(zwLog, mux.NewZoneWatch(
zwLog,
*rt.Config().Multizone.Global.KDS,
rt.EventBus(),
rt.ReadOnlyResourceManager(),
))); err != nil {
return err

if rt.Config().Multizone.Global.KDS.ZoneHealthCheck.Timeout.Duration > time.Duration(0) {
zwLog := kdsGlobalLog.WithName("zone-watch")
if err := rt.Add(component.NewResilientComponent(zwLog, mux.NewZoneWatch(
zwLog,
*rt.Config().Multizone.Global.KDS,
rt.EventBus(),
rt.ReadOnlyResourceManager(),
))); err != nil {
return err
}
}
return rt.Add(component.NewResilientComponent(kdsGlobalLog.WithName("kds-mux-client"), mux.NewServer(
onSessionStarted,
Expand Down

0 comments on commit 8693e31

Please sign in to comment.