Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NET11250]Added fix for health check update for consul-dataplane #267

Merged
merged 64 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
ff083c5
Added Fix health check update for consul-dataplane
abhishek-hashicorp Dec 9, 2024
4964983
Fix lint
abhishek-hashicorp Dec 9, 2024
5f4633c
Update command_test.go
abhishek-hashicorp Dec 9, 2024
a03cac7
Update command_test.go
abhishek-hashicorp Dec 9, 2024
648d243
Fix tests
abhishek-hashicorp Dec 9, 2024
832a6e8
Fix tests
abhishek-hashicorp Dec 9, 2024
7de0102
Fix tests
abhishek-hashicorp Dec 9, 2024
0535494
fix tests
abhishek-hashicorp Dec 9, 2024
cc1d005
Fix tests for missing container reappearing
abhishek-hashicorp Dec 9, 2024
77a6e41
Update command_test.go
abhishek-hashicorp Dec 9, 2024
8712ba5
Update command_test.go
abhishek-hashicorp Dec 9, 2024
3831a8a
Update command_test.go
abhishek-hashicorp Dec 9, 2024
5f4786f
Update command_test.go
abhishek-hashicorp Dec 9, 2024
0e1efb9
Update command_test.go
abhishek-hashicorp Dec 9, 2024
ada2b3b
Update command_test.go
abhishek-hashicorp Dec 9, 2024
6f4c09a
Update command_test.go
abhishek-hashicorp Dec 9, 2024
32fa3dc
Update command_test.go
abhishek-hashicorp Dec 9, 2024
578329a
Update command_test.go
abhishek-hashicorp Dec 9, 2024
7f4b305
Update command_test.go
abhishek-hashicorp Dec 9, 2024
e8139f2
Update command_test.go
abhishek-hashicorp Dec 10, 2024
d8a55ee
Update command_test.go
abhishek-hashicorp Dec 10, 2024
2e718fc
Update command_test.go
abhishek-hashicorp Dec 10, 2024
412c16b
Update command_test.go
abhishek-hashicorp Dec 10, 2024
866725b
Update command_test.go
abhishek-hashicorp Dec 10, 2024
5da9070
Update command_test.go
abhishek-hashicorp Dec 10, 2024
0a15354
Update command_test.go
abhishek-hashicorp Dec 10, 2024
205c152
Update command_test.go
abhishek-hashicorp Dec 10, 2024
d874e93
Update command_test.go
abhishek-hashicorp Dec 10, 2024
02c0e76
Update command_test.go
abhishek-hashicorp Dec 10, 2024
edd914b
Update command_test.go
abhishek-hashicorp Dec 10, 2024
ca66c5a
Update command_test.go
abhishek-hashicorp Dec 10, 2024
dacfc8e
Update command_test.go
abhishek-hashicorp Dec 10, 2024
deddcdb
Update command_test.go
abhishek-hashicorp Dec 10, 2024
abf7975
Update command_test.go
abhishek-hashicorp Dec 10, 2024
1cccdbf
Update command_test.go
abhishek-hashicorp Dec 10, 2024
6852877
Update command_test.go
abhishek-hashicorp Dec 10, 2024
12a1b23
Update command_test.go
abhishek-hashicorp Dec 10, 2024
aacd44c
Update command_test.go
abhishek-hashicorp Dec 10, 2024
e7a137d
Update command_test.go
abhishek-hashicorp Dec 10, 2024
aad3768
Update command_test.go
abhishek-hashicorp Dec 10, 2024
98c5269
Merge branch 'main' into abhishekhashicorp/fix-health-check
abhishek-hashicorp Dec 10, 2024
1f5eb36
Update command_test.go
abhishek-hashicorp Dec 10, 2024
88bd97d
Update command_test.go
abhishek-hashicorp Dec 10, 2024
f3ceb6c
Update command_test.go
abhishek-hashicorp Dec 10, 2024
4b70a0e
Update command_test.go
abhishek-hashicorp Dec 10, 2024
438db7b
Update command_test.go
abhishek-hashicorp Dec 10, 2024
f57f375
Update command_test.go
abhishek-hashicorp Dec 10, 2024
8f547ff
Update command_test.go
abhishek-hashicorp Dec 10, 2024
dca26c1
Update command_test.go
abhishek-hashicorp Dec 10, 2024
ebd942e
Update command_test.go
abhishek-hashicorp Dec 10, 2024
95ce970
Update command_test.go
abhishek-hashicorp Dec 10, 2024
f7aa814
Update command_test.go
abhishek-hashicorp Dec 10, 2024
871e9c1
Update command_test.go
abhishek-hashicorp Dec 10, 2024
e07091e
Update command_test.go
abhishek-hashicorp Dec 10, 2024
bc42a85
Update command_test.go
abhishek-hashicorp Dec 10, 2024
41d02ac
Removed comments
abhishek-hashicorp Dec 10, 2024
2e47b1e
Update command_test.go
abhishek-hashicorp Dec 10, 2024
55a6de5
Update command_test.go
abhishek-hashicorp Dec 10, 2024
d58260e
Update command_test.go
abhishek-hashicorp Dec 10, 2024
4066c86
Update CHANGELOG.md
abhishek-hashicorp Dec 10, 2024
1b369c1
Address review comment
abhishek-hashicorp Jan 9, 2025
dc2695e
Revert suggested changes
abhishek-hashicorp Jan 9, 2025
36dd1d9
Update checks.go
abhishek-hashicorp Jan 9, 2025
afe3540
Remove redundant check and typo correction
abhishek-hashicorp Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Unreleased
BUG FIXES
* Fix the issue where the service was accepting traffic even though it wasn't healthy. This fix updates the health check status for `consul-dataplane` container and takes into account the health of the service container as well.

