Skip to content

Commit

Permalink
adding config option for Healthy threshold
Browse files Browse the repository at this point in the history
Healthy threshold: The number of consecutive health checks successes required before considering an unhealthy target healthy

This configuration is required since the default of "5" time the interval which is minimum of sum of 30s that is too long delay in our configurations

Signed-off-by: Samuel Lang <[email protected]>
  • Loading branch information
universam1 committed Nov 18, 2021
1 parent 90034a9 commit 2be8ffb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions aws/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Adapter struct {
healthCheckPort uint
healthCheckInterval time.Duration
healthCheckTimeout time.Duration
healthyThresholdCount uint
targetPort uint
albHTTPTargetPort uint
nlbHTTPTargetPort uint
Expand Down Expand Up @@ -91,6 +92,7 @@ const (
DefaultTargetPort = 9999
DefaultHealthCheckInterval = 10 * time.Second
DefaultHealthCheckTimeout = 5 * time.Second
DefaultHealthyThresholdCount = 5
DefaultCertificateUpdateInterval = 30 * time.Minute
DefaultCreationTimeout = 5 * time.Minute
DefaultIdleConnectionTimeout = 1 * time.Minute
Expand Down Expand Up @@ -248,6 +250,13 @@ func (a *Adapter) WithHealthCheckPort(port uint) *Adapter {
return a
}

// WithHealthyThresholdCount returns the receiver adapter after changing the healthy threshold count that will be used by
// the resources created by the adapter
func (a *Adapter) WithHealthyThresholdCount(count uint) *Adapter {
a.healthyThresholdCount = count
return a
}

// WithTargetPort returns the receiver adapter after changing the target port that will be used by
// the resources created by the adapter
func (a *Adapter) WithTargetPort(port uint) *Adapter {
Expand Down Expand Up @@ -611,6 +620,7 @@ func (a *Adapter) CreateStack(certificateARNs []string, scheme, securityGroup, o
interval: a.healthCheckInterval,
timeout: a.healthCheckTimeout,
},
healthyThresholdCount: a.healthyThresholdCount,
targetPort: a.targetPort,
targetHTTPS: a.targetHTTPS,
httpDisabled: a.httpDisabled(loadBalancerType),
Expand Down Expand Up @@ -663,6 +673,7 @@ func (a *Adapter) UpdateStack(stackName string, certificateARNs map[string]time.
interval: a.healthCheckInterval,
timeout: a.healthCheckTimeout,
},
healthyThresholdCount: a.healthyThresholdCount,
targetPort: a.targetPort,
targetHTTPS: a.targetHTTPS,
httpDisabled: a.httpDisabled(loadBalancerType),
Expand Down
8 changes: 8 additions & 0 deletions aws/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,11 @@ func TestWithTargetHTTPS(t *testing.T) {
require.Equal(t, true, b.targetHTTPS)
})
}

func TestWithHealthyThresholdCount(t *testing.T) {
t.Run("WithHealthyThresholdCount sets the healthyThresholdCount property", func(t *testing.T) {
a := Adapter{}
b := a.WithHealthyThresholdCount(2)
require.Equal(t, uint(2), b.healthyThresholdCount)
})
}
1 change: 1 addition & 0 deletions aws/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ type stackSpec struct {
clusterID string
vpcID string
healthCheck *healthCheck
healthyThresholdCount uint
targetPort uint
targetHTTPS bool
httpDisabled bool
Expand Down
1 change: 1 addition & 0 deletions aws/cf_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func newTargetGroup(spec *stackSpec, targetPortParameter string) *cloudformation
HealthCheckPath: cloudformation.Ref(parameterTargetGroupHealthCheckPathParameter).String(),
HealthCheckPort: cloudformation.Ref(parameterTargetGroupHealthCheckPortParameter).String(),
HealthCheckProtocol: cloudformation.String(healthCheckProtocol),
HealthyThresholdCount: cloudformation.Integer(int64(spec.healthyThresholdCount)),
Port: cloudformation.Ref(targetPortParameter).Integer(),
Protocol: cloudformation.String(protocol),
VPCID: cloudformation.Ref(parameterTargetGroupVPCIDParameter).String(),
Expand Down
11 changes: 11 additions & 0 deletions aws/cf_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,17 @@ func TestGenerateTemplate(t *testing.T) {
validateTargetGroupOutput(t, template, "TG", "TargetGroupARN")
},
},
{
name: "Defines the HealthyThresholdCount if defined",
spec: &stackSpec{
loadbalancerType: LoadBalancerTypeApplication,
healthyThresholdCount: 2,
},
validate: func(t *testing.T, template *cloudformation.Template) {
tg := template.Resources["TG"].Properties.(*cloudformation.ElasticLoadBalancingV2TargetGroup)
require.Equal(t, cloudformation.Integer(2), tg.HealthyThresholdCount)
},
},
} {
t.Run(test.name, func(t *testing.T) {
generated, err := generateTemplate(test.spec)
Expand Down
4 changes: 4 additions & 0 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
healthCheckPort uint
healthCheckInterval time.Duration
healthCheckTimeout time.Duration
healthyThresholdCount uint
targetPort uint
albHTTPTargetPort uint
nlbHTTPTargetPort uint
Expand Down Expand Up @@ -221,6 +222,8 @@ func loadSettings() error {
Default(aws.DefaultHealthCheckInterval.String()).DurationVar(&healthCheckInterval)
kingpin.Flag("health-check-timeout", "sets the health check timeout for the created target groups. The flag accepts a value acceptable to time.ParseDuration").
Default(aws.DefaultHealthCheckTimeout.String()).DurationVar(&healthCheckTimeout)
kingpin.Flag("healthy-threshold-count", "The number of consecutive health checks successes required before considering an unhealthy target healthy").
Default(strconv.FormatUint(aws.DefaultHealthyThresholdCount, 10)).UintVar(&healthyThresholdCount)
kingpin.Flag("idle-connection-timeout", "sets the idle connection timeout of all ALBs. The flag accepts a value acceptable to time.ParseDuration and are between 1s and 4000s.").
Default(aws.DefaultIdleConnectionTimeout.String()).DurationVar(&idleConnectionTimeout)
kingpin.Flag("deregistration-delay-timeout", "sets the deregistration delay timeout of all target groups. The flag accepts a value acceptable to time.ParseDuration that is between 1s and 3600s.").
Expand Down Expand Up @@ -370,6 +373,7 @@ func main() {
WithHealthCheckPort(healthCheckPort).
WithHealthCheckInterval(healthCheckInterval).
WithHealthCheckTimeout(healthCheckTimeout).
WithHealthyThresholdCount(healthyThresholdCount).
WithTargetPort(targetPort).
WithALBHTTPTargetPort(albHTTPTargetPort).
WithNLBHTTPTargetPort(nlbHTTPTargetPort).
Expand Down

0 comments on commit 2be8ffb

Please sign in to comment.