Skip to content

Add /api/v1/about http endpoint #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
3 changes: 3 additions & 0 deletions server/src/handlers/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::rbac::role::Action;

use self::middleware::{Auth, DisAllowRootUser};

mod about;
mod health_check;
mod ingest;
mod logstream;
Expand Down Expand Up @@ -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 "/about" ==> Returns information about instance
.service(web::resource("/about").route(web::get().to(about::about)))
.service(
web::scope("/logstream")
.service(
Expand Down
56 changes: 56 additions & 0 deletions server/src/handlers/http/about.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*/

use actix_web::web::Json;
use serde_json::json;

use crate::{about, option::CONFIG, storage::StorageMetadata, utils::update};

pub async fn about() -> Json<serde_json::Value> {
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,
"deploymentId": deployment_id,
"updateAvailable": update_available,
"latestVersion": latest_release,
"license": "AGPL-3.0-only",
"mode": mode,
"staging": staging,
"store": store
}))
}
7 changes: 4 additions & 3 deletions server/src/utils/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ use anyhow::anyhow;
use chrono::{DateTime, Utc};

use crate::about;
use crate::storage::StorageMetadata;

use super::uid;

#[derive(Debug)]
pub struct LatestRelease {
pub version: semver::Version,
pub date: DateTime<Utc>,
}

pub async fn get_latest(meta: &StorageMetadata) -> Result<LatestRelease, anyhow::Error> {
pub async fn get_latest(deployment_id: &uid::Uid) -> Result<LatestRelease, anyhow::Error> {
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");
Expand Down