mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-15 07:11:04 +00:00
feat: Added a /health endpoint (#230)
This commit is contained in:
@@ -131,10 +131,17 @@ pub struct NodeCount(pub ChainId, pub usize);
|
|||||||
/// Message sent to the Aggregator to get the network state of a particular node
|
/// Message sent to the Aggregator to get the network state of a particular node
|
||||||
pub struct GetNetworkState(pub Box<str>, pub NodeId);
|
pub struct GetNetworkState(pub Box<str>, pub NodeId);
|
||||||
|
|
||||||
|
/// Message sent to the Aggregator to get a health check
|
||||||
|
pub struct GetHealth;
|
||||||
|
|
||||||
impl Message for GetNetworkState {
|
impl Message for GetNetworkState {
|
||||||
type Result = Option<Request<Chain, GetNodeNetworkState>>;
|
type Result = Option<Request<Chain, GetNodeNetworkState>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Message for GetHealth {
|
||||||
|
type Result = usize;
|
||||||
|
}
|
||||||
|
|
||||||
impl Handler<AddNode> for Aggregator {
|
impl Handler<AddNode> for Aggregator {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
|
|
||||||
@@ -264,3 +271,11 @@ impl Handler<GetNetworkState> for Aggregator {
|
|||||||
Some(self.get_chain(&*chain)?.addr.send(GetNodeNetworkState(nid)))
|
Some(self.get_chain(&*chain)?.addr.send(GetNodeNetworkState(nid)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Handler<GetHealth> for Aggregator {
|
||||||
|
type Result = usize;
|
||||||
|
|
||||||
|
fn handle(&mut self, _: GetHealth, _: &mut Self::Context) -> Self::Result {
|
||||||
|
self.chains.len()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+16
-1
@@ -17,7 +17,7 @@ mod util;
|
|||||||
|
|
||||||
use node::connector::NodeConnector;
|
use node::connector::NodeConnector;
|
||||||
use feed::connector::FeedConnector;
|
use feed::connector::FeedConnector;
|
||||||
use aggregator::{Aggregator, GetNetworkState};
|
use aggregator::{Aggregator, GetNetworkState, GetHealth};
|
||||||
use util::{Locator, LocatorFactory};
|
use util::{Locator, LocatorFactory};
|
||||||
use types::NodeId;
|
use types::NodeId;
|
||||||
|
|
||||||
@@ -77,6 +77,19 @@ fn state_route(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn health(
|
||||||
|
aggregator: web::Data<Addr<Aggregator>>
|
||||||
|
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||||
|
aggregator
|
||||||
|
.send(GetHealth)
|
||||||
|
.from_err()
|
||||||
|
.and_then(|count| {
|
||||||
|
let body = format!("Connected chains: {}", count);
|
||||||
|
|
||||||
|
HttpResponse::Ok().body(body)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
use web::{resource, get};
|
use web::{resource, get};
|
||||||
|
|
||||||
@@ -99,6 +112,8 @@ fn main() -> std::io::Result<()> {
|
|||||||
.service(resource("/feed/").route(get().to(feed_route)))
|
.service(resource("/feed/").route(get().to(feed_route)))
|
||||||
.service(resource("/network_state/{chain}/{nid}").route(get().to_async(state_route)))
|
.service(resource("/network_state/{chain}/{nid}").route(get().to_async(state_route)))
|
||||||
.service(resource("/network_state/{chain}/{nid}/").route(get().to_async(state_route)))
|
.service(resource("/network_state/{chain}/{nid}/").route(get().to_async(state_route)))
|
||||||
|
.service(resource("/health").route(get().to_async(health)))
|
||||||
|
.service(resource("/health/").route(get().to_async(health)))
|
||||||
})
|
})
|
||||||
.bind(format!("0.0.0.0:{}", port))?
|
.bind(format!("0.0.0.0:{}", port))?
|
||||||
.start();
|
.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user