Our Personal Data Server from scratch! tranquil.farm
oauth atproto pds rust postgresql objectstorage fun

feat: add version information to _health endpoint #29

merged opened by diddyfo.id targeting main from [deleted fork]: feat/version-health

Currently, the endpoint only returns a plain text message depending on the state of the PDS. This is behaviour that is not congruent with most other PDSes, which provide a basic JSON response containing the version number and (on third-party implementation) a prefix for the implementation's name. The result is that tools such as atproto-scraping and PDSwatch are unable to recognize tranquil or the version number. This PR fixes the behaviour (and is also my first PR with Rust so let me know if there are any changes that need to be made).

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:5szlrh3xkfxxsuu4mo6oe6h7/sh.tangled.repo.pull/3mfszbjrzto22
+35 -25
Diff #1
+33 -13
crates/tranquil-pds/src/api/server/meta.rs
··· 1 1 2 2 3 + use axum::{Json, extract::State, http::StatusCode, response::IntoResponse}; 4 + use serde_json::json; 3 5 6 + #[cfg(debug_assertions)] 7 + pub const BUILD_VERSION: &str = concat!( 8 + env!("CARGO_PKG_VERSION"), 9 + " (built ", 10 + env!("BUILD_TIMESTAMP"), 11 + ")" 12 + ); 13 + #[cfg(not(debug_assertions))] 14 + pub const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION"); 4 15 16 + fn get_available_comms_channels() -> Vec<tranquil_db_traits::CommsChannel> { 17 + use tranquil_db_traits::CommsChannel; 18 + let cfg = tranquil_config::get(); 5 19 6 20 7 21 ··· 48 62 49 63 50 64 65 + "did": format!("did:web:{}", pds_hostname), 66 + "links": links, 67 + "contact": contact, 68 + "version": BUILD_VERSION, 69 + "availableCommsChannels": get_available_comms_channels(), 70 + "selfHostedDidWebEnabled": is_self_hosted_did_web_enabled() 71 + }); 51 72 52 73 53 74 ··· 58 79 59 80 60 81 61 - 62 - 63 - 64 - 65 - 66 - 67 - 68 - 69 - 70 - 71 - 72 82 } 73 83 pub async fn health(State(state): State<AppState>) -> impl IntoResponse { 74 84 match state.infra_repo.health_check().await { 75 - Ok(true) => (StatusCode::OK, "OK"), 76 - _ => (StatusCode::SERVICE_UNAVAILABLE, "Service Unavailable"), 85 + Ok(true) => ( 86 + StatusCode::OK, 87 + Json(json!({ 88 + "version": format!("tranquil {}", BUILD_VERSION) 89 + })), 90 + ), 91 + _ => ( 92 + StatusCode::SERVICE_UNAVAILABLE, 93 + Json(json!({ 94 + "error": "Service Unavailable" 95 + })), 96 + ), 77 97 } 78 98 }
+1 -1
crates/tranquil-pds/src/api/server/mod.rs
··· 29 29 }; 30 30 pub use invite::{create_invite_code, create_invite_codes, get_account_invite_codes}; 31 31 pub use logo::get_logo; 32 - pub use meta::{describe_server, health, robots_txt}; 32 + pub use meta::{BUILD_VERSION, describe_server, health, robots_txt}; 33 33 pub use migration::{get_did_document, update_did_document}; 34 34 pub use passkey_account::{ 35 35 complete_passkey_setup, create_passkey_account, recover_passkey_account,
+1 -11
crates/tranquil-pds/src/main.rs
··· 6 6 use tokio_util::sync::CancellationToken; 7 7 use tracing::{error, info, warn}; 8 8 use tranquil_pds::comms::{CommsService, DiscordSender, EmailSender, SignalSender, TelegramSender}; 9 - 10 - #[cfg(debug_assertions)] 11 - const BUILD_VERSION: &str = concat!( 12 - env!("CARGO_PKG_VERSION"), 13 - " (built ", 14 - env!("BUILD_TIMESTAMP"), 15 - ")" 16 - ); 17 - #[cfg(not(debug_assertions))] 18 - const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION"); 19 - 20 9 use tranquil_pds::crawlers::{Crawlers, start_crawlers_service}; 21 10 use tranquil_pds::scheduled::{ 22 11 backfill_genesis_commit_blocks, backfill_record_blobs, backfill_repo_rev, backfill_user_blocks, 23 12 start_backup_tasks, start_scheduled_tasks, 24 13 }; 25 14 use tranquil_pds::state::AppState; 15 + use tranquil_pds::api::server::meta::BUILD_VERSION; 26 16 27 17 #[derive(Parser)] 28 18 #[command(name = "tranquil-pds", version = BUILD_VERSION, about = "Tranquil AT Protocol PDS")]

History

4 rounds 7 comments
sign up or login to add to the discussion
1 commit
expand
e567d169
feat: add version information to _health endpoint
expand 2 comments

took a while but it should be ready to merge now!

okay yea that patch looks muuuch better. thanks!

pull request successfully merged
3 commits
expand
68058306
feat: send version information on _health
7406f4e8
move and utilize BUILD_VERSION variable
98d44072
relocate BUILD_VERSION to lib.rs
expand 2 comments

This probably needs to be squashed when merging lol

oookay yea i think ... tangled is really hating this for whatever reason. knowing tangled its maybe because your branch is made off of one commit older than the current main branch? maybe rebasing (and maybe squashing) onto current main and resubmitting will fix it?

otherwise i might merge this manually and not through tangled because this ... doesnt look great. knowing that tangled uses the generated patches to do the merge i dont want to try and merge it with tangled when the patches are this messy ...

code itself looks fine when looking directly at the repo tho so! thank you!

2 commits
expand
68058306
feat: send version information on _health
7406f4e8
move and utilize BUILD_VERSION variable
expand 2 comments

I couldn't figure out how to make the BUILD_VERSION constant public(crate) without getting an error about it being private so I moved it to the meta file and used it from there. If this isn't the right way to do it please let me know

ah right i forgot. its because the health endpoint handler is defined in the lib crate of that cargo package and the main.rs is the bin crate of that package. so pub(crate) makes it available to the bin crate but not the lib crate. and a plain pub wont work either since bin depends on lib so lib cant depend on bin.

putting BUILD_VERSION in meta.rs isnt a bad solution but i think id prefer it in lib.rs itself (right above the app function). so its at the top level of the lib crate just like it was at the top level of the bin crate. im a bit nitpicky heh 馃槄

1 commit
expand
68058306
feat: send version information on _health
expand 1 comment

hmm i think instead of reading CARGO_PKG_VERSION here make the BUILD_VERSION const in tranquil-pds/src/main.rs pub(crate) and then use that for the version here. so we keep one source of truth for the version. otherwise good! thank you!