Skip to content

Commit

Permalink
Merge pull request #423 from dora-rs/metrics-refactoring
Browse files Browse the repository at this point in the history
Metrics refactoring
  • Loading branch information
phil-opp authored Feb 13, 2024
2 parents 96074a5 + 4ca5325 commit 973e991
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
18 changes: 9 additions & 9 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 apis/python/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pyo3 = { workspace = true, features = ["eyre", "abi3-py37"] }
eyre = "0.6"
serde_yaml = "0.8.23"
flume = "0.10.14"
dora-runtime = { workspace = true, features = ["tracing", "python"] }
dora-runtime = { workspace = true, features = ["tracing", "metrics", "python"] }
arrow = { workspace = true, features = ["pyarrow"] }
pythonize = { workspace = true }
futures = "0.3.28"
Expand Down
6 changes: 2 additions & 4 deletions binaries/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ dora-operator-api-types = { workspace = true }
dora-core = { workspace = true }
dora-tracing = { workspace = true, optional = true }
dora-metrics = { workspace = true, optional = true }
opentelemetry = { version = "0.21.0", features = ["metrics"], optional = true }
opentelemetry-system-metrics = { version = "0.1.6", optional = true }
eyre = "0.6.8"
futures = "0.3.21"
futures-concurrency = "7.1.0"
Expand All @@ -37,6 +35,6 @@ aligned-vec = "0.5.0"
[features]
default = ["tracing", "metrics"]
tracing = ["dora-tracing"]
telemetry = ["tracing", "opentelemetry", "tracing-opentelemetry"]
metrics = ["opentelemetry", "opentelemetry-system-metrics", "dora-metrics"]
telemetry = ["tracing", "tracing-opentelemetry"]
metrics = ["dora-metrics"]
python = ["pyo3", "dora-operator-api-python", "pythonize", "arrow/pyarrow"]
16 changes: 2 additions & 14 deletions binaries/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use dora_core::{
daemon_messages::{NodeConfig, RuntimeConfig},
descriptor::OperatorConfig,
};
use dora_metrics::init_meter_provider;
use dora_node_api::{DoraNode, Event};
use eyre::{bail, Context, Result};
use futures::{Stream, StreamExt};
Expand All @@ -14,7 +15,6 @@ use operator::{run_operator, OperatorEvent, StopReason};
#[cfg(feature = "tracing")]
use dora_tracing::set_up_tracing;
use std::{
borrow::Cow,
collections::{BTreeMap, BTreeSet, HashMap},
mem,
};
Expand Down Expand Up @@ -123,19 +123,7 @@ async fn run(
init_done: oneshot::Receiver<Result<()>>,
) -> eyre::Result<()> {
#[cfg(feature = "metrics")]
let _started = {
use dora_metrics::init_metrics;
use opentelemetry::global;
use opentelemetry_system_metrics::init_process_observer;

let _started = init_metrics().context("Could not create opentelemetry meter")?;
let meter = global::meter(Cow::Borrowed(Box::leak(
config.node_id.to_string().into_boxed_str(),
)));
init_process_observer(meter).context("could not initiale system metrics observer")?;
_started
};

let _meter_provider = init_meter_provider(config.node_id.to_string());
init_done
.await
.wrap_err("the `init_done` channel was closed unexpectedly")?
Expand Down
4 changes: 3 additions & 1 deletion libraries/extensions/telemetry/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ license.workspace = true
[dependencies]
opentelemetry = { version = "0.21", features = ["metrics"] }
opentelemetry-otlp = { version = "0.14.0", features = ["tonic", "metrics"] }
opentelemetry_sdk = { version = "0.21.0", features = ["rt-tokio", "metrics"] }
opentelemetry_sdk = { version = "0.21", features = ["rt-tokio", "metrics"] }
eyre = "0.6.12"
opentelemetry-system-metrics = { version = "0.1.6" }
15 changes: 13 additions & 2 deletions libraries/extensions/telemetry/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
//! [`sysinfo`]: https://github.com/GuillaumeGomez/sysinfo
//! [`opentelemetry-rust`]: https://github.com/open-telemetry/opentelemetry-rust
use opentelemetry::metrics::{self};
use opentelemetry_sdk::{metrics::MeterProvider, runtime};
use std::time::Duration;

use eyre::{Context, Result};
use opentelemetry::metrics::{self, MeterProvider as _};
use opentelemetry_otlp::{ExportConfig, WithExportConfig};
use opentelemetry_sdk::{metrics::MeterProvider, runtime};
use opentelemetry_system_metrics::init_process_observer;
/// Init opentelemetry meter
///
/// Use the default Opentelemetry exporter with default config
Expand All @@ -34,5 +37,13 @@ pub fn init_metrics() -> metrics::Result<MeterProvider> {
.tonic()
.with_export_config(export_config),
)
.with_period(Duration::from_secs(10))
.build()
}

pub fn init_meter_provider(meter_id: String) -> Result<MeterProvider> {
let meter_provider = init_metrics().context("Could not create opentelemetry meter")?;
let meter = meter_provider.meter(meter_id);
let _ = init_process_observer(meter).context("could not initiale system metrics observer")?;
Ok(meter_provider)
}

0 comments on commit 973e991

Please sign in to comment.