mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-04 04:12:55 +00:00
feat: add initial implementation for status endpoint (#1789)
* feat: add initial implementation for status endpoint * feat(status_endpoint): add more data to response * feat(status_endpoint): use build data env vars * feat(status_endpoint): add simple test * fix(status_endpoint): adjust the toml indentation
This commit is contained in:
@@ -52,4 +52,4 @@ serde.workspace = true
|
||||
toml = "0.5"
|
||||
|
||||
[build-dependencies]
|
||||
build-data = "0.1.3"
|
||||
build-data = "0.1.4"
|
||||
|
||||
@@ -103,3 +103,6 @@ table = { path = "../table" }
|
||||
tokio-postgres = "0.7"
|
||||
tokio-postgres-rustls = "0.10"
|
||||
tokio-test = "0.4"
|
||||
|
||||
[build-dependencies]
|
||||
build-data = "0.1.4"
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
// limitations under the License.
|
||||
|
||||
fn main() {
|
||||
build_data::set_RUSTC_VERSION();
|
||||
build_data::set_BUILD_HOSTNAME();
|
||||
build_data::set_GIT_BRANCH();
|
||||
build_data::set_GIT_COMMIT();
|
||||
build_data::set_SOURCE_TIMESTAMP();
|
||||
|
||||
#[cfg(feature = "dashboard")]
|
||||
fetch_dashboard_assets();
|
||||
}
|
||||
|
||||
@@ -512,6 +512,8 @@ impl HttpServer {
|
||||
routing::get(handler::health).post(handler::health),
|
||||
);
|
||||
|
||||
router = router.route("/status", routing::get(handler::status));
|
||||
|
||||
#[cfg(feature = "dashboard")]
|
||||
{
|
||||
if !self.options.disable_dashboard {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::time::Instant;
|
||||
|
||||
use aide::transform::TransformOperation;
|
||||
@@ -158,3 +159,26 @@ pub struct HealthResponse {}
|
||||
pub async fn health(Query(_params): Query<HealthQuery>) -> Json<HealthResponse> {
|
||||
Json(HealthResponse {})
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
pub struct StatusResponse<'a> {
|
||||
pub source_time: &'a str,
|
||||
pub commit: &'a str,
|
||||
pub branch: &'a str,
|
||||
pub rustc_version: &'a str,
|
||||
pub hostname: &'a str,
|
||||
pub version: &'a str,
|
||||
}
|
||||
|
||||
/// Handler to expose information info about runtime, build, etc.
|
||||
#[axum_macros::debug_handler]
|
||||
pub async fn status() -> Json<StatusResponse<'static>> {
|
||||
Json(StatusResponse {
|
||||
source_time: env!("SOURCE_TIMESTAMP"),
|
||||
commit: env!("GIT_COMMIT"),
|
||||
branch: env!("GIT_BRANCH"),
|
||||
rustc_version: env!("RUSTC_VERSION"),
|
||||
hostname: env!("BUILD_HOSTNAME"),
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -365,3 +365,18 @@ async fn test_health() {
|
||||
expected_json_str
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_status() {
|
||||
let expected_json = http_handler::StatusResponse {
|
||||
source_time: env!("SOURCE_TIMESTAMP"),
|
||||
commit: env!("GIT_COMMIT"),
|
||||
branch: env!("GIT_BRANCH"),
|
||||
rustc_version: env!("RUSTC_VERSION"),
|
||||
hostname: env!("BUILD_HOSTNAME"),
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
};
|
||||
|
||||
let Json(json) = http_handler::status().await;
|
||||
assert_eq!(json, expected_json);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user