use crate::split_ctx::PoisonKind;
use spate_core::metrics::{Counter, Gauge, Meter};
#[derive(Clone)]
pub(crate) struct S3Metrics {
pub(crate) objects_listed: Counter,
pub(crate) objects_completed: Counter,
pub(crate) objects_remaining: Gauge,
pub(crate) bytes_read: Counter,
pub(crate) bytes_decoded: Counter,
pub(crate) get_retries: Counter,
objects_failed_not_found: Counter,
objects_failed_etag_drift: Counter,
objects_failed_undecodable: Counter,
objects_failed_retries_exhausted: Counter,
}
impl std::fmt::Debug for S3Metrics {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("S3Metrics")
}
}
impl S3Metrics {
pub(crate) fn new(meter: &Meter) -> S3Metrics {
let failed = |reason: &'static str| {
meter.counter("objects_failed_total", &[("reason", reason.into())])
};
S3Metrics {
objects_listed: meter.counter("objects_listed_total", &[]),
objects_completed: meter.counter("objects_completed_total", &[]),
objects_remaining: meter.gauge("objects_remaining", &[]),
bytes_read: meter.counter("bytes_read_total", &[]),
bytes_decoded: meter.counter("bytes_decoded_total", &[]),
get_retries: meter.counter("get_retries_total", &[]),
objects_failed_not_found: failed(PoisonKind::NotFound.reason_label()),
objects_failed_etag_drift: failed(PoisonKind::EtagDrift.reason_label()),
objects_failed_undecodable: failed(PoisonKind::Undecodable.reason_label()),
objects_failed_retries_exhausted: failed(PoisonKind::RetriesExhausted.reason_label()),
}
}
pub(crate) fn objects_failed(&self, kind: PoisonKind) -> &Counter {
match kind {
PoisonKind::NotFound => &self.objects_failed_not_found,
PoisonKind::EtagDrift => &self.objects_failed_etag_drift,
PoisonKind::Undecodable => &self.objects_failed_undecodable,
PoisonKind::RetriesExhausted => &self.objects_failed_retries_exhausted,
}
}
}