Skip to content

Commit 85dfcca

Browse files
authored
ref: Give backends a name (#101)
This introduces a `name` to the generic backends, which we emit as a separate metrics tag now.
1 parent e856aa5 commit 85dfcca

File tree

7 files changed

+59
-19
lines changed

7 files changed

+59
-19
lines changed

objectstore-service/src/backend/bigtable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ impl BigTableBackend {
203203

204204
#[async_trait::async_trait]
205205
impl Backend for BigTableBackend {
206+
fn name(&self) -> &'static str {
207+
"bigtable"
208+
}
209+
206210
async fn put_object(
207211
&self,
208212
path: &ObjectPath,

objectstore-service/src/backend/gcs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ impl fmt::Debug for GcsBackend {
262262

263263
#[async_trait::async_trait]
264264
impl Backend for GcsBackend {
265+
fn name(&self) -> &'static str {
266+
"gcs"
267+
}
268+
265269
async fn put_object(
266270
&self,
267271
path: &ObjectPath,

objectstore-service/src/backend/local_fs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ impl LocalFsBackend {
2828

2929
#[async_trait::async_trait]
3030
impl Backend for LocalFsBackend {
31+
fn name(&self) -> &'static str {
32+
"local-fs"
33+
}
34+
3135
async fn put_object(
3236
&self,
3337
path: &ObjectPath,

objectstore-service/src/backend/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pub type BackendStream = BoxStream<'static, io::Result<Bytes>>;
2222

2323
#[async_trait::async_trait]
2424
pub trait Backend: Debug + Send + Sync + 'static {
25+
/// The backend name, used for diagnostics.
26+
fn name(&self) -> &'static str;
27+
2528
async fn put_object(
2629
&self,
2730
path: &ObjectPath,

objectstore-service/src/backend/s3_compatible.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ impl S3CompatibleBackend<NoToken> {
126126

127127
#[async_trait::async_trait]
128128
impl<T: TokenProvider> Backend for S3CompatibleBackend<T> {
129+
fn name(&self) -> &'static str {
130+
"s3-compatible"
131+
}
132+
129133
async fn put_object(
130134
&self,
131135
path: &ObjectPath,

objectstore-service/src/lib.rs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,38 +114,59 @@ impl StorageService {
114114
}
115115
}
116116

117-
let stored_size = Arc::new(AtomicU64::new(0));
118-
let stream = futures_util::stream::once(async { Ok(first_chunk.into()) })
119-
.chain(stream)
120-
.inspect({
121-
let stored_size = Arc::clone(&stored_size);
122-
move |res| {
123-
if let Ok(chunk) = res {
124-
stored_size.fetch_add(chunk.len() as u64, Ordering::Relaxed);
125-
}
126-
}
127-
})
128-
.boxed();
129-
130-
let backend_tag = match backend {
117+
let (backend_choice, backend_ty, stored_size) = match backend {
131118
BackendChoice::HighVolume => {
119+
let stored_size = first_chunk.len() as u64;
120+
let stream = futures_util::stream::once(async { Ok(first_chunk.into()) }).boxed();
121+
132122
self.0
133123
.high_volume_backend
134124
.put_object(&path, metadata, stream)
135125
.await?;
136-
"high-volume"
126+
(
127+
"high-volume",
128+
self.0.high_volume_backend.name(),
129+
stored_size,
130+
)
137131
}
138132
BackendChoice::LongTerm => {
133+
let stored_size = Arc::new(AtomicU64::new(0));
134+
let stream = futures_util::stream::once(async { Ok(first_chunk.into()) })
135+
.chain(stream)
136+
.inspect({
137+
let stored_size = Arc::clone(&stored_size);
138+
move |res| {
139+
if let Ok(chunk) = res {
140+
stored_size.fetch_add(chunk.len() as u64, Ordering::Relaxed);
141+
}
142+
}
143+
})
144+
.boxed();
145+
139146
self.0
140147
.long_term_backend
141148
.put_object(&path, metadata, stream)
142149
.await?;
143-
"long-term"
150+
(
151+
"long-term",
152+
self.0.long_term_backend.name(),
153+
stored_size.load(Ordering::Acquire),
154+
)
144155
}
145156
};
146157

147-
merni::distribution!("put.latency"@s: start.elapsed(), "usecase" => path.usecase, "backend" => backend_tag);
148-
merni::distribution!("put.size"@b: stored_size.load(Ordering::Acquire), "usecase" => path.usecase, "backend" => backend_tag);
158+
merni::distribution!(
159+
"put.latency"@s: start.elapsed(),
160+
"usecase" => path.usecase,
161+
"backend_choice" => backend_choice,
162+
"backend_type" => backend_ty
163+
);
164+
merni::distribution!(
165+
"put.size"@b: stored_size,
166+
"usecase" => path.usecase,
167+
"backend_choice" => backend_choice,
168+
"backend_type" => backend_ty
169+
);
149170

150171
Ok(path)
151172
}

objectstore-service/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::{self, Display};
33
/// The fully scoped path of an object.
44
///
55
/// This consists of a usecase, the scope, and the user-defined object key.
6-
#[derive(Debug)]
6+
#[derive(Debug, Clone)]
77
pub struct ObjectPath {
88
/// The usecase, or "product" this object belongs to.
99
///

0 commit comments

Comments
 (0)