Skip to content

Commit 24a38e2

Browse files
authored
Add /api/v1/about http endpoint (#462)
Fixes #461
1 parent a35e07d commit 24a38e2

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

server/src/about.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub async fn print(config: &Config, meta: &StorageMetadata) {
122122
// print current version
123123
let current = current();
124124
let latest_release = if config.parseable.check_update {
125-
update::get_latest(meta).await.ok()
125+
update::get_latest(&meta.deployment_id).await.ok()
126126
} else {
127127
None
128128
};

server/src/handlers/http.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::rbac::role::Action;
3131

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

34+
mod about;
3435
mod health_check;
3536
mod ingest;
3637
mod logstream;
@@ -233,6 +234,8 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
233234
.service(web::resource("/liveness").route(web::get().to(health_check::liveness)))
234235
// GET "/readiness" ==> Readiness check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes
235236
.service(web::resource("/readiness").route(web::get().to(health_check::readiness)))
237+
// GET "/about" ==> Returns information about instance
238+
.service(web::resource("/about").route(web::get().to(about::about)))
236239
.service(
237240
web::scope("/logstream")
238241
.service(

server/src/handlers/http/about.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Parseable Server (C) 2022 - 2023 Parseable, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
use actix_web::web::Json;
20+
use serde_json::json;
21+
22+
use crate::{about, option::CONFIG, storage::StorageMetadata, utils::update};
23+
24+
pub async fn about() -> Json<serde_json::Value> {
25+
let meta = StorageMetadata::global();
26+
27+
let current_release = about::current();
28+
let latest_release = update::get_latest(&meta.deployment_id).await;
29+
30+
let (update_available, latest_release) = match latest_release {
31+
Ok(latest_release) => (
32+
latest_release.version > current_release.released_version,
33+
Some(format!("v{}", latest_release.version)),
34+
),
35+
Err(_) => (false, None),
36+
};
37+
38+
let current_version = format!("v{}", current_release.released_version);
39+
let commit = current_release.commit_hash;
40+
let deployment_id = meta.deployment_id.to_string();
41+
let mode = CONFIG.mode_string();
42+
let staging = CONFIG.staging_dir();
43+
let store = CONFIG.storage().get_endpoint();
44+
45+
Json(json!({
46+
"version": current_version,
47+
"commit": commit,
48+
"deploymentId": deployment_id,
49+
"updateAvailable": update_available,
50+
"latestVersion": latest_release,
51+
"license": "AGPL-3.0-only",
52+
"mode": mode,
53+
"staging": staging,
54+
"store": store
55+
}))
56+
}

server/src/utils/update.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ use anyhow::anyhow;
2222
use chrono::{DateTime, Utc};
2323

2424
use crate::about;
25-
use crate::storage::StorageMetadata;
25+
26+
use super::uid;
2627

2728
#[derive(Debug)]
2829
pub struct LatestRelease {
2930
pub version: semver::Version,
3031
pub date: DateTime<Utc>,
3132
}
3233

33-
pub async fn get_latest(meta: &StorageMetadata) -> Result<LatestRelease, anyhow::Error> {
34+
pub async fn get_latest(deployment_id: &uid::Uid) -> Result<LatestRelease, anyhow::Error> {
3435
let agent = reqwest::ClientBuilder::new()
35-
.user_agent(about::user_agent(&meta.deployment_id))
36+
.user_agent(about::user_agent(deployment_id))
3637
.timeout(Duration::from_secs(8))
3738
.build()
3839
.expect("client can be built on this system");

0 commit comments

Comments
 (0)