-
Notifications
You must be signed in to change notification settings - Fork 12
feat(spider-execution-manager): Add the execution-manager binary. #362
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ce9fe93
Done refactoring and implementation.
LinZhihao-723 51de436
Make liveness public API to not take an Arc.
LinZhihao-723 f9ffb29
Add clone to the type constraints.
LinZhihao-723 d644646
Update cargo to drop unused yaml dependency.
LinZhihao-723 99ea4fa
Add constraints to the heartbeat interval.
LinZhihao-723 e25bf26
Merge branch 'main' into em-bin
LinZhihao-723 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
components/spider-execution-manager/src/bin/execution_manager.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| //! Command-line entrypoint for the execution manager. | ||
|
|
||
| use std::{error::Error, path::PathBuf}; | ||
|
|
||
| use clap::Parser; | ||
| use spider_execution_manager::{ | ||
| Config, | ||
| client::grpc::{GrpcLivenessClient, GrpcSchedulerClient, GrpcStorageClient}, | ||
| runtime::Runtime, | ||
| }; | ||
| use spider_utils::{config::YamlConfig, logging::set_up_logging}; | ||
|
|
||
| /// Command-line arguments for the execution manager. | ||
| #[derive(Debug, Parser)] | ||
| #[command(about = "Run the Spider execution manager.")] | ||
| struct Cli { | ||
| /// Path to the YAML configuration file. | ||
| #[arg(short, long, value_name = "PATH")] | ||
| config: PathBuf, | ||
| } | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<(), Box<dyn Error>> { | ||
| let _log_guard = set_up_logging(); | ||
| let cli = Cli::parse(); | ||
| let config = Config::from_yaml_file(&cli.config) | ||
| .inspect_err(|error| tracing::error!(error = % error, "Failed to load configuration."))?; | ||
|
|
||
| let storage_endpoint = config.storage.endpoint().inspect_err( | ||
| |error| tracing::error!(error = % error, "Failed to parse storage endpoint."), | ||
| )?; | ||
| let scheduler_endpoint = config.scheduler.endpoint().inspect_err( | ||
| |error| tracing::error!(error = % error, "Failed to parse scheduler endpoint."), | ||
| )?; | ||
| let pool_size = config.connection_pool_size; | ||
|
|
||
| let storage_client = GrpcStorageClient::connect(storage_endpoint.clone(), pool_size) | ||
| .await | ||
| .inspect_err( | ||
| |error| tracing::error!(error = % error, "Failed to connect to storage gRPC service."), | ||
| )?; | ||
| let liveness_client = GrpcLivenessClient::connect(storage_endpoint, pool_size) | ||
| .await | ||
| .inspect_err( | ||
| |error| tracing::error!(error = % error, "Failed to connect to liveness gRPC service."), | ||
| )?; | ||
| let scheduler_client = GrpcSchedulerClient::connect(scheduler_endpoint, pool_size).await.inspect_err(|error| tracing::error!(error = % error, "Failed to connect to scheduler gRPC service."))?; | ||
|
|
||
| let (runtime, cancellation_token) = Runtime::create( | ||
| scheduler_client, | ||
| storage_client, | ||
| liveness_client, | ||
| config.runtime_config(), | ||
| ) | ||
| .await | ||
| .inspect_err( | ||
| |error| tracing::error!(error = % error, "Failed to create execution manager runtime."), | ||
| )?; | ||
|
|
||
| let em_id = runtime.get_em_id().get(); | ||
|
|
||
| tracing::info!(em_id, "Execution manager started."); | ||
| let mut run_handle = tokio::spawn(runtime.run()); | ||
|
|
||
| let () = tokio::select! { | ||
| result = tokio::signal::ctrl_c() => { | ||
| if let Err(error) = result { | ||
| tracing::error!(em_id, error = % error, "Failed to listen for Ctrl-C."); | ||
| } | ||
| tracing::info!(em_id, "Received Ctrl-C. Shutting down execution manager."); | ||
| cancellation_token.cancel(); | ||
| run_handle.await | ||
| } | ||
| result = &mut run_handle => { | ||
| tracing::info!("Execution manager runtime exited."); | ||
| result | ||
| } | ||
| } | ||
| .inspect_err( | ||
| |error| tracing::error!(em_id, error = % error, "Execution manager runtime panicked."), | ||
| )? | ||
| .inspect_err( | ||
| |error| tracing::error!(em_id, error = % error, "Execution manager exited on error."), | ||
| )?; | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| use std::{ | ||
| net::IpAddr, | ||
| num::{NonZeroU64, NonZeroUsize}, | ||
| path::PathBuf, | ||
| time::Duration, | ||
| }; | ||
|
|
||
| use serde::Deserialize; | ||
| use spider_utils::config::EndpointConfig; | ||
|
|
||
| use crate::runtime::RuntimeConfig; | ||
|
|
||
| #[derive(Clone, Debug, Deserialize)] | ||
| pub struct Config { | ||
| /// The IP address the execution manager hosts on. | ||
| pub host: IpAddr, | ||
|
|
||
| /// The endpoint of the storage gRPC server. | ||
| pub storage: EndpointConfig, | ||
|
|
||
| /// The endpoint of the scheduler gRPC server. | ||
| pub scheduler: EndpointConfig, | ||
|
|
||
| /// Liveness configuration. | ||
| pub liveness: LivenessConfig, | ||
|
|
||
| /// Task executor configuration. | ||
| pub task_executor: TaskExecutorConfig, | ||
|
|
||
| /// The number of connections each gRPC client pool eagerly establishes. | ||
| /// | ||
| /// Must be greater than zero. | ||
| pub connection_pool_size: NonZeroUsize, | ||
|
|
||
| /// How long, in milliseconds, the scheduler is asked to block each polling request before | ||
| /// returning an empty response on task dispatching. | ||
| pub scheduler_poll_wait_ms: u64, | ||
| } | ||
|
|
||
| impl Config { | ||
| /// Builds the [`RuntimeConfig`] consumed by the runtime from this configuration. | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// The derived [`RuntimeConfig`]. | ||
| #[must_use] | ||
| pub fn runtime_config(&self) -> RuntimeConfig { | ||
| RuntimeConfig { | ||
| em_ip: self.host, | ||
| heartbeat_interval: Duration::from_secs( | ||
| self.liveness.storage_heartbeat_interval_sec.get(), | ||
| ), | ||
| scheduler_heartbeat_interval: Duration::from_secs( | ||
| self.liveness.scheduler_heartbeat_interval_sec.get(), | ||
| ), | ||
| scheduler_poll_wait_ms: self.scheduler_poll_wait_ms, | ||
| executor_binary_path: self.task_executor.bin_path.clone(), | ||
| package_dir: self.task_executor.package_dir.clone(), | ||
| log_dir: self.task_executor.log_dir.clone(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize)] | ||
| pub struct LivenessConfig { | ||
| /// The interval, in seconds, between liveness heartbeats sent to the storage. | ||
| /// | ||
| /// Must be greater than zero. | ||
| pub storage_heartbeat_interval_sec: NonZeroU64, | ||
|
|
||
| /// The interval, in seconds, between scheduler heartbeats sent to the scheduler. | ||
| /// | ||
| /// Must be greater than zero. | ||
| pub scheduler_heartbeat_interval_sec: NonZeroU64, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize)] | ||
| pub struct TaskExecutorConfig { | ||
| /// Absolute path the `spider-task-executor` binary the process pool spawns. | ||
| pub bin_path: PathBuf, | ||
|
|
||
| /// Directory of TDL packages exposed to executors via `SPIDER_TDL_PACKAGE_DIR`. | ||
| pub package_dir: PathBuf, | ||
|
|
||
| /// Directory the process pool writes per-executor stderr logs into. | ||
| pub log_dir: PathBuf, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.