Skip to content

Commit 8b0050b

Browse files
socutessocutes
andauthored
release: Add functions and interfaces related to health checks (robustmq#1785)
* dev Signed-off-by: socutes <socutes@gmail.com> * dev Signed-off-by: socutes <socutes@gmail.com> * dev Signed-off-by: socutes <socutes@gmail.com> --------- Signed-off-by: socutes <socutes@gmail.com> Co-authored-by: socutes <socutes@gmail.com>
1 parent eef03f6 commit 8b0050b

14 files changed

Lines changed: 213 additions & 139 deletions

File tree

Cargo.lock

Lines changed: 39 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ members = [
5353
resolver = "2"
5454

5555
[workspace.package]
56-
version = "0.3.2"
56+
version = "0.3.3"
5757
edition = "2021"
5858
license = "Apache-2.0"
5959

src/admin-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ bytes.workspace = true
4646
validator.workspace = true
4747
rocksdb-engine.workspace = true
4848
connector.workspace = true
49+
common-healthy.workspace = true
4950

5051
[dev-dependencies]
5152
mockall.workspace = true

src/admin-server/src/cluster/health.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use axum::http::StatusCode;
1516
use common_base::http_response::success_response;
17+
use common_healthy::ready::healthy_ready_check;
1618
use serde::{Deserialize, Serialize};
1719

1820
#[derive(Serialize, Deserialize, Debug)]
@@ -30,16 +32,26 @@ fn build_placeholder_resp(check_type: &str) -> String {
3032
})
3133
}
3234

33-
pub async fn health_live() -> String {
34-
build_placeholder_resp("live")
35-
}
36-
37-
pub async fn health_ready() -> String {
38-
build_placeholder_resp("ready")
39-
}
40-
41-
pub async fn health_startup() -> String {
42-
build_placeholder_resp("startup")
35+
pub async fn health_ready() -> (StatusCode, String) {
36+
if healthy_ready_check() {
37+
(
38+
StatusCode::OK,
39+
success_response(HealthCheckResp {
40+
status: "ok".to_string(),
41+
check_type: "ready".to_string(),
42+
message: "all configured ports are ready".to_string(),
43+
}),
44+
)
45+
} else {
46+
(
47+
StatusCode::SERVICE_UNAVAILABLE,
48+
success_response(HealthCheckResp {
49+
status: "not_ready".to_string(),
50+
check_type: "ready".to_string(),
51+
message: "one or more configured ports are not ready".to_string(),
52+
}),
53+
)
54+
}
4355
}
4456

4557
pub async fn health_node() -> String {

0 commit comments

Comments
 (0)