2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-11-20 11:21:14 +00:00

Update metrics to 0.22 (plus mechanical changes)

This commit is contained in:
asonix 2023-12-26 18:06:38 -06:00
parent aa7b8d97ee
commit dc90e00324
14 changed files with 64 additions and 68 deletions

38
Cargo.lock generated
View file

@ -280,9 +280,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.76"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59d2a3357dde987206219e78ecfbbb6e8dad06cbb65292758d3270e6254f7355"
checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9"
[[package]]
name = "async-stream"
@ -1379,20 +1379,19 @@ checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "metrics"
version = "0.21.1"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fde3af1a009ed76a778cb84fdef9e7dbbdf5775ae3e4cc1f434a6a307f6f76c5"
checksum = "77b9e10a211c839210fd7f99954bda26e5f8e26ec686ad68da6a32df7c80e782"
dependencies = [
"ahash",
"metrics-macros",
"portable-atomic",
]
[[package]]
name = "metrics-exporter-prometheus"
version = "0.12.2"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d4fa7ce7c4862db464a37b0b31d89bca874562f034bd7993895572783d02950"
checksum = "83a4c4718a371ddfb7806378f23617876eea8b82e5ff1324516bcd283249d9ea"
dependencies = [
"base64 0.21.5",
"hyper",
@ -1405,22 +1404,11 @@ dependencies = [
"tokio",
]
[[package]]
name = "metrics-macros"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.43",
]
[[package]]
name = "metrics-util"
version = "0.15.1"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4de2ed6e491ed114b40b732e4d1659a9d53992ebd87490c44a6ffe23739d973e"
checksum = "2670b8badcc285d486261e2e9f1615b506baff91427b61bd336a472b65bbf5ed"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
@ -1949,9 +1937,9 @@ dependencies = [
[[package]]
name = "quanta"
version = "0.11.1"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a17e662a7a8291a865152364c20c7abc5e60486ab2001e8ec10b24862de0b9ab"
checksum = "577c55a090a94ed7da0e6580cc38a553558e2d736398b5d8ebf81bc9880f8acd"
dependencies = [
"crossbeam-utils",
"libc",
@ -2014,11 +2002,11 @@ dependencies = [
[[package]]
name = "raw-cpuid"
version = "10.7.0"
version = "11.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332"
checksum = "9d86a7c4638d42c44551f4791a20e687dbb4c3de1f33c43dd71e355cd429def1"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.4.1",
]
[[package]]

View file

@ -35,8 +35,8 @@ flume = "0.11.0"
futures-core = "0.3"
hex = "0.4.3"
md-5 = "0.10.5"
metrics = "0.21.1"
metrics-exporter-prometheus = { version = "0.12.1", default-features = false, features = ["http-listener"] }
metrics = "0.22.0"
metrics-exporter-prometheus = { version = "0.13.0", default-features = false, features = ["http-listener"] }
mime = "0.3.1"
opentelemetry_sdk = { version = "0.21", features = ["rt-tokio"] }
opentelemetry = { version = "0.21" }

View file

@ -70,7 +70,8 @@ impl Drop for Backgrounded {
fn drop(&mut self) {
let any_items = self.identifier.is_some() || self.upload_id.is_some();
metrics::increment_counter!("pict-rs.background.upload", "completed" => (!any_items).to_string());
metrics::counter!("pict-rs.background.upload", "completed" => (!any_items).to_string())
.increment(1);
if any_items {
let cleanup_parent_span =

View file

@ -57,7 +57,7 @@ impl ProcessMap {
completed = &tracing::field::Empty,
);
metrics::increment_counter!("pict-rs.process-map.inserted");
metrics::counter!("pict-rs.process-map.inserted").increment(1);
(CancelState::Sender { sender }, span)
}
@ -142,7 +142,7 @@ where
let res = std::task::ready!(fut.poll(cx));
if process_map.remove(key).is_some() {
metrics::increment_counter!("pict-rs.process-map.removed");
metrics::counter!("pict-rs.process-map.removed").increment(1);
}
if let Ok(tup) = &res {
@ -165,7 +165,7 @@ impl Drop for CancelToken {
self.span.record("completed", completed);
if !completed {
metrics::increment_counter!("pict-rs.process-map.removed");
metrics::counter!("pict-rs.process-map.removed").increment(1);
}
}
}

View file

@ -100,6 +100,7 @@ where
impl Drop for Metrics {
fn drop(&mut self) {
metrics::histogram!(self.name, self.start.elapsed().as_secs_f64(), "complete" => self.complete.to_string());
metrics::histogram!(self.name, "complete" => self.complete.to_string())
.record(self.start.elapsed().as_secs_f64());
}
}

View file

@ -27,7 +27,7 @@ struct MetricsGuard {
impl MetricsGuard {
fn guard() -> Self {
metrics::increment_counter!("pict-rs.generate.start");
metrics::counter!("pict-rs.generate.start").increment(1);
Self {
start: Instant::now(),
armed: true,
@ -41,8 +41,10 @@ impl MetricsGuard {
impl Drop for MetricsGuard {
fn drop(&mut self) {
metrics::histogram!("pict-rs.generate.duration", self.start.elapsed().as_secs_f64(), "completed" => (!self.armed).to_string());
metrics::increment_counter!("pict-rs.generate.end", "completed" => (!self.armed).to_string());
metrics::histogram!("pict-rs.generate.duration", "completed" => (!self.armed).to_string())
.record(self.start.elapsed().as_secs_f64());
metrics::counter!("pict-rs.generate.end", "completed" => (!self.armed).to_string())
.increment(1);
}
}

View file

@ -291,7 +291,8 @@ impl Drop for Session {
fn drop(&mut self) {
let any_items = self.hash.is_some() || self.alias.is_some() || self.identifier.is_some();
metrics::increment_counter!("pict-rs.ingest.end", "completed" => (!any_items).to_string());
metrics::counter!("pict-rs.ingest.end", "completed" => (!any_items).to_string())
.increment(1);
if self.hash.is_some() || self.alias.is_some() | self.identifier.is_some() {
let cleanup_parent_span = tracing::info_span!(parent: None, "Dropped session cleanup");

View file

@ -196,7 +196,7 @@ impl<S: Store + 'static> FormData for Upload<S> {
let client = client.clone();
let config = config.clone();
metrics::increment_counter!("pict-rs.files", "upload" => "inline");
metrics::counter!("pict-rs.files", "upload" => "inline").increment(1);
let span = tracing::info_span!("file-upload", ?filename);
@ -268,7 +268,7 @@ impl<S: Store + 'static> FormData for Import<S> {
let client = client.clone();
let config = config.clone();
metrics::increment_counter!("pict-rs.files", "import" => "inline");
metrics::counter!("pict-rs.files", "import" => "inline").increment(1);
let span = tracing::info_span!("file-import", ?filename);
@ -410,7 +410,7 @@ impl<S: Store + 'static> FormData for BackgroundedUpload<S> {
let repo = (**repo).clone();
let store = (**store).clone();
metrics::increment_counter!("pict-rs.files", "upload" => "background");
metrics::counter!("pict-rs.files", "upload" => "background").increment(1);
let span = tracing::info_span!("file-proxy", ?filename);
@ -500,7 +500,7 @@ async fn claim_upload<S: Store + 'static>(
Ok(wait_res) => {
let upload_result = wait_res?;
repo.claim(upload_id).await?;
metrics::increment_counter!("pict-rs.background.upload.claim");
metrics::counter!("pict-rs.background.upload.claim").increment(1);
match upload_result {
UploadResult::Success { alias, token } => {
@ -607,7 +607,7 @@ async fn do_download_inline<S: Store + 'static>(
client: &ClientWithMiddleware,
config: web::Data<Configuration>,
) -> Result<HttpResponse, Error> {
metrics::increment_counter!("pict-rs.files", "download" => "inline");
metrics::counter!("pict-rs.files", "download" => "inline").increment(1);
let (alias, delete_token, details) =
ingest_inline(stream, tmp_dir, &repo, &store, client, &config).await?;
@ -628,7 +628,7 @@ async fn do_download_backgrounded<S: Store + 'static>(
repo: web::Data<ArcRepo>,
store: web::Data<S>,
) -> Result<HttpResponse, Error> {
metrics::increment_counter!("pict-rs.files", "download" => "background");
metrics::counter!("pict-rs.files", "download" => "background").increment(1);
let backgrounded = Backgrounded::proxy((**repo).clone(), (**store).clone(), stream).await?;

View file

@ -26,7 +26,8 @@ struct MetricsGuardWithStatus {
impl MetricsGuard {
fn new(matched_path: Option<String>) -> Self {
metrics::increment_counter!("pict-rs.request.start", "path" => format!("{matched_path:?}"));
metrics::counter!("pict-rs.request.start", "path" => format!("{matched_path:?}"))
.increment(1);
Self {
start: Instant::now(),
@ -49,16 +50,16 @@ impl MetricsGuard {
impl Drop for MetricsGuard {
fn drop(&mut self) {
if self.armed {
metrics::increment_counter!("pict-rs.request.complete", "path" => format!("{:?}", self.matched_path));
metrics::histogram!("pict-rs.request.timings", self.start.elapsed().as_secs_f64(), "path" => format!("{:?}", self.matched_path))
metrics::counter!("pict-rs.request.complete", "path" => format!("{:?}", self.matched_path)).increment(1);
metrics::histogram!("pict-rs.request.timings", "path" => format!("{:?}", self.matched_path)).record(self.start.elapsed().as_secs_f64());
}
}
}
impl Drop for MetricsGuardWithStatus {
fn drop(&mut self) {
metrics::increment_counter!("pict-rs.request.complete", "path" => format!("{:?}", self.matched_path), "status" => self.status.to_string());
metrics::histogram!("pict-rs.request.timings", self.start.elapsed().as_secs_f64(), "path" => format!("{:?}", self.matched_path), "status" => self.status.to_string());
metrics::counter!("pict-rs.request.complete", "path" => format!("{:?}", self.matched_path), "status" => self.status.to_string()).increment(1);
metrics::histogram!("pict-rs.request.timings", "path" => format!("{:?}", self.matched_path), "status" => self.status.to_string()).record(self.start.elapsed().as_secs_f64());
}
}

View file

@ -27,7 +27,7 @@ struct MetricsGuard {
impl MetricsGuard {
fn guard(command: Arc<str>) -> Self {
metrics::increment_counter!("pict-rs.process.start", "command" => command.to_string());
metrics::counter!("pict-rs.process.start", "command" => command.to_string()).increment(1);
Self {
start: Instant::now(),
@ -45,12 +45,12 @@ impl Drop for MetricsGuard {
fn drop(&mut self) {
metrics::histogram!(
"pict-rs.process.duration",
self.start.elapsed().as_secs_f64(),
"command" => self.command.to_string(),
"completed" => (!self.armed).to_string(),
);
)
.record(self.start.elapsed().as_secs_f64());
metrics::increment_counter!("pict-rs.process.end", "completed" => (!self.armed).to_string() , "command" => self.command.to_string());
metrics::counter!("pict-rs.process.end", "completed" => (!self.armed).to_string() , "command" => self.command.to_string()).increment(1);
}
}

View file

@ -233,7 +233,7 @@ struct MetricsGuard {
impl MetricsGuard {
fn guard(worker_id: uuid::Uuid, queue: &'static str) -> Self {
metrics::increment_counter!("pict-rs.job.start", "queue" => queue, "worker-id" => worker_id.to_string());
metrics::counter!("pict-rs.job.start", "queue" => queue, "worker-id" => worker_id.to_string()).increment(1);
Self {
worker_id,
@ -250,8 +250,8 @@ impl MetricsGuard {
impl Drop for MetricsGuard {
fn drop(&mut self) {
metrics::histogram!("pict-rs.job.duration", self.start.elapsed().as_secs_f64(), "queue" => self.queue, "worker-id" => self.worker_id.to_string(), "completed" => (!self.armed).to_string());
metrics::increment_counter!("pict-rs.job.end", "queue" => self.queue, "worker-id" => self.worker_id.to_string(), "completed" => (!self.armed).to_string());
metrics::histogram!("pict-rs.job.duration", "queue" => self.queue, "worker-id" => self.worker_id.to_string(), "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64());
metrics::counter!("pict-rs.job.end", "queue" => self.queue, "worker-id" => self.worker_id.to_string(), "completed" => (!self.armed).to_string()).increment(1);
}
}

View file

@ -100,8 +100,8 @@ impl UploadGuard {
impl Drop for UploadGuard {
fn drop(&mut self) {
metrics::increment_counter!("pict-rs.background.upload.ingest", "completed" => (!self.armed).to_string());
metrics::histogram!("pict-rs.background.upload.ingest.duration", self.start.elapsed().as_seconds_f64(), "completed" => (!self.armed).to_string());
metrics::counter!("pict-rs.background.upload.ingest", "completed" => (!self.armed).to_string()).increment(1);
metrics::histogram!("pict-rs.background.upload.ingest.duration", "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_seconds_f64());
if self.armed {
tracing::warn!(

View file

@ -55,20 +55,21 @@ impl WaitMetricsGuard {
impl Drop for PushMetricsGuard {
fn drop(&mut self) {
metrics::increment_counter!("pict-rs.queue.push", "completed" => (!self.armed).to_string(), "queue" => self.queue);
metrics::counter!("pict-rs.queue.push", "completed" => (!self.armed).to_string(), "queue" => self.queue).increment(1);
}
}
impl Drop for PopMetricsGuard {
fn drop(&mut self) {
metrics::histogram!("pict-rs.queue.pop.duration", self.start.elapsed().as_secs_f64(), "completed" => (!self.armed).to_string(), "queue" => self.queue);
metrics::increment_counter!("pict-rs.queue.pop", "completed" => (!self.armed).to_string(), "queue" => self.queue);
metrics::histogram!("pict-rs.queue.pop.duration", "completed" => (!self.armed).to_string(), "queue" => self.queue).record(self.start.elapsed().as_secs_f64());
metrics::counter!("pict-rs.queue.pop", "completed" => (!self.armed).to_string(), "queue" => self.queue).increment(1);
}
}
impl Drop for WaitMetricsGuard {
fn drop(&mut self) {
metrics::histogram!("pict-rs.upload.wait.duration", self.start.elapsed().as_secs_f64(), "completed" => (!self.armed).to_string());
metrics::increment_counter!("pict-rs.upload.wait", "completed" => (!self.armed).to_string());
metrics::histogram!("pict-rs.upload.wait.duration", "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64());
metrics::counter!("pict-rs.upload.wait", "completed" => (!self.armed).to_string())
.increment(1);
}
}

View file

@ -182,11 +182,11 @@ impl PostgresRepo {
.create_timeout(Some(Duration::from_secs(2)))
.recycle_timeout(Some(Duration::from_secs(2)))
.post_create(Hook::sync_fn(|_, _| {
metrics::increment_counter!("pict-rs.postgres.pool.connection.create");
metrics::counter!("pict-rs.postgres.pool.connection.create").increment(1);
Ok(())
}))
.post_recycle(Hook::sync_fn(|_, _| {
metrics::increment_counter!("pict-rs.postgres.pool.connection.recycle");
metrics::counter!("pict-rs.postgres.pool.connection.recycle").increment(1);
Ok(())
}))
.max_size(parallelism * 8)
@ -238,8 +238,9 @@ impl GetConnectionMetricsGuard {
impl Drop for GetConnectionMetricsGuard {
fn drop(&mut self) {
metrics::increment_counter!("pict-rs.postgres.pool.get", "completed" => (!self.armed).to_string());
metrics::histogram!("pict-rs.postgres.pool.get.duration", self.start.elapsed().as_secs_f64(), "completed" => (!self.armed).to_string());
metrics::counter!("pict-rs.postgres.pool.get", "completed" => (!self.armed).to_string())
.increment(1);
metrics::histogram!("pict-rs.postgres.pool.get.duration", "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64());
}
}
@ -321,7 +322,7 @@ impl<'a> JobNotifierState<'a> {
.or_insert_with(crate::sync::notify)
.notify_one();
metrics::increment_counter!("pict-rs.postgres.job-notifier.notified", "queue" => queue_name.to_string());
metrics::counter!("pict-rs.postgres.job-notifier.notified", "queue" => queue_name.to_string()).increment(1);
}
}
@ -339,7 +340,7 @@ impl<'a> UploadNotifierState<'a> {
.and_then(|weak| weak.upgrade())
{
notifier.notify_waiters();
metrics::increment_counter!("pict-rs.postgres.upload-notifier.notified");
metrics::counter!("pict-rs.postgres.upload-notifier.notified").increment(1);
}
}
}
@ -363,7 +364,7 @@ async fn delegate_notifications(
let upload_notifier_state = UploadNotifierState { inner: &inner };
while let Ok(notification) = receiver.recv_async().await {
metrics::increment_counter!("pict-rs.postgres.notification");
metrics::counter!("pict-rs.postgres.notification").increment(1);
match notification.channel() {
"queue_status_channel" => {