From 1a7cf27825653f3b815c145994446d6627135475 Mon Sep 17 00:00:00 2001 From: Satyam Singh Date: Mon, 31 Jul 2023 12:39:23 +0530 Subject: [PATCH 1/4] Function get_latest only required deployment_id --- server/src/about.rs | 2 +- server/src/utils/update.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/src/about.rs b/server/src/about.rs index c696a9c18..1dff12755 100644 --- a/server/src/about.rs +++ b/server/src/about.rs @@ -122,7 +122,7 @@ pub async fn print(config: &Config, meta: &StorageMetadata) { // print current version let current = current(); let latest_release = if config.parseable.check_update { - update::get_latest(meta).await.ok() + update::get_latest(&meta.deployment_id).await.ok() } else { None }; diff --git a/server/src/utils/update.rs b/server/src/utils/update.rs index 19659f877..c33879a55 100644 --- a/server/src/utils/update.rs +++ b/server/src/utils/update.rs @@ -22,7 +22,8 @@ use anyhow::anyhow; use chrono::{DateTime, Utc}; use crate::about; -use crate::storage::StorageMetadata; + +use super::uid; #[derive(Debug)] pub struct LatestRelease { @@ -30,9 +31,9 @@ pub struct LatestRelease { pub date: DateTime, } -pub async fn get_latest(meta: &StorageMetadata) -> Result { +pub async fn get_latest(deployment_id: &uid::Uid) -> Result { let agent = reqwest::ClientBuilder::new() - .user_agent(about::user_agent(&meta.deployment_id)) + .user_agent(about::user_agent(deployment_id)) .timeout(Duration::from_secs(8)) .build() .expect("client can be built on this system"); From 466ea26fd71ba55b12331f19f6412beb6d12ccef Mon Sep 17 00:00:00 2001 From: Satyam Singh Date: Mon, 31 Jul 2023 12:44:21 +0530 Subject: [PATCH 2/4] Add about endpoint --- server/src/handlers/http.rs | 3 ++ server/src/handlers/http/about.rs | 56 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 server/src/handlers/http/about.rs diff --git a/server/src/handlers/http.rs b/server/src/handlers/http.rs index c163c6a5c..3bcc70a0e 100644 --- a/server/src/handlers/http.rs +++ b/server/src/handlers/http.rs @@ -31,6 +31,7 @@ use crate::rbac::role::Action; use self::middleware::{Auth, DisAllowRootUser}; +mod about; mod health_check; mod ingest; mod logstream; @@ -233,6 +234,8 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) { .service(web::resource("/liveness").route(web::get().to(health_check::liveness))) // GET "/readiness" ==> Readiness check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes .service(web::resource("/readiness").route(web::get().to(health_check::readiness))) + // GET "/readiness" ==> Readiness check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes + .service(web::resource("/about").route(web::get().to(about::about))) .service( web::scope("/logstream") .service( diff --git a/server/src/handlers/http/about.rs b/server/src/handlers/http/about.rs new file mode 100644 index 000000000..73dce54a4 --- /dev/null +++ b/server/src/handlers/http/about.rs @@ -0,0 +1,56 @@ +/* + * Parseable Server (C) 2022 - 2023 Parseable, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +use actix_web::web::Json; +use serde_json::json; + +use crate::{about, option::CONFIG, storage::StorageMetadata, utils::update}; + +pub async fn about() -> Json { + let meta = StorageMetadata::global(); + + let current_release = about::current(); + let latest_release = update::get_latest(&meta.deployment_id).await; + + let (update_available, latest_release) = match latest_release { + Ok(latest_release) => ( + latest_release.version > current_release.released_version, + Some(format!("v{}", latest_release.version)), + ), + Err(_) => (false, None), + }; + + let current_version = format!("v{}", current_release.released_version); + let commit = current_release.commit_hash; + let deployment_id = meta.deployment_id.to_string(); + let mode = CONFIG.mode_string(); + let staging = CONFIG.staging_dir(); + let store = CONFIG.storage().get_endpoint(); + + Json(json!({ + "version": current_version, + "commit": commit, + "deployment-id": deployment_id, + "update-available": update_available, + "latest-version": latest_release, + "license": "AGPL-3.0-only", + "mode": mode, + "staging": staging, + "store": store + })) +} From 21b91c3f0f1730f14c8b3e1bff63c2e049130e4b Mon Sep 17 00:00:00 2001 From: Satyam Singh Date: Mon, 31 Jul 2023 12:55:28 +0530 Subject: [PATCH 3/4] Fix --- server/src/handlers/http.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/handlers/http.rs b/server/src/handlers/http.rs index 3bcc70a0e..ab935a2a8 100644 --- a/server/src/handlers/http.rs +++ b/server/src/handlers/http.rs @@ -234,7 +234,7 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) { .service(web::resource("/liveness").route(web::get().to(health_check::liveness))) // GET "/readiness" ==> Readiness check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes .service(web::resource("/readiness").route(web::get().to(health_check::readiness))) - // GET "/readiness" ==> Readiness check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes + // GET "/about" ==> Returns information about instance .service(web::resource("/about").route(web::get().to(about::about))) .service( web::scope("/logstream") From 98327a0a1a8ffed7bcc70477cacaf055bea305fd Mon Sep 17 00:00:00 2001 From: Satyam Singh Date: Mon, 31 Jul 2023 13:07:26 +0530 Subject: [PATCH 4/4] Change to camelCase --- server/src/handlers/http/about.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/handlers/http/about.rs b/server/src/handlers/http/about.rs index 73dce54a4..ba6feb188 100644 --- a/server/src/handlers/http/about.rs +++ b/server/src/handlers/http/about.rs @@ -45,9 +45,9 @@ pub async fn about() -> Json { Json(json!({ "version": current_version, "commit": commit, - "deployment-id": deployment_id, - "update-available": update_available, - "latest-version": latest_release, + "deploymentId": deployment_id, + "updateAvailable": update_available, + "latestVersion": latest_release, "license": "AGPL-3.0-only", "mode": mode, "staging": staging,