Skip to content

Commit

Permalink
feat: add healthcheck path to app manifest
Browse files Browse the repository at this point in the history
Closes #597.
  • Loading branch information
SoManyHs committed Mar 13, 2020
1 parent ae84b9c commit 454b596
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
5 changes: 5 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/lb_fargate_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
LBFargateParamContainerImageKey = "ContainerImage"
LBFargateParamContainerPortKey = "ContainerPort"
LBFargateRulePathKey = "RulePath"
LBFargateHealthCheckPathKey = "HealthCheckPath"
LBFargateTaskCPUKey = "TaskCPU"
LBFargateTaskMemoryKey = "TaskMemory"
LBFargateTaskCountKey = "TaskCount"
Expand Down Expand Up @@ -141,6 +142,10 @@ func (c *LBFargateStackConfig) Parameters() []*cloudformation.Parameter {
ParameterKey: aws.String(LBFargateRulePathKey),
ParameterValue: aws.String(templateParams.App.Path),
},
{
ParameterKey: aws.String(LBFargateHealthCheckPathKey),
ParameterValue: aws.String(templateParams.App.HealthCheckPath),
},
{
ParameterKey: aws.String(LBFargateTaskCPUKey),
ParameterValue: aws.String(strconv.Itoa(templateParams.App.CPU)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ func TestLBFargateStackConfig_Parameters(t *testing.T) {
ParameterKey: aws.String(LBFargateRulePathKey),
ParameterValue: aws.String("frontend"),
},
{
ParameterKey: aws.String(LBFargateHealthCheckPathKey),
ParameterValue: aws.String("/"),
},
{
ParameterKey: aws.String(LBFargateTaskCPUKey),
ParameterValue: aws.String("256"),
Expand Down
12 changes: 10 additions & 2 deletions internal/pkg/manifest/lb_fargate_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type LogsConfig struct {
// RoutingRule holds the path to route requests to the service.
type RoutingRule struct {
Path string `yaml:"path"`
HealthCheckPath string `yaml:"healthcheck"`
}

// AutoScalingConfig is the configuration to scale the service with target tracking scaling policies.
Expand All @@ -74,8 +75,10 @@ type LBFargateManifestProps struct {
Port uint16
}

// NewLoadBalancedFargateManifest creates a new public load balanced web service with an exposed port of 80, receives
// all the requests from the load balancer and has a single task with minimal CPU and Memory thresholds.
// NewLoadBalancedFargateManifest creates a new public load balanced web
// service, receives all the requests from the load balancer, has a single task
// with minimal CPU and Memory thresholds, and sets the default health check
// path to "/"
func NewLoadBalancedFargateManifest(input *LBFargateManifestProps) *LBFargateManifest {
return &LBFargateManifest{
AppManifest: AppManifest{
Expand All @@ -91,6 +94,7 @@ func NewLoadBalancedFargateManifest(input *LBFargateManifestProps) *LBFargateMan
LBFargateConfig: LBFargateConfig{
RoutingRule: RoutingRule{
Path: input.Path,
HealthCheckPath: "/",
},
ContainersConfig: ContainersConfig{
CPU: 256,
Expand Down Expand Up @@ -146,6 +150,7 @@ func (m *LBFargateManifest) EnvConf(envName string) LBFargateConfig {
conf := LBFargateConfig{
RoutingRule: RoutingRule{
Path: m.Path,
HealthCheckPath: m.HealthCheckPath,
},
ContainersConfig: ContainersConfig{
CPU: m.CPU,
Expand All @@ -162,6 +167,9 @@ func (m *LBFargateManifest) EnvConf(envName string) LBFargateConfig {
if target.RoutingRule.Path != "" {
conf.RoutingRule.Path = target.RoutingRule.Path
}
if target.RoutingRule.HealthCheckPath != "" {
conf.RoutingRule.HealthCheckPath = target.RoutingRule.HealthCheckPath
}
if target.CPU != 0 {
conf.CPU = target.CPU
}
Expand Down
35 changes: 28 additions & 7 deletions internal/pkg/manifest/lb_fargate_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func TestLBFargateManifest_EnvConf(t *testing.T) {
}{
"with no existing environments": {
inDefaultConfig: LBFargateConfig{
RoutingRule: RoutingRule{Path: "/awards/*"},
RoutingRule: RoutingRule{
Path: "/awards/*",
HealthCheckPath: "/",
},
ContainersConfig: ContainersConfig{
CPU: 1024,
Memory: 1024,
Expand All @@ -80,7 +83,10 @@ func TestLBFargateManifest_EnvConf(t *testing.T) {
inEnvNameToQuery: "prod-iad",

wantedConfig: LBFargateConfig{
RoutingRule: RoutingRule{Path: "/awards/*"},
RoutingRule: RoutingRule{
Path: "/awards/*",
HealthCheckPath: "/",
},
ContainersConfig: ContainersConfig{
CPU: 1024,
Memory: 1024,
Expand All @@ -90,7 +96,10 @@ func TestLBFargateManifest_EnvConf(t *testing.T) {
},
"with partial overrides": {
inDefaultConfig: LBFargateConfig{
RoutingRule: RoutingRule{Path: "/awards/*"},
RoutingRule: RoutingRule{
Path: "/awards/*",
HealthCheckPath: "/",
},
ContainersConfig: ContainersConfig{
CPU: 1024,
Memory: 1024,
Expand Down Expand Up @@ -127,7 +136,10 @@ func TestLBFargateManifest_EnvConf(t *testing.T) {
},

wantedConfig: LBFargateConfig{
RoutingRule: RoutingRule{Path: "/awards/*"},
RoutingRule: RoutingRule{
Path: "/awards/*",
HealthCheckPath: "/",
},
ContainersConfig: ContainersConfig{
CPU: 2046,
Memory: 1024,
Expand All @@ -150,7 +162,10 @@ func TestLBFargateManifest_EnvConf(t *testing.T) {
},
"with complete override": {
inDefaultConfig: LBFargateConfig{
RoutingRule: RoutingRule{Path: "/awards/*"},
RoutingRule: RoutingRule{
Path: "/awards/*",
HealthCheckPath: "/",
},
ContainersConfig: ContainersConfig{
CPU: 1024,
Memory: 1024,
Expand All @@ -166,7 +181,10 @@ func TestLBFargateManifest_EnvConf(t *testing.T) {
inEnvNameToQuery: "prod-iad",
inEnvOverride: map[string]LBFargateConfig{
"prod-iad": {
RoutingRule: RoutingRule{Path: "/frontend*"},
RoutingRule: RoutingRule{
Path: "/frontend*",
HealthCheckPath: "/healthcheck",
},
ContainersConfig: ContainersConfig{
CPU: 2046,
Memory: 2046,
Expand All @@ -190,7 +208,10 @@ func TestLBFargateManifest_EnvConf(t *testing.T) {
},

wantedConfig: LBFargateConfig{
RoutingRule: RoutingRule{Path: "/frontend*"},
RoutingRule: RoutingRule{
Path: "/frontend*",
HealthCheckPath: "/healthcheck",
},
ContainersConfig: ContainersConfig{
CPU: 2046,
Memory: 2046,
Expand Down
4 changes: 4 additions & 0 deletions templates/lb-fargate-service/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Parameters:
Description: 'URL of the addons nested stack template within the S3 bucket.'
Type: String
Default: ""
HealthCheckPath:
Type: String
Default: '{{.App.HealthCheckPath}}'
Conditions:
HTTPLoadBalancer:
!Not
Expand Down Expand Up @@ -275,6 +278,7 @@ Resources:
HealthCheckIntervalSeconds: 10 # Default is 30.
HealthyThresholdCount: 2 # Default is 5.
HealthCheckTimeoutSeconds: 5
HealthCheckPath: !Ref HealthCheckPath
Port: !Ref ContainerPort
Protocol: HTTP
TargetGroupAttributes:
Expand Down
2 changes: 2 additions & 0 deletions templates/lb-fargate-service/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ image:
http:
# Requests to this path will be forwarded to your service.
path: '{{.Path}}'
# # You can specify a custom health check path. The default is "/"
# healthcheck: '{{.HealthCheckPath}}'

# Number of CPU units for the task.
cpu: {{.CPU}}
Expand Down
3 changes: 2 additions & 1 deletion templates/lb-fargate-service/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"TaskCount": "{{.App.Count}}",
"HTTPSEnabled": "{{.HTTPSEnabled}}",
"LogRetention": "30",
"AddonsTemplateURL": ""
"AddonsTemplateURL": "",
"HealthCheckPath": "{{.App.HealthCheckPath}}"
},
"Tags": {
"ecs-project": "{{.Env.Project}}",
Expand Down

0 comments on commit 454b596

Please sign in to comment.