Skip to content

feat(health-check): send nic-up after connection recovers - #37

Open
ahmad-can wants to merge 3 commits into
canonical:mainfrom
ahmad-can:fix/nic-up-recovery-signal
Open

ahmad-can wants to merge 3 commits into
canonical:mainfrom
ahmad-can:fix/nic-up-recovery-signal

Conversation

@ahmad-can

Copy link
Copy Markdown
Collaborator

Issue

The health check (tcp_health_check.py) sends nic-down to the hypervisor's pre-evacuation-setup-service when it cannot reach the Consul servers. It never reports that the connection came back, so the hypervisor has no signal to recover and nova-compute stays stopped. (LP #2171374)

Solution

The detector now sends nic-up once connectivity returns:

  • nic-up is sent after a nic-down was sent and the check has succeeded monitoring_samples times in a row, so a flapping link doesn't trigger repeated recoveries.
  • The state file tracks failure_count, alert_sent and success_count. It is written atomically and only when the state changes.
  • An error reply from the receiver counts as a failed send, so the alert is retried on the next run.
  • The unix socket has a 3s timeout, so a stuck receiver can't hold the check until Consul kills it at 5s.
  • The script is installed atomically and only when its contents differ.

The receiving side is in snap-openstack-hypervisor: hypervisor PR. Restarting VMs and the false nic-down trigger are out of scope.

Context

Consul runs the check script about every 12s and kills it at a 5s timeout. The script talks to the hypervisor snap over a unix socket (consul-socket plug) with JSON messages, protocol version 1.0, statuses nic-down and nic-up.

During testing the consul-socket plug was connected only once, and a Field default in consul-notify misbehaved. I connected the plug by hand on the nodes. Neither is changed here.

Testing Instructions

  1. Unit tests and lint: tox -e unit-tests (72 tests) and tox -e lint.
  2. Deploy the charm, or copy src/tcp_health_check.py to /var/snap/consul-client_<id>/common/consul/data/ on a compute node. The hypervisor snap must carry the matching receiver change.
  3. Block the node's access to the Consul servers. With Cilium, target the pod IP range (10.1.0.0/16, port 30321), not the service IP. Expect nic-down and nova-compute stopped.
  4. Remove the block. After monitoring_samples consecutive successes, expect nic-up and nova-compute active again.
  5. Toggle the block on and off quickly. Expect no nic-up until the successes are consecutive.

Comment thread src/tcp_health_check.py Outdated
elif not socket_path:
logging.error("Cannot send alert: socket_path is required but was not provided")
else:
if send_nic_down_alert(socket_path):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A delayed nic-down acknowledgement can suppress recovery permanently. Lines 210–214 set alert_sent only when the acknowledgement arrives. The receiver replies after stopping nova-compute and handling VMs. If that takes over three seconds, the sender times out despite the action occurring. If connectivity recovers before another successful nic-down exchange, alert_sent remains false and no nic-up is sent.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

on_failure now sets alert_sent = True optimistically regardless of the ack (src/tcp_health_check.py:213-215). A timed-out ack logs a warning but the recovery nic-up is still armed.
Safe because the receiver is idempotent: it saves state before acting on nic-down, and nic-up is a no-op if no evacuation was recorded. Nic-up still requires N consecutive successes, so flapping behavior is unchanged.

@ahmad-can
ahmad-can requested a review from gboutry November 20, 2026 07:54

@gboutry gboutry left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I reran the delayed-ack case against the receiver over a local Unix socket, with the Nova and Masakari calls stubbed. nic-up is now sent when the socket timeout returns before the check is killed. I hit two other cases that still need fixing.

Comment thread src/tcp_health_check.py Resolved
Comment thread src/tcp_health_check.py Resolved
@ahmad-can
ahmad-can requested a review from gboutry November 20, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants