Skip to content
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

[ENH]: support export foyer metrics via otel #3204

Merged
merged 6 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 70 additions & 65 deletions Cargo.lock

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

12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ figment = { version = "0.10.12", features = ["env", "yaml", "test"] }
flatbuffers = "24.3.25"
futures = "0.3"
num_cpus = "1.16.0"
opentelemetry = { version = "0.27.0", default-features = false, features = ["trace", "metrics"] }
opentelemetry = { version = "0.27.0", default-features = false, features = [
"trace",
"metrics",
] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep these to one line so sort on the deps is feasible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

BTW, I introduced a configuration file for taplo (which is used by VS code "Even Better Toml" and command line tool "taplo", the tools are mostly used to format .toml file in the Rust community).

Copy link
Contributor Author

@MrCroxx MrCroxx Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also enable the validator in CI. IMHO, using a tool for formatting and validating is always better than human reviewing.

FYI - taplo: https://taplo.tamasfe.dev/

opentelemetry-otlp = "0.27"
opentelemetry_sdk = { version = "0.27", features = ["rt-tokio"] }
parking_lot = { version = "0.12.3", features = ["serde"] }
Expand All @@ -44,7 +47,12 @@ tracing = "0.1"
tracing-bunyan-formatter = "0.3"
tracing-opentelemetry = "0.28.0"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
uuid = { version = "1.11.0", features = ["v4", "fast-rng", "macro-diagnostics", "serde"] }
uuid = { version = "1.11.0", features = [
"v4",
"fast-rng",
"macro-diagnostics",
"serde",
] }

chroma-benchmark = { path = "rust/benchmark" }
chroma-blockstore = { path = "rust/blockstore" }
Expand Down
2 changes: 1 addition & 1 deletion rust/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ path = "src/lib.rs"

[dependencies]
clap = { workspace = true }
foyer = "0.12"
foyer = { version = "0.13.1", features = ["opentelemetry_0_27", "tracing"] }
anyhow = "1.0"
opentelemetry = { version = "0.27.0", default-features = false, features = [
"trace",
Expand Down
9 changes: 6 additions & 3 deletions rust/cache/src/foyer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{CacheError, Weighted};
use chroma_error::ChromaError;
use clap::Parser;
use foyer::opentelemetry_0_27::OpenTelemetryMetricsRegistry;
use foyer::{
CacheBuilder, DirectFsDeviceOptions, Engine, FifoConfig, FifoPicker, HybridCacheBuilder,
InvalidRatioPicker, LargeEngineOptions, LfuConfig, LruConfig, RateLimitPicker, S3FifoConfig,
Expand Down Expand Up @@ -272,6 +273,7 @@ where
.with_record_hybrid_fetch_threshold(Duration::from_micros(config.trace_fetch_us as _));

let builder = HybridCacheBuilder::<K, V>::new()
.with_metrics_registry(OpenTelemetryMetricsRegistry::new(global::meter("chroma")))
.with_tracing_options(tracing_options)
.memory(config.mem)
.with_shards(config.shards);
Expand Down Expand Up @@ -457,13 +459,14 @@ where
type Key = K;
type Value = V;

fn on_memory_release(&self, key: Self::Key, value: Self::Value)
fn on_leave(&self, _: foyer::Event, key: &Self::Key, value: &Self::Value)
where
K: Clone + Send + Sync + Eq + PartialEq + Hash + 'static,
Self::Key: foyer::Key,
Self::Value: foyer::Value,
{
// NOTE(rescrv): There's no mechanism by which we can error. We could log a
// metric, but this should really never happen.
let _ = self.0.send((key, value));
let _ = self.0.send((key.clone(), value.clone()));
}
}
let evl = TokioEventListener(tx);
Expand Down
Loading