updates telemetry to no longer use grpc
This commit is contained in:
57
server/src/http/backend/mod.rs
Normal file
57
server/src/http/backend/mod.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
mod connection;
|
||||
|
||||
use crate::http::backend::connection::BackendConnection;
|
||||
use crate::telemetry::management_service::TelemetryManagementService;
|
||||
use actix_web::{rt, web, HttpRequest, HttpResponse};
|
||||
use log::{error, trace};
|
||||
use std::sync::Arc;
|
||||
use tokio::select;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tonic::codegen::tokio_stream::StreamExt;
|
||||
|
||||
async fn backend_connect(
|
||||
req: HttpRequest,
|
||||
stream: web::Payload,
|
||||
cancel_token: web::Data<CancellationToken>,
|
||||
telemetry_management_service: web::Data<Arc<TelemetryManagementService>>,
|
||||
) -> Result<HttpResponse, actix_web::Error> {
|
||||
trace!("backend_connect");
|
||||
let (res, session, stream) = actix_ws::handle(&req, stream)?;
|
||||
|
||||
let mut stream = stream
|
||||
.aggregate_continuations()
|
||||
// up to 1 MiB
|
||||
.max_continuation_size(2_usize.pow(20));
|
||||
|
||||
let cancel_token = cancel_token.get_ref().clone();
|
||||
let tlm_management = telemetry_management_service.get_ref().clone();
|
||||
|
||||
rt::spawn(async move {
|
||||
let mut connection = BackendConnection::new(session, tlm_management);
|
||||
while !connection.should_close {
|
||||
let result = select! {
|
||||
_ = cancel_token.cancelled() => {
|
||||
connection.should_close = true;
|
||||
Ok(())
|
||||
},
|
||||
Some(msg) = connection.rx.recv() => connection.handle_response(msg).await,
|
||||
Some(msg) = stream.next() => connection.handle_request_message(msg).await,
|
||||
else => {
|
||||
connection.should_close = true;
|
||||
Ok(())
|
||||
},
|
||||
};
|
||||
if let Err(e) = result {
|
||||
error!("backend socket error: {e}");
|
||||
connection.should_close = true;
|
||||
}
|
||||
}
|
||||
connection.cleanup().await;
|
||||
});
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn setup_backend(cfg: &mut web::ServiceConfig) {
|
||||
cfg.route("", web::get().to(backend_connect));
|
||||
}
|
||||
Reference in New Issue
Block a user