hashicorp / hashicorp/consul

Simple health check on simple service doesn't work

Open
#21,982 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
30.1k
Forks
4.6k
Avg merge
1d 18h
Merged PRs (30d)
39

Description

#### Overview of the Issue

Can't seem to make a simple service health check work. I register it through Python's request lib, then make an endpoint available for health checks, but service checks show failing on UI.

#### Reproduction Steps

1. Start and register the service

```python
payload = {
'Address': '127.0.0.1',
'Check': {
'DeregisterCriticalServiceAfter': '30s',
'HTTP': 'http://127.0.0.1:5000',
'Interval': '5s',
'Timeout': '5s'},
'ID': 'my-service',
'Name': 'MyService',
'Port': 5000,
'Tags': ['greeter']
}

response = requests.put('http://127.0.0.1:8500/v1/agent/service/register', json=payload)
```

Testing the service manually:
```bash
>>> curl -i http://127.0.0.1:5000/health
HTTP/1.1 200 OK
date: Sun, 01 Dec 2024 04:45:37 GMT
server: uvicorn
content-length: 20
content-type: application/json

"Service is healthy"%

>>> curl -i http://127.0.0.1:5000/
HTTP/1.1 200 OK
date: Sun, 01 Dec 2024 04:45:55 GMT
server: uvicorn
content-length: 15
content-type: application/json

"Hello, world!"%
```

And in the UI:

![image](https://github.com/user-attachments/assets/20d8f244-76bc-45f0-b74f-87578c531844)

also, after 30 seconds the service gets removed.

### Consul info for both Client and Server

Client info
agent:
check_monitors = 0
check_ttls = 0
checks = 0
services = 0
build:
prerelease =
revision = c3f767b1
version = 1.15.4
version_metadata =
consul:
acl = disabled
bootstrap = false
known_datacenters = 1
leader = true
leader_addr = 127.0.0.1:8300
server = true
raft:
applied_index = 1145
commit_index = 1145
fsm_pending = 0
last_contact = 0
last_log_index = 1145
last_log_term = 2
last_snapshot_index = 0
last_snapshot_term = 0
latest_configuration = [{Suffrage:Voter ID:b28fa40e-ec1e-21d4-5cd7-dddbd20769b0 Address:127.0.0.1:8300}]
latest_configuration_index = 0
num_peers = 0
protocol_version = 3
protocol_version_max = 3
protocol_version_min = 0
snapshot_version_max = 1
snapshot_version_min = 0
state = Leader
term = 2
runtime:
arch = amd64
cpu_count = 16
goroutines = 145
max_procs = 16
os = linux
version = go1.20.4
serf_lan:
coordinate_resets = 0
encrypted = false
event_queue = 1
event_time = 2
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 1
members = 1
query_queue = 0
query_time = 1
serf_wan:
coordinate_resets = 0
encrypted = false
event_queue = 0
event_time = 1
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 1
members = 1
query_queue = 0
query_time = 1

### Operating system and Environment details

Operating System:
Platform: linux - OpenSuse Tumbleweed
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Wed Sep 25 07:09:20 UTC 2024 (b87e886)
Available memory (MB): 31961
Available CPU cores: 16

### Log Fragments

Don't know how

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the registration through the /v1/agent/service/register API with the supplied Python request and compare the configured HTTP check URL with the service endpoints and Consul UI status. Inspect the agent's health-check behavior and logs; done means the check reports passing and the service is not deregistered after 30 seconds.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend, observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.