Skip to content
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

refactor(agent): remove dashboard #125

Merged
merged 1 commit into from
May 29, 2024
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 config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ key_store.mapping_key = "RelevantOracleMappingAddress"

# [metrics_server]
#
# Where to serve the quick-access dashboard and metrics. Metrics live under "/metrics"
# Where to serve metrics. Metrics live under "/metrics"
# NOTE: non-loopback addresses must be used carefully, making sure the
# connection is not exposed for unauthorized access.
# bind_address = "127.0.0.1:8888"
Expand Down
1 change: 0 additions & 1 deletion src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ Note that there is an Oracle and Exporter for each network, but only one Local S

################################################################################################################################## */

pub mod dashboard;
pub mod legacy_schedule;
pub mod market_schedule;
pub mod metrics;
Expand Down
283 changes: 0 additions & 283 deletions src/agent/dashboard.rs

This file was deleted.

56 changes: 15 additions & 41 deletions src/agent/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ lazy_static! {
}

/// Internal metrics server state, holds state needed for serving
/// dashboard and metrics.
/// metrics.
pub struct MetricsServer {
pub start_time: Instant,
pub logger: Logger,
pub adapter: Arc<State>,
}

impl MetricsServer {
/// Instantiate a metrics API with a dashboard
/// Instantiate a metrics API.
pub async fn spawn(addr: impl Into<SocketAddr> + 'static, logger: Logger, adapter: Arc<State>) {
let server = MetricsServer {
start_time: Instant::now(),
Expand All @@ -82,56 +82,30 @@ impl MetricsServer {
};

let shared_state = Arc::new(Mutex::new(server));

let shared_state4dashboard = shared_state.clone();
let dashboard_route = warp::path("dashboard")
.or(warp::path::end())
.and_then(move |_| {
let shared_state = shared_state4dashboard.clone();
async move {
let locked_state = shared_state.lock().await;
let response = locked_state
.render_dashboard() // Defined in a separate impl block near dashboard-specific code
.await
.unwrap_or_else(|e| {
// Add logging here
error!(locked_state.logger,"Dashboard: Rendering failed"; "error" => e.to_string());

// Withhold failure details from client
"Could not render dashboard! See the logs for details".to_owned()
});
Result::<Box<dyn Reply>, Rejection>::Ok(Box::new(reply::with_status(
reply::html(response),
StatusCode::OK,
)))
}
});

let shared_state4metrics = shared_state.clone();
let metrics_route = warp::path("metrics")
.and(warp::path::end())
.and_then(move || {
let shared_state = shared_state4metrics.clone();
async move {
let locked_state = shared_state.lock().await;
let locked_state = shared_state.lock().await;
let mut buf = String::new();
let response = encode(&mut buf, &&PROMETHEUS_REGISTRY.lock().await).map_err(|e| -> Box<dyn std::error::Error> {e.into()
}).and_then(|_| -> Result<_, Box<dyn std::error::Error>> {

Ok(Box::new(reply::with_status(buf, StatusCode::OK)))
}).unwrap_or_else(|e| {
error!(locked_state.logger, "Metrics: Could not gather metrics from registry"; "error" => e.to_string());

Box::new(reply::with_status("Could not gather metrics. See logs for details".to_string(), StatusCode::INTERNAL_SERVER_ERROR))
});
let response = encode(&mut buf, &&PROMETHEUS_REGISTRY.lock().await)
.map_err(|e| -> Box<dyn std::error::Error> {
e.into()
})
.and_then(|_| -> Result<_, Box<dyn std::error::Error>> {
Ok(Box::new(reply::with_status(buf, StatusCode::OK)))
}).unwrap_or_else(|e| {
error!(locked_state.logger, "Metrics: Could not gather metrics from registry"; "error" => e.to_string());
Box::new(reply::with_status("Could not gather metrics. See logs for details".to_string(), StatusCode::INTERNAL_SERVER_ERROR))
});

Result::<Box<dyn Reply>, Rejection>::Ok(response)
Result::<Box<dyn Reply>, Rejection>::Ok(response)
}
});

warp::serve(dashboard_route.or(metrics_route))
.bind(addr)
.await;
warp::serve(metrics_route).bind(addr).await;
}
}

Expand Down
Loading