IMPROVEMENTS
* Bump Go version to `1.22.7`
Expand Down
34 changes: 29 additions & 5 deletions subcommand/health-sync/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func (c *Command) syncChecks(consulClient *api.Client,
}

serviceName := c.constructServiceName(taskMeta.Family)

containersToSync, missingContainers := findContainersToSync(parsedContainerNames, taskMeta)

// Mark the Consul health status as critical for missing containers
Expand All @@ -131,20 +130,20 @@ func (c *Command) syncChecks(consulClient *api.Client,
}
}

parsedContainers := make(map[string]string)
// iterate over parse
for _, container := range containersToSync {
c.log.Debug("updating Consul check from ECS container health",
"name", container.Name,
"status", container.Health.Status,
"statusSince", container.Health.StatusSince,
"exitCode", container.Health.ExitCode,
)

parsedContainers[container.Name] = container.Health.Status
previousStatus := currentStatuses[container.Name]
if container.Health.Status != previousStatus {
var err error
if container.Name == config.ConsulDataplaneContainerName {
err = c.handleHealthForDataplaneContainer(consulClient, taskMeta.TaskID(), serviceName, clusterARN, container.Name, container.Health.Status)
} else {
if container.Name != config.ConsulDataplaneContainerName {
checkID := constructCheckID(makeServiceID(serviceName, taskMeta.TaskID()), container.Name)
err = c.updateConsulHealthStatus(consulClient, checkID, clusterARN, container.Health.Status)
}
Expand All @@ -161,8 +160,33 @@ func (c *Command) syncChecks(consulClient *api.Client,
currentStatuses[container.Name] = container.Health.Status
}
}

}
overallDataplaneHealthStatus, ok := parsedContainers[config.ConsulDataplaneContainerName]
// if dataplane container exist and healthy then proceed to checking the other containers health
if ok && overallDataplaneHealthStatus == ecs.HealthStatusHealthy {
//
for _, healthStatus := range parsedContainers {
// as soon as we find any unhealthy container, we can set the dataplane health to unhealthy
if healthStatus != ecs.HealthStatusHealthy {
overallDataplaneHealthStatus = ecs.HealthStatusUnhealthy
break
}
}
} else {
// If no dataplane container or dataplane container is not healthy set overall health to unhealthy
overallDataplaneHealthStatus = ecs.HealthStatusUnhealthy
}

err = c.handleHealthForDataplaneContainer(consulClient, taskMeta.TaskID(), serviceName, clusterARN, config.ConsulDataplaneContainerName, overallDataplaneHealthStatus)
if err != nil {
c.log.Warn("failed to update Consul health status", "err", err)
} else {
c.log.Info("container health check updated in Consul",
"name", config.ConsulDataplaneContainerName,
"status", overallDataplaneHealthStatus,
)
}
return currentStatuses
}

