Skip to content

Commit

Permalink
feat: Expose component configs as info metrics (#1584)
Browse files Browse the repository at this point in the history
## What ❔

- Exposes configs of various components as info metrics
[defined](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#info)
in the Open Metrics standard.
- Reworks mempool cache to be shared between API servers.

## Why ❔

- More idiomatic and observable than printing these configs to logs (or
not observing at all).
- Allows to use configs in Grafana dashboards, alerts etc.
- The mempool cache makes sense to share logically, and if multiple
instances are used, reported metrics can be bogus.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
slowli committed Apr 10, 2024
1 parent 713f56b commit 7c8ae40
Show file tree
Hide file tree
Showing 30 changed files with 669 additions and 242 deletions.
8 changes: 7 additions & 1 deletion .github/release-please/config.json
Expand Up @@ -7,7 +7,13 @@
"packages": {
"core": {
"release-type": "simple",
"component": "core"
"component": "core",
"extra-files": [
{
"type": "generic",
"path": "bin/external_node/Cargo.toml"
}
]
},
"prover": {
"release-type": "simple",
Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -120,6 +120,7 @@ regex = "1"
reqwest = "0.11"
rlp = "0.5"
rocksdb = "0.21.0"
rustc_version = "0.4.0"
secp256k1 = "0.27.0"
semver = "1"
sentry = "0.31"
Expand Down
5 changes: 4 additions & 1 deletion core/bin/external_node/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "zksync_external_node"
version = "0.1.0"
version = "22.1.0" # x-release-please-version
edition.workspace = true
authors.workspace = true
homepage.workspace = true
Expand Down Expand Up @@ -44,3 +44,6 @@ clap = { workspace = true, features = ["derive"] }
serde_json.workspace = true
semver.workspace = true
tracing.workspace = true

[build-dependencies]
rustc_version.workspace = true
46 changes: 46 additions & 0 deletions core/bin/external_node/build.rs
@@ -0,0 +1,46 @@
//! Build script for the external node binary.

use std::{
env, fs,
io::{self, Write},
path::Path,
};

use rustc_version::{Channel, LlvmVersion};

fn print_rust_meta(out: &mut impl Write, meta: &rustc_version::VersionMeta) -> io::Result<()> {
writeln!(
out,
"pub(crate) const RUSTC_METADATA: RustcMetadata = RustcMetadata {{ \
version: {semver:?}, \
commit_hash: {commit_hash:?}, \
commit_date: {commit_date:?}, \
channel: {channel:?}, \
host: {host:?}, \
llvm: {llvm:?} \
}};",
semver = meta.semver.to_string(),
commit_hash = meta.commit_hash,
commit_date = meta.commit_date,
channel = match meta.channel {
Channel::Dev => "dev",
Channel::Beta => "beta",
Channel::Nightly => "nightly",
Channel::Stable => "stable",
},
host = meta.host,
llvm = meta.llvm_version.as_ref().map(LlvmVersion::to_string),
)
}

fn main() {
let out_dir = env::var("OUT_DIR").expect("`OUT_DIR` env var not set for build script");
let rustc_meta = rustc_version::version_meta().expect("Failed obtaining rustc metadata");

let metadata_module_path = Path::new(&out_dir).join("metadata_values.rs");
let metadata_module =
fs::File::create(metadata_module_path).expect("cannot create metadata module");
let mut metadata_module = io::BufWriter::new(metadata_module);

print_rust_meta(&mut metadata_module, &rustc_meta).expect("failed printing rustc metadata");
}
2 changes: 0 additions & 2 deletions core/bin/external_node/src/config/mod.rs
Expand Up @@ -721,8 +721,6 @@ impl From<ExternalNodeConfig> for InternalApiConfig {
req_entities_limit: config.optional.req_entities_limit,
fee_history_limit: config.optional.fee_history_limit,
filters_disabled: config.optional.filters_disabled,
mempool_cache_update_interval: config.optional.mempool_cache_update_interval(),
mempool_cache_size: config.optional.mempool_cache_size,
dummy_verifier: config.remote.dummy_verifier,
l1_batch_commit_data_generator_mode: config.remote.l1_batch_commit_data_generator_mode,
}
Expand Down

0 comments on commit 7c8ae40

Please sign in to comment.