health: expand health check functionality with `health` package by crypto
Problem
Health checks for many infrastructure providers such as GCP, AWS and Cloudflare require an endpoint which accepts an HTTP GET request and returns status 200 if the service is healthy.
The current mechanism to address this was last updated in 2017 (#15496) where an exception was made to return status 200 for an empty HTTP GET request as the rpc only currently accepts POST requests of type application/json.
It would be useful to expand this functionality to enable operators to define the state required to be considered healthy. Other execution clients such as Erigon and Nethermind have implemented similar solutions.
Proposed Solution
This PR seeks to add a new package called health which extends the functionality of the http server to add a /health endpoint when invoked with the --http.health flag.
When enabled an operator can set parameters using the X-GETH-HEALTHCHECK header.
Available options (these match Erigon for cross compatibility):
synced - will check if the node has completed syncing min_peer_count<count> - will check that the node has at least <count> many peers check_block<block> - will check that the node is at least ahead of the <block> specified max_seconds_behind<seconds> - will check that the node is no more than <seconds> behind from its latest blockThe request will return:
Status 200 if all of the specified parameters are met Status 500 if one or more parameters is not met or invalid A response body containing the status of each checkWhen no value is provided for an option that check will not run. The status of the check will be DISABLED in the return object.
Example Request
curl --request GET 'http://localhost:8545/health' --header 'X-GETH-HEALTHCHECK: min_peer_count10' --header 'X-GETH-HEALTHCHECK: synced' --header 'X-GETH-HEALTHCHECK: max_seconds_behind60'
Alternatively you can send a POST request using the same parameters in JSON:
curl --request POST http://localhost:8545/health --data '{"min_peer_count": 10, "synced": true, "max_seconds_behind": 60}'
Example Healthy Response (Status: 200)
{ "query": "OK", "check_block":"DISABLED", "max_seconds_behind":"OK", "min_peer_count":"OK", "synced":"OK" }
Example Unhealthy Response (Status: 500)
{ "query": "OK", "check_block":"DISABLED", "max_seconds_behind":"OK", "min_peer_count":"not enough peers: 2 (minimum 10)", "synced":"OK" }
Structure
Due to the restriction on the rpc package only accepting POST requests of type application/json and issues with circular imports creating a separate package which can be enabled independently appeared to be the cleanest solution. The package is similar in implementation to the graphql package in that it extends the http server, so the new package is mimicking the structure of this package.
Further Development
The work on this PR was done by the team at Republic Crypto. We're happy to accept input and apply requests for change where needed.
相关知识
Different Types of Health Check
Health check
The Importance of Regular Health Check
Your health
Disparities in Preventive Oral Health Care and Periodontal Health Among Adults With Diabetes
Importance of Health Check
Health and Wellbeing Check In Tips
Connected Health: Smart Scales, Watches and Health Monitors
25 Health Idioms with Examples: Talk About Good or Bad Health
Health Information
网址: health: expand health check functionality with `health` package by crypto https://www.trfsz.com/newsview1636131.html
推荐资讯
- 1发朋友圈对老公彻底失望的心情 12775
- 2BMI体重指数计算公式是什么 11235
- 3补肾吃什么 补肾最佳食物推荐 11199
- 4性生活姿势有哪些 盘点夫妻性 10428
- 5BMI正常值范围一般是多少? 10137
- 6在线基础代谢率(BMR)计算 9652
- 7一边做饭一边躁狂怎么办 9138
- 8从出汗看健康 出汗透露你的健 9063
- 9早上怎么喝水最健康? 8613
- 10五大原因危害女性健康 如何保 7828