Expand Down
36 changes: 31 additions & 5 deletions subcommand/health-sync/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestRun(t *testing.T) {
healthSyncContainers map[string]healthSyncContainerMetaData
missingDataplaneContainer bool
shouldMissingContainersReappear bool
expectedDataplaneHealthStatus string
}{
"no additional health sync containers": {},
"one healthy health sync container": {
Expand Down Expand Up @@ -132,6 +133,7 @@ func TestRun(t *testing.T) {
status: ecs.HealthStatusUnhealthy,
},
},
expectedDataplaneHealthStatus: api.HealthCritical,
},
"one healthy and one missing health sync containers": {
healthSyncContainers: map[string]healthSyncContainerMetaData{
Expand All @@ -143,7 +145,8 @@ func TestRun(t *testing.T) {
status: ecs.HealthStatusUnhealthy,
},
},
consulLogin: consulLoginCfg,
expectedDataplaneHealthStatus: api.HealthPassing,
consulLogin: consulLoginCfg,
},
"two unhealthy health sync containers": {
healthSyncContainers: map[string]healthSyncContainerMetaData{
Expand All @@ -154,6 +157,7 @@ func TestRun(t *testing.T) {
status: ecs.HealthStatusUnhealthy,
},
},
expectedDataplaneHealthStatus: api.HealthCritical,
},
"missing dataplane container": {
missingDataplaneContainer: true,
Expand Down Expand Up @@ -200,6 +204,7 @@ func TestRun(t *testing.T) {
status: ecs.HealthStatusUnhealthy,
},
},
expectedDataplaneHealthStatus: api.HealthPassing,
shouldMissingContainersReappear: true,
consulLogin: consulLoginCfg,
},
Expand Down Expand Up @@ -368,6 +373,7 @@ func TestRun(t *testing.T) {

// Align the expectations for checks according to the
// state of health sync containers
markDataplaneContainerUnhealthy := false
for _, expCheck := range expectedSvcChecks {
found := false
for name, hsc := range c.healthSyncContainers {
Expand All @@ -377,21 +383,41 @@ func TestRun(t *testing.T) {
expCheck.Status = api.HealthCritical
} else {
expCheck.Status = ecsHealthToConsulHealth(hsc.status)
// If there are multiple health sync containers and one of them is unhealthy
// then the service check should be critical.
for containerName := range c.healthSyncContainers {
if c.healthSyncContainers[containerName].status == ecs.HealthStatusUnhealthy &&
c.healthSyncContainers[containerName].missing == false {
expCheck.Status = api.HealthCritical
markDataplaneContainerUnhealthy = true
break
}
}

}
found = true
break
}
}

if !found {
if c.missingDataplaneContainer {
expCheck.Status = api.HealthCritical
if c.expectedDataplaneHealthStatus != "" {
expCheck.Status = c.expectedDataplaneHealthStatus
} else {
expCheck.Status = api.HealthPassing
if c.missingDataplaneContainer || markDataplaneContainerUnhealthy {
expCheck.Status = api.HealthCritical
} else if len(c.healthSyncContainers) == 0 || !markDataplaneContainerUnhealthy {
expCheck.Status = api.HealthPassing
}
}
}
}
expectedProxyCheck.Status = api.HealthPassing
if markDataplaneContainerUnhealthy {
expectedProxyCheck.Status = api.HealthCritical
} else {
expectedProxyCheck.Status = api.HealthPassing
}

if c.missingDataplaneContainer {
expectedProxyCheck.Status = api.HealthCritical
}
Expand Down
Loading