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

probes unhealthy only if threshold exeeded #315

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 7 additions & 9 deletions internal/controller/dnsrecord_healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,18 @@ func removeUnhealthyEndpoints(specEndpoints []*endpoint.Endpoint, dnsRecord *v1a

var haveHealthyProbes bool
for _, probe := range probes.Items {
// if the probe is healthy or unknown, continue to the next probe
// if the probe is healthy, continue to the next probe
if probe.Status.Healthy != nil && *probe.Status.Healthy {
haveHealthyProbes = true
continue
}

// if we exceeded a threshold or we haven't probed yet
if probe.Status.ConsecutiveFailures >= dnsRecord.Spec.HealthCheck.FailureThreshold || probe.Status.Healthy == nil {
//delete bad endpoint from all endpoints targets
tree.RemoveNode(&common.DNSTreeNode{
Name: probe.Spec.Address,
})
unhealthyAddresses = append(unhealthyAddresses, probe.Spec.Address)
}
// if unhealthy or we haven't probed yet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok good so assume not healthy until proven is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. Unless heathy: true we consider it unhealthy

//delete bad endpoint from all endpoints targets
tree.RemoveNode(&common.DNSTreeNode{
Name: probe.Spec.Address,
})
unhealthyAddresses = append(unhealthyAddresses, probe.Spec.Address)

}

Expand Down
3 changes: 0 additions & 3 deletions internal/controller/dnsrecord_healthchecks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ var _ = Describe("DNSRecordReconciler_HealthChecks", func() {
if probe.Spec.Address == "172.32.200.1" {
probe.Status.Healthy = ptr.To(false)
probe.Status.LastCheckedAt = metav1.Now()
probe.Status.ConsecutiveFailures = dnsRecord.Spec.HealthCheck.FailureThreshold + 1
g.Expect(k8sClient.Status().Update(ctx, &probe)).To(Succeed())
updated = true
}
Expand Down Expand Up @@ -499,7 +498,6 @@ var _ = Describe("DNSRecordReconciler_HealthChecks", func() {
if probe.Spec.Address == "172.32.200.2" {
probe.Status.Healthy = ptr.To(false)
probe.Status.LastCheckedAt = metav1.Now()
probe.Status.ConsecutiveFailures = dnsRecord.Spec.HealthCheck.FailureThreshold + 1
g.Expect(k8sClient.Status().Update(ctx, &probe)).To(Succeed())
updated = true
}
Expand Down Expand Up @@ -585,7 +583,6 @@ var _ = Describe("DNSRecordReconciler_HealthChecks", func() {
if probe.Spec.Address == "172.32.200.1" {
probe.Status.Healthy = ptr.To(false)
probe.Status.LastCheckedAt = metav1.Now()
probe.Status.ConsecutiveFailures = dnsRecord.Spec.HealthCheck.FailureThreshold + 1
g.Expect(k8sClient.Status().Update(ctx, &probe)).To(Succeed())
updated = true
}
Expand Down
5 changes: 4 additions & 1 deletion internal/probes/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,14 @@ func (w *Probe) Start(clientctx context.Context, k8sClient client.Client, probe
freshProbe.Status.ObservedGeneration = freshProbe.Generation
if !probeResult.Healthy {
freshProbe.Status.ConsecutiveFailures++
if freshProbe.Status.ConsecutiveFailures > freshProbe.Spec.FailureThreshold {
freshProbe.Status.Healthy = &probeResult.Healthy
}
} else {
freshProbe.Status.ConsecutiveFailures = 0
freshProbe.Status.Healthy = &probeResult.Healthy
}
logger.V(1).Info("health: execution complete ", "result", probeResult, "checked at", probeResult.CheckedAt.String(), "previoud check at ", probeResult.PreviousCheck)
freshProbe.Status.Healthy = &probeResult.Healthy
freshProbe.Status.LastCheckedAt = probeResult.CheckedAt
freshProbe.Status.Reason = probeResult.Reason
freshProbe.Status.Status = probeResult.Status
Expand Down
Loading