Skip to content
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
577 changes: 576 additions & 1 deletion Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tonic = "0.14.1"
tucana = { version = "0.0.77", features = ["aquila", "sagittarius_gateway"] }
code0-flow = { version = "0.0.42", features = ["flow_config", "flow_health", "flow_telemetry"] }
serde_json = "1.0.140"
lupus = "0.0.2"
async-nats = "0.50.0"
tonic-health = "0.14.1"
tokio-stream = "0.1.17"
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod sagittarius;
pub mod server;
pub mod startup;
pub mod telemetry;
pub mod validation;
pub mod version;

const CONFIG_PATH_ENV: &str = "AQUILA_CONFIG_PATH";
Expand Down
3 changes: 2 additions & 1 deletion src/sagittarius/flow_service_client_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ impl SagittariusFlowClient {
dev_export::overwrite(&self.flow_export_path, flows.clone()).await;
}

let (purged_count, stored_count) = flow_store::replace_all(&self.store, flows).await;
let (purged_count, stored_count) =
flow_store::replace_all(&self.store, flows).await;
log::info!(
"Finished replacing stored flows received_count={} purged_count={} stored_count={}",
received_count,
Expand Down
4 changes: 3 additions & 1 deletion src/sagittarius/module_configuration_client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ impl SagittariusModuleConfigurationClient {
}

log::warn!("Sagittarius closed the module configuration stream; reconnecting");
Err(tonic::Status::unavailable("module configuration stream ended"))
Err(tonic::Status::unavailable(
"module configuration stream ended",
))
}
}
4 changes: 3 additions & 1 deletion src/sagittarius/test_execution_client_impl/flow_id_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ fn prune_expired(entries: &mut HashMap<String, ExecutionFlowIdMapping>, now: Ins

/// Evicts whichever entry is closest to expiring, since that's the best
/// approximation of "oldest" without tracking insertion order separately.
fn remove_soonest_to_expire(entries: &mut HashMap<String, ExecutionFlowIdMapping>) -> Option<String> {
fn remove_soonest_to_expire(
entries: &mut HashMap<String, ExecutionFlowIdMapping>,
) -> Option<String> {
let soonest_execution_id = entries
.iter()
.min_by_key(|(_, mapping)| mapping.expires_at)
Expand Down
44 changes: 41 additions & 3 deletions src/sagittarius/test_execution_client_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use tucana::sagittarius_gateway::execution_service_client::ExecutionServiceClien
use tucana::sagittarius_gateway::{ExecutionLogonRequest, Logon};
use tucana::shared::{ExecutionFlow, ValidationFlow};

use crate::{authorization::authorization::get_authentication_metadata, flow::key_has_flow_id};
use crate::{
authorization::authorization::get_authentication_metadata, flow::key_has_flow_id, validation,
};

pub struct SagittariusTestExecutionServiceClient {
nats_client: async_nats::Client,
Expand Down Expand Up @@ -205,8 +207,44 @@ impl SagittariusTestExecutionServiceClient {
}
};

// TODO: When the new validator is ready, the body needs to be validated at this
// point.
if validation::is_rest_flow(&validation_flow) {
let input_schema = validation::extract_input_schema(&validation_flow);
if let Err(err) = validation::validate_body_against_schema(
input_schema,
request.body.as_ref(),
) {
log::warn!(
"Rejecting Sagittarius execution request due to input schema validation failure requested_execution_id={} flow_id={} error={}",
request.execution_identifier,
request.flow_id,
err
);

let execution_id = if request.execution_identifier.is_empty() {
uuid::Uuid::new_v4().to_string()
} else {
request.execution_identifier.clone()
};

let rejection = validation::rejection_result(
execution_id,
request.flow_id,
&err,
);

if let Err(status) =
self.response_sender.send_execution_result(rejection).await
{
log::error!(
"Failed to send input schema validation rejection result flow_id={} error={:?}",
request.flow_id,
status
);
}

continue;
}
}

let execution_id = if request.execution_identifier.is_empty() {
uuid::Uuid::new_v4().to_string()
Expand Down
6 changes: 4 additions & 2 deletions src/sagittarius/test_execution_client_impl/response_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::sync::Arc;

use tokio::sync::Mutex;
use tonic::Status;
use tucana::sagittarius_gateway::execution_logon_request::Data;
use tucana::sagittarius_gateway::ExecutionLogonRequest;
use tucana::sagittarius_gateway::execution_logon_request::Data;
use tucana::shared::ExecutionResult;

use super::flow_id_cache::ExecutionFlowIdCache;
Expand Down Expand Up @@ -50,7 +50,9 @@ impl SagittariusExecutionResponseSender {
}

pub(super) async fn remember_execution_flow(&self, execution_id: &str, flow_id: i64) {
self.execution_flow_ids.remember(execution_id, flow_id).await;
self.execution_flow_ids
.remember(execution_id, flow_id)
.await;
}

pub(super) async fn forget_execution_flow(&self, execution_id: &str) {
Expand Down
10 changes: 8 additions & 2 deletions src/server/action_transfer/logon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,21 @@ pub(super) fn extract_token(
/// Whether a broadcasted config update is meant for `action_identifier`, since
/// [`spawn_cfg_forwarder`] subscribes to a single broadcast channel shared by
/// every connected action.
fn applies_to_action(configs: &tucana::shared::ModuleConfigurations, action_identifier: &str) -> bool {
fn applies_to_action(
configs: &tucana::shared::ModuleConfigurations,
action_identifier: &str,
) -> bool {
configs.module_identifier == action_identifier
}

/// Rewrites every definition's `definition_source` on the module an action
/// logs on with, so downstream consumers can tell it came from this action
/// rather than from whatever source the action's module definition was
/// authored against.
fn overwrite_module_definition_sources(module: &mut tucana::shared::Module, action_identifier: &str) {
fn overwrite_module_definition_sources(
module: &mut tucana::shared::Module,
action_identifier: &str,
) {
let source = format!("action.{}", action_identifier);

for flow_type in &mut module.flow_types {
Expand Down
6 changes: 3 additions & 3 deletions src/server/action_transfer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use tokio_stream::wrappers::ReceiverStream;
use tonic::Status;
use tracing::Instrument;
use tucana::aquila::{
ActionTransferRequest, ActionTransferResponse, action_transfer_service_server::ActionTransferService,
ActionTransferRequest, ActionTransferResponse,
action_transfer_service_server::ActionTransferService,
};

use crate::{
configuration::service::ServiceConfiguration,
sagittarius::module_service_client_impl::SagittariusModuleServiceClient,
telemetry::metrics,
sagittarius::module_service_client_impl::SagittariusModuleServiceClient, telemetry::metrics,
};

use logon::{extract_token, handle_logon};
Expand Down
4 changes: 3 additions & 1 deletion src/server/action_transfer/nats_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use async_nats::{Subject, Subscriber};
use futures::StreamExt;
use prost::Message;
use tucana::{
aquila::{ActionEvent, ActionExecutionRequest, ActionExecutionResponse, ActionTransferResponse},
aquila::{
ActionEvent, ActionExecutionRequest, ActionExecutionResponse, ActionTransferResponse,
},
shared::{ExecutionFlow, Flows, ValidationFlow, Value},
};

Expand Down
4 changes: 2 additions & 2 deletions src/server/dynamic_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
test_execution_client_impl::SagittariusExecutionResponseSender,
},
server::{
action_transfer::AquilaActionTransferServiceServer,
create_readiness_interceptor, module_service_server_impl::AquilaModuleServiceServer,
action_transfer::AquilaActionTransferServiceServer, create_readiness_interceptor,
module_service_server_impl::AquilaModuleServiceServer,
runtime_execution_service_server_impl::AquilaExecutionServiceServer,
runtime_status_service_server_impl::AquilaRuntimeStatusServiceServer,
},
Expand Down
6 changes: 5 additions & 1 deletion src/server/runtime_status_service_server_impl/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ pub(super) fn spawn(
interval.tick().await;

let timeout_updates = registry
.collect_timeout_updates(Instant::now(), not_responding_after, stopped_after_not_responding)
.collect_timeout_updates(
Instant::now(),
not_responding_after,
stopped_after_not_responding,
)
.await;

if timeout_updates.is_empty() {
Expand Down
7 changes: 6 additions & 1 deletion src/server/runtime_status_service_server_impl/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ impl TrackedRuntimeRegistry {
stopped_after_not_responding: Duration,
) -> Vec<RuntimeStatusUpdateRequest> {
let mut tracked = self.tracked.lock().await;
collect_timeout_updates(&mut tracked, now, not_responding_after, stopped_after_not_responding)
collect_timeout_updates(
&mut tracked,
now,
not_responding_after,
stopped_after_not_responding,
)
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/server/static_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

use crate::{
configuration::{config::Config, service::ServiceConfiguration, state::AppReadiness},
server::{
action_transfer::AquilaActionTransferServiceServer,
create_readiness_interceptor,
},
server::{action_transfer::AquilaActionTransferServiceServer, create_readiness_interceptor},
};
use async_nats::jetstream::kv::Store;
use log::info;
Expand Down
5 changes: 4 additions & 1 deletion src/startup/dynamic_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ pub async fn run(
action_config_tx_for_module_configuration.clone(),
);

match module_configuration_client.init_configuration_stream().await {
match module_configuration_client
.init_configuration_stream()
.await
{
Ok(_) => {
log::warn!(
"Sagittarius module configuration stream ended normally; reconnecting"
Expand Down
Loading