Skip to content
Merged
Changes from all 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
28 changes: 6 additions & 22 deletions objectstore-service/src/backend/counting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,12 @@ use crate::multipart::{
};
use crate::stream::ClientStream;

/// Converts an objectstore `usecase` into the `app_feature` value used by our COGS pipelines.
fn usecase_to_appfeature(usecase: &str) -> &'static str {
// TODO: Flesh out this mapping
match usecase {
"attachments" => "attachments",
"preprod" => "preprod",
_ => {
objectstore_log::warn!(?usecase, "COGS: Can't convert usecase to app_feature");
"shared"
}
}
}

/// Increments `cogs.usage` by one operation for the given `usecase`.
///
/// Under the hood, `usecase` is converted to the appropriate `app_feature` value expected in our
/// COGS pipeline.
/// Under the hood, the `usecase` is used as the `app_feature`. This allows to identify distinct
Comment thread
sentry[bot] marked this conversation as resolved.
/// products and map them in the for the COGs pipeline.
fn count(usecase: &str) {
objectstore_metrics::count!(
"cogs.usage" += 1,
app_feature = usecase_to_appfeature(usecase),
);
objectstore_metrics::count!("cogs.usage" += 1, app_feature = usecase.to_owned());
Comment thread
cursor[bot] marked this conversation as resolved.
}

/// A [`Backend`] decorator that counts each operation performed for COGS. Also implements
Expand Down Expand Up @@ -282,19 +266,19 @@ mod tests {
}

#[test]
fn unmapped_usecase_falls_back_to_shared() {
fn new_usecase_is_app_feature() {
let captured = capture(async {
let backend = CountingBackend::new(Box::new(InMemoryBackend::new("in-memory")));
backend
.get_object(&object_id("unmapped"), None)
.get_object(&object_id("new_usecase"), None)
.await
.unwrap();
});

assert!(
captured
.iter()
.any(|m| m == "cogs.usage:+1|c|#app_feature:shared"),
.any(|m| m == "cogs.usage:+1|c|#app_feature:new_usecase"),
"captured: {captured:?}"
);
}
Expand Down
Loading