Skip to content

Commit

Permalink
feat: add initial implementation for status endpoint (GreptimeTeam#1789)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
etolbakov authored Jun 21, 2023
1 parent 6205616 commit 3b91fc2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ serde.workspace = true
toml = "0.5"

[build-dependencies]
build-data = "0.1.3"
build-data = "0.1.4"
3 changes: 3 additions & 0 deletions src/servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions src/servers/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions src/servers/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions src/servers/src/http/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use std::collections::HashMap;
use std::env;
use std::time::Instant;

use aide::transform::TransformOperation;
Expand Down Expand Up @@ -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"),
})
}
15 changes: 15 additions & 0 deletions src/servers/tests/http/http_handler_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 3b91fc2

Please sign in to comment.