Skip to content

Commit

Permalink
Make prometheus_exporter a library
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Jan 14, 2021
1 parent 1ae866f commit 331c544
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 55 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ members = [
"core/bin/zksync_core",
"core/bin/zksync_eth_sender",
"core/bin/zksync_witness_generator",
"core/bin/zksync_prometheus_exporter",

# Libraries
"core/lib/circuit",
"core/lib/eth_client",
"core/lib/eth_signer",
"core/lib/prometheus_exporter",
"core/lib/types",
"core/lib/state",
"core/lib/storage",
Expand Down
3 changes: 3 additions & 0 deletions changelog/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ All notable changes to the core components will be documented in this file.

### Changed

- `prometheus_exporter` was made a library to be used by several crates. `prometheus_exporter` is launched by every
microservice.

### Added

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion core/bin/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ zksync_api = { path = "../zksync_api", version = "1.0" }
zksync_core = { path = "../zksync_core", version = "1.0" }
zksync_witness_generator = { path = "../zksync_witness_generator", version = "1.0" }
zksync_eth_sender = { path = "../zksync_eth_sender", version = "1.0" }
zksync_prometheus_exporter = { path = "../zksync_prometheus_exporter", version = "1.0" }

zksync_prometheus_exporter = { path = "../../lib/prometheus_exporter", version = "1.0" }
zksync_config = { path = "../../lib/config", version = "1.0" }
zksync_storage = { path = "../../lib/storage", version = "1.0" }

Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ zksync_config = { path = "../../lib/config", version = "1.0" }
zksync_utils = { path = "../../lib/utils", version = "1.0" }
zksync_contracts = { path = "../../lib/contracts", version = "1.0" }
zksync_api_client = { path = "../../lib/api_client", version = "0.1" }
zksync_prometheus_exporter = { path = "../../lib/prometheus_exporter", version = "1.0" }

hex = "0.4"
ethabi = "12.0.0"
Expand Down
11 changes: 11 additions & 0 deletions core/bin/zksync_api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use std::cell::RefCell;
use zksync_api::run_api;
use zksync_config::ZkSyncConfig;
use zksync_prometheus_exporter::run_prometheus_exporter;
use zksync_storage::ConnectionPool;

#[tokio::main]
Expand All @@ -20,12 +21,22 @@ async fn main() -> anyhow::Result<()> {
}
let connection_pool = ConnectionPool::new(None);

// Run prometheus data exporter.
let (prometheus_task_handle, counter_task_handle) =
run_prometheus_exporter(connection_pool.clone(), config.api.prometheus.port);

let task_handle = run_api(connection_pool, stop_signal_sender, &config);

tokio::select! {
_ = async { task_handle.await } => {
panic!("API server actors aren't supposed to finish their execution")
},
_ = async { prometheus_task_handle.await } => {
panic!("Prometheus exporter actors aren't supposed to finish their execution")
},
_ = async { counter_task_handle.await } => {
panic!("Operation counting actor is not supposed to finish its execution")
},
_ = async { stop_signal_receiver.next().await } => {
log::warn!("Stop signal received, shutting down");
}
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ zksync_crypto = { path = "../../lib/crypto", version = "1.0" }
zksync_config = { path = "../../lib/config", version = "1.0" }
zksync_utils = { path = "../../lib/utils", version = "1.0" }
zksync_contracts = { path = "../../lib/contracts", version = "1.0" }
zksync_prometheus_exporter = { path = "../../lib/prometheus_exporter", version = "1.0" }

ethabi = "12.0.0"
web3 = "0.13.0"
Expand Down
11 changes: 11 additions & 0 deletions core/bin/zksync_core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use std::cell::RefCell;
use zksync_config::ZkSyncConfig;
use zksync_core::{run_core, wait_for_tasks};
use zksync_prometheus_exporter::run_prometheus_exporter;
use zksync_storage::ConnectionPool;

#[tokio::main]
Expand All @@ -20,6 +21,10 @@ async fn main() -> anyhow::Result<()> {
}
let connection_pool = ConnectionPool::new(None);

// Run prometheus data exporter.
let (prometheus_task_handle, counter_task_handle) =
run_prometheus_exporter(connection_pool.clone(), config.api.prometheus.port);

let task_handles = run_core(connection_pool, stop_signal_sender, &config)
.await
.expect("Unable to start Core actors");
Expand All @@ -28,6 +33,12 @@ async fn main() -> anyhow::Result<()> {
_ = async { wait_for_tasks(task_handles).await } => {
// We don't need to do anything here, since actors will panic upon future resolving.
},
_ = async { prometheus_task_handle.await } => {
panic!("Prometheus exporter actors aren't supposed to finish their execution")
},
_ = async { counter_task_handle.await } => {
panic!("Operation counting actor is not supposed to finish its execution")
},
_ = async { stop_signal_receiver.next().await } => {
log::warn!("Stop signal received, shutting down");
}
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_eth_sender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ zksync_storage = { path = "../../lib/storage", version = "1.0" }
zksync_basic_types = { path = "../../lib/basic_types", version = "1.0" }
zksync_config = { path = "../../lib/config", version = "1.0" }
zksync_contracts = { path = "../../lib/contracts", version = "1.0" }
zksync_prometheus_exporter = { path = "../../lib/prometheus_exporter", version = "1.0" }

hex = "0.4"
ethabi = "12.0.0"
Expand Down
11 changes: 11 additions & 0 deletions core/bin/zksync_eth_sender/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use std::cell::RefCell;
use zksync_config::ZkSyncConfig;
use zksync_eth_sender::run_eth_sender;
use zksync_prometheus_exporter::run_prometheus_exporter;
use zksync_storage::ConnectionPool;

#[tokio::main]
Expand All @@ -25,12 +26,22 @@ async fn main() -> anyhow::Result<()> {
let pool = ConnectionPool::new(Some(ETH_SENDER_CONNECTION_POOL_SIZE));
let config = ZkSyncConfig::from_env();

// Run prometheus data exporter.
let (prometheus_task_handle, counter_task_handle) =
run_prometheus_exporter(pool.clone(), config.api.prometheus.port);

let task_handle = run_eth_sender(pool, config);

tokio::select! {
_ = async { task_handle.await } => {
panic!("Ethereum sender actors aren't supposed to finish their execution")
},
_ = async { prometheus_task_handle.await } => {
panic!("Prometheus exporter actors aren't supposed to finish their execution")
},
_ = async { counter_task_handle.await } => {
panic!("Operation counting actor is not supposed to finish its execution")
},
_ = async { stop_signal_receiver.next().await } => {
log::warn!("Stop signal received, shutting down");
}
Expand Down
44 changes: 0 additions & 44 deletions core/bin/zksync_prometheus_exporter/src/main.rs

This file was deleted.

1 change: 1 addition & 0 deletions core/bin/zksync_witness_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ zksync_crypto = { path = "../../lib/crypto", version = "1.0" }
zksync_config = { path = "../../lib/config", version = "1.0" }
zksync_utils = { path = "../../lib/utils", version = "1.0" }
zksync_prover_utils = { path = "../../lib/prover_utils", version = "1.0" }
zksync_prometheus_exporter = { path = "../../lib/prometheus_exporter", version = "1.0" }

serde = "1.0.90"
serde_json = "1.0.0"
Expand Down
19 changes: 17 additions & 2 deletions core/bin/zksync_witness_generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use std::cell::RefCell;
use zksync_config::ZkSyncConfig;
use zksync_prometheus_exporter::run_prometheus_exporter;
use zksync_storage::ConnectionPool;
use zksync_witness_generator::run_prover_server;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// `eth_sender` doesn't require many connections to the database.
// `witness_generator` doesn't require many connections to the database.
const WITNESS_GENERATOR_CONNECTION_POOL_SIZE: u32 = 2;

env_logger::init();
Expand All @@ -25,9 +26,23 @@ async fn main() -> anyhow::Result<()> {
let connection_pool = ConnectionPool::new(Some(WITNESS_GENERATOR_CONNECTION_POOL_SIZE));
let config = ZkSyncConfig::from_env();

// Run prometheus data exporter.
let (prometheus_task_handle, counter_task_handle) =
run_prometheus_exporter(connection_pool.clone(), config.api.prometheus.port);

run_prover_server(connection_pool, stop_signal_sender, config);

stop_signal_receiver.next().await;
tokio::select! {
_ = async { prometheus_task_handle.await } => {
panic!("Prometheus exporter actors aren't supposed to finish their execution")
},
_ = async { counter_task_handle.await } => {
panic!("Operation counting actor is not supposed to finish its execution")
},
_ = async { stop_signal_receiver.next().await } => {
log::warn!("Stop signal received, shutting down");
}
};

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ categories = ["cryptography"]
publish = false # We don't want to publish our binaries.

[dependencies]
zksync_types = { path = "../../lib/types", version = "1.0" }
zksync_storage = { path = "../../lib/storage", version = "1.0" }
zksync_config = { path = "../../lib/config", version = "1.0" }
zksync_types = { path = "../types", version = "1.0" }
zksync_storage = { path = "../storage", version = "1.0" }
zksync_config = { path = "../config", version = "1.0" }

log = "0.4"
env_logger = "0.6"
Expand All @@ -25,4 +25,3 @@ anyhow = "1.0"

metrics = "0.13.0-alpha.8"
metrics-exporter-prometheus = "0.1.0-alpha.7"

File renamed without changes.
4 changes: 1 addition & 3 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ zkSync repository consists of several applications:
transactions to the L1 smart contract.
- `Witness Generator` service (`core/bin/zksync_witness_generator`) creates input data required for provers to prove
blocks, and implements a private API server for provers to interact with.
- `Prometheus Exporter` service (`core/bin/zksync_prometheus_exporter`) manages exporting data about the application
state for further node behavior analysis.

- Explorer: zkSync network explorer. A web application that receives data from the Server API and renders it to the
convenient blockchain explorer interface.
Expand Down Expand Up @@ -65,14 +63,14 @@ This section provides an overview on folders / sub-projects that exist in this r
- `/zksync_api`: zkSync server API microservice.
- `/zksync_eth_sender`: zkSync server Ethereum sender microservice.
- `/zksync_witness_generator`: zkSync server Witness Generator & Prover Server microservice.
- `/zksync_prometheus_exporter`: zkSync server Prometheus data exporter microservice.
- `/lib`: Dependencies of the binaries above.
- `/basic_types`: Crate with declaration of the essential zkSync primitives, such as `address`.
- `/circuit`: Cryptographic environment enforsing the correctness of executed transactions in the zkSync network.
- `/config`: Utilities to load configuration options of zkSync applications.
- `/contracts`: Loaders for zkSync contracts interfaces and ABI.
- `/crypto`: Cryptographical primitives using among zkSync crates.
- `/eth_client`: Module providing an interface to interact with an Ethereum node.
- `/zksync_prometheus_exporter`: Prometheus data exporter.
- `/prover_utils`: Utilities related to the proof generation.
- `/state`: A fast pre-circuit executor for zkSync transactions used on the Server level to generate blocks.
- `/storage`: An encapsulated database interface.
Expand Down

0 comments on commit 331c544

Please sign in to comment.