Skip to content

Commit

Permalink
blockscout-service-launcher: Add features for each module (#529)
Browse files Browse the repository at this point in the history
* Split launcher crate on 'database', 'launcher', and 'tracing' features

* Bump 'tonic' to 0.9, 'opentelemetry' to 0.19, 'opentelemetry-jaeger' to 0.18, 'tracing-opentelemetry' to 0.19

* Sort dependencies

* Bump to 0.8.0
  • Loading branch information
rimrakhimov authored Sep 4, 2023
1 parent 45989be commit dca3405
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 76 deletions.
79 changes: 57 additions & 22 deletions libs/blockscout-service-launcher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blockscout-service-launcher"
version = "0.7.1"
version = "0.8.0"
description = "Allows to launch blazingly fast blockscout rust services"
license = "MIT"
repository = "https://github.com/blockscout/blockscout-rs"
Expand All @@ -11,32 +11,67 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"] }
actix-web = "4"
actix-web-prom = "0.6"
cfg-if = "1.0.0"
tracing = "0.1"
tonic = "0.8"
futures = "0.3"
prometheus = "0.13"
opentelemetry = { version = "0.18", features = ["rt-tokio"] }
opentelemetry-jaeger = { version = "0.17", features = ["rt-tokio"] }
tracing-opentelemetry = "0.18"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
anyhow = "1.0"
tokio = { version = "1", features = ["rt-multi-thread"] }
actix-web = { version = "4", optional = true }
actix-web-prom = { version = "0.6", optional = true }
anyhow = { version = "1.0", optional = true }
futures = { version = "0.3", optional = true }
cfg-if = { version = "1.0.0", optional = true }
opentelemetry = { version = "0.19", optional = true }
opentelemetry-jaeger = { version = "0.18", features = ["rt-tokio"], optional = true }
prometheus = { version = "0.13", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
tokio = { version = "1", optional = true }
tonic = { version = ">= 0.8, < 0.10", optional = true }
tracing = { version = "0.1", optional = true }
tracing-opentelemetry = { version = "0.19", optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"], optional = true }
url = { version = "2.3.1", optional = true }

# Dependencies required for database initialization

sea-orm-0_11 = { package = "sea-orm", version = "0.11", optional = true }
sea-orm-migration-0_11 = { package = "sea-orm-migration", version = "0.11", optional = true }

sea-orm-0_10 = { package = "sea-orm", version = "0.10", optional = true }
sea-orm-migration-0_10 = { package = "sea-orm-migration", version = "0.10", optional = true }

url = { version = "2.3.1", optional = true }
sea-orm-0_11 = { package = "sea-orm", version = "0.11", optional = true }
sea-orm-migration-0_11 = { package = "sea-orm-migration", version = "0.11", optional = true }

[features]
database = ["url"]
database-0_11 = ["sea-orm-0_11", "sea-orm-migration-0_11", "database"]
database-0_10 = ["sea-orm-0_10", "sea-orm-migration-0_10", "database"]
default = ["launcher", "tracing"]
launcher = [
"dep:actix-web",
"dep:actix-web-prom",
"dep:anyhow",
"dep:futures",
"dep:prometheus",
"dep:serde",
"dep:tokio",
"dep:tonic",
"dep:tracing",
]
tracing = [
"dep:anyhow",
"dep:opentelemetry",
"dep:opentelemetry-jaeger",
"dep:serde",
"dep:tracing-opentelemetry",
"dep:tracing-subscriber",
]

# Cannot be used without corresponding sea-orm dependency.
# Choose any of `database-0_10`, `database-0_11` for the actual usage.
database = [
"dep:anyhow",
"dep:cfg-if",
"dep:tracing",
"dep:url",
]
database-0_10 = [
"database",
"dep:sea-orm-0_10",
"dep:sea-orm-migration-0_10",
]
database-0_11 = [
"database",
"dep:sea-orm-0_11",
"dep:sea-orm-migration-0_11",
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{
use super::{
metrics::Metrics,
router::{configure_router, HttpRouter},
settings::{MetricsSettings, ServerSettings},
Expand Down
8 changes: 8 additions & 0 deletions libs/blockscout-service-launcher/src/launcher/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod launch;
mod metrics;
mod router;
mod settings;

pub use launch::{launch, LaunchSettings};
pub use router::HttpRouter;
pub use settings::*;
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,3 @@ impl Default for MetricsSettings {
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TracingFormat {
Default,
Json,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct TracingSettings {
/// If disabled, tracing is not initialized for neither
/// stdout, nor jaeger (enabled by default).
pub enabled: bool,
pub format: TracingFormat,
}

impl Default for TracingSettings {
fn default() -> Self {
Self {
enabled: true,
format: TracingFormat::Default,
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct JaegerSettings {
pub enabled: bool,
pub agent_endpoint: String,
}

impl Default for JaegerSettings {
fn default() -> Self {
Self {
enabled: false,
agent_endpoint: "127.0.0.1:6831".to_string(),
}
}
}
17 changes: 6 additions & 11 deletions libs/blockscout-service-launcher/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
mod launch;
mod metrics;
mod router;
mod settings;
mod tracing;

pub use crate::tracing::init_logs;
pub use launch::{launch, LaunchSettings};
pub use router::HttpRouter;
pub use settings::*;

#[cfg(feature = "database")]
pub mod database;

#[cfg(feature = "launcher")]
pub mod launcher;

#[cfg(feature = "tracing")]
pub mod tracing;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{JaegerSettings, TracingFormat, TracingSettings};
use super::{JaegerSettings, TracingFormat, TracingSettings};
use opentelemetry::{
global::{self},
sdk::{self, propagation::TraceContextPropagator},
Expand Down
5 changes: 5 additions & 0 deletions libs/blockscout-service-launcher/src/tracing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod init;
mod settings;

pub use init::*;
pub use settings::*;
42 changes: 42 additions & 0 deletions libs/blockscout-service-launcher/src/tracing/settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TracingFormat {
Default,
Json,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct TracingSettings {
/// If disabled, tracing is not initialized for neither
/// stdout, nor jaeger (enabled by default).
pub enabled: bool,
pub format: TracingFormat,
}

impl Default for TracingSettings {
fn default() -> Self {
Self {
enabled: true,
format: TracingFormat::Default,
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct JaegerSettings {
pub enabled: bool,
pub agent_endpoint: String,
}

impl Default for JaegerSettings {
fn default() -> Self {
Self {
enabled: false,
agent_endpoint: "127.0.0.1:6831".to_string(),
}
}
}

0 comments on commit dca3405

Please sign in to comment.