Preserve the in-progress cluster RPC experiment for archival
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
pub mod rpc;
|
||||
|
||||
use std::{io, sync::Arc};
|
||||
|
||||
use axum::{
|
||||
@@ -9,7 +11,7 @@ use axum::{
|
||||
routing::get,
|
||||
};
|
||||
use clusters::{DOCUMENTS, ResolvedDeployment, SqlDriver};
|
||||
use serde::Serialize;
|
||||
use rpc::DeploymentStatus;
|
||||
use subtle::ConstantTimeEq;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -20,29 +22,27 @@ struct AdminState {
|
||||
read_only: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct DeploymentStatus<'a> {
|
||||
deployment: &'a str,
|
||||
config_version: Option<&'a str>,
|
||||
storage_driver: &'static str,
|
||||
read_only: bool,
|
||||
}
|
||||
|
||||
impl AdminState {
|
||||
fn status(&self) -> DeploymentStatus<'_> {
|
||||
fn status(&self) -> DeploymentStatus {
|
||||
let config = &self.config;
|
||||
DeploymentStatus {
|
||||
deployment: &config.deployment,
|
||||
deployment: config.deployment.clone(),
|
||||
config_version: self
|
||||
.config_version
|
||||
.as_deref()
|
||||
.or(Some(&config.config_version)),
|
||||
storage_driver: self.storage_driver,
|
||||
.clone()
|
||||
.or_else(|| Some(config.config_version.clone())),
|
||||
storage_driver: self.storage_driver.to_owned(),
|
||||
read_only: self.read_only,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl rpc::Service for AdminState {
|
||||
async fn status(&self, _: rpc::StatusRequest) -> Result<DeploymentStatus, StatusCode> {
|
||||
Ok(self.status())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn router(
|
||||
config: Arc<ResolvedDeployment>,
|
||||
config_version: Option<String>,
|
||||
@@ -71,8 +71,16 @@ pub fn router(
|
||||
};
|
||||
let read_only = settings.read_only;
|
||||
|
||||
let state = AdminState {
|
||||
config,
|
||||
config_version,
|
||||
storage_driver,
|
||||
read_only,
|
||||
};
|
||||
let admin = Router::new()
|
||||
.route("/status", get(deployment_status))
|
||||
.route("/admin/v1/status", get(deployment_status))
|
||||
.with_state(state.clone())
|
||||
.merge(rpc::router(state))
|
||||
.route_layer(middleware::from_fn_with_state(
|
||||
Arc::<str>::from(token),
|
||||
require_admin,
|
||||
@@ -80,13 +88,7 @@ pub fn router(
|
||||
Ok(Router::new()
|
||||
.route("/healthz", get(|| async { StatusCode::NO_CONTENT }))
|
||||
.route("/readyz", get(|| async { StatusCode::NO_CONTENT }))
|
||||
.nest("/admin/v1", admin)
|
||||
.with_state(AdminState {
|
||||
config,
|
||||
config_version,
|
||||
storage_driver,
|
||||
read_only,
|
||||
}))
|
||||
.merge(admin))
|
||||
}
|
||||
|
||||
async fn deployment_status(State(state): State<AdminState>) -> Response {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//! Shared wire contract for querying the Bedrock instance serving the request.
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct StatusRequest {}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct DeploymentStatus {
|
||||
pub deployment: String,
|
||||
pub config_version: Option<String>,
|
||||
pub storage_driver: String,
|
||||
pub read_only: bool,
|
||||
}
|
||||
|
||||
bedrock_rpc::service! {
|
||||
"/admin/v1/deployment" {
|
||||
fn status(StatusRequest) -> DeploymentStatus;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user