Skip to content

Commit

Permalink
[ENH]: support export foyer metrics via otel (#3204)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <[email protected]>## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
   - Support otel metrics export

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*

---------

Signed-off-by: MrCroxx <[email protected]>
  • Loading branch information
MrCroxx authored Dec 30, 2024
1 parent 8a3457f commit f83d1c5
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[formatting]
column_width = 65535
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.

15 changes: 1 addition & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
[workspace]
resolver = "2"

members = [
"rust/benchmark",
"rust/blockstore",
"rust/cache",
"rust/chroma",
"rust/config",
"rust/distance",
"rust/error",
"rust/index",
"rust/load",
"rust/storage",
"rust/types",
"rust/worker",
]
members = ["rust/benchmark", "rust/blockstore", "rust/cache", "rust/chroma", "rust/config", "rust/distance", "rust/error", "rust/index", "rust/load", "rust/storage", "rust/types", "rust/worker"]

[workspace.dependencies]
arrow = "52.2.0"
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

0 comments on commit f83d1c5

Please sign in to comment.