From 71d81681d55a0e8eaca3e37dbaa82498406cb27d Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 4 Feb 2024 15:45:47 -0600 Subject: [PATCH] It compiles --- src/backgrounded.rs | 2 +- src/concurrent_processor.rs | 6 +- src/ingest.rs | 4 +- src/init_metrics.rs | 281 +++++++++++++++++++++++++++++------- src/lib.rs | 18 ++- src/middleware/payload.rs | 8 +- src/process.rs | 7 +- src/queue.rs | 6 +- src/queue/cleanup.rs | 4 +- src/queue/process.rs | 4 +- src/repo/metrics.rs | 10 +- src/repo/postgres.rs | 4 +- 12 files changed, 265 insertions(+), 89 deletions(-) diff --git a/src/backgrounded.rs b/src/backgrounded.rs index 1585afc..37f8677 100644 --- a/src/backgrounded.rs +++ b/src/backgrounded.rs @@ -71,7 +71,7 @@ impl Drop for Backgrounded { fn drop(&mut self) { let any_items = self.identifier.is_some() || self.upload_id.is_some(); - metrics::counter!("pict-rs.background.upload", "completed" => (!any_items).to_string()) + metrics::counter!(crate::init_metrics::BACKGROUND_UPLOAD, "completed" => (!any_items).to_string()) .increment(1); if any_items { diff --git a/src/concurrent_processor.rs b/src/concurrent_processor.rs index 9d5f147..4a0f9cd 100644 --- a/src/concurrent_processor.rs +++ b/src/concurrent_processor.rs @@ -57,7 +57,7 @@ impl ProcessMap { completed = &tracing::field::Empty, ); - metrics::counter!("pict-rs.process-map.inserted").increment(1); + metrics::counter!(crate::init_metrics::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::counter!("pict-rs.process-map.removed").increment(1); + metrics::counter!(crate::init_metrics::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::counter!("pict-rs.process-map.removed").increment(1); + metrics::counter!(crate::init_metrics::PROCESS_MAP_REMOVED).increment(1); } } } diff --git a/src/ingest.rs b/src/ingest.rs index 5c245ce..69802ae 100644 --- a/src/ingest.rs +++ b/src/ingest.rs @@ -196,7 +196,7 @@ where .body(Body::wrap_stream(crate::stream::make_send(stream))) .send() .instrument(tracing::info_span!("external-validation")) - .with_metrics("pict-rs.ingest.external-validation") + .with_metrics(crate::init_metrics::INGEST_EXTERNAL_VALIDATION) .await?; if !response.status().is_success() { @@ -303,7 +303,7 @@ impl Drop for Session { fn drop(&mut self) { let any_items = self.hash.is_some() || self.alias.is_some() || self.identifier.is_some(); - metrics::counter!("pict-rs.ingest.end", "completed" => (!any_items).to_string()) + metrics::counter!(crate::init_metrics::INGEST_END, "completed" => (!any_items).to_string()) .increment(1); if self.hash.is_some() || self.alias.is_some() | self.identifier.is_some() { diff --git a/src/init_metrics.rs b/src/init_metrics.rs index 1720fd6..18cd2d3 100644 --- a/src/init_metrics.rs +++ b/src/init_metrics.rs @@ -1,10 +1,179 @@ pub(super) fn init_metrics() { + describe_toplevel(); + describe_queue_cleanup(); + describe_payload(); + describe_job(); + describe_queue_process(); + describe_ingest(); + describe_backgrounded(); + describe_concurrent_processor(); + describe_repo(); + describe_process(); describe_postgres(); describe_middleware(); describe_generate(); describe_object_storage(); } +fn describe_toplevel() { + metrics::describe_counter!(FILES, "How many files have been uploaded to pict-rs"); + metrics::describe_counter!( + BACKGROUND_UPLOAD_CLAIM, + "How many uploaded files have been claimed" + ); +} + +pub(crate) const FILES: &str = "pict-rs.files"; +pub(crate) const BACKGROUND_UPLOAD_CLAIM: &str = "pict-rs.background.upload.claim"; + +fn describe_queue_cleanup() { + metrics::describe_counter!( + CLEANUP_OUTDATED_PROXY, + "How many proxy URLs haven't been accessed in the configured timeframe and have been queued for cleanup" + ); + metrics::describe_counter!( + CLEANUP_OUTDATED_VARIANT, + "How many variants haven't been accessed in the configured timeframe and have been queued for cleanup" + ); +} + +pub(crate) const CLEANUP_OUTDATED_PROXY: &str = "pict-rs.cleanup.outdated-proxy"; +pub(crate) const CLEANUP_OUTDATED_VARIANT: &str = "pict-rs.cleanup.outdated-variant"; + +fn describe_payload() { + metrics::describe_counter!( + PAYLOAD_DRAIN_START, + "How many payloads have been dropped before read to completion and need draining" + ); + metrics::describe_counter!( + PAYLOAD_DRAIN_END, + "How many payloads pict-rs has finished draining" + ); + metrics::describe_histogram!( + PAYLOAD_DRAIN_DURATION, + "Timings for how long it took to drain dropped payloads" + ); + metrics::describe_counter!( + PAYLOAD_DRAIN_FAIL_SEND, + "How many payloads pict-rs has failed to drain due to filling the drain queue" + ); +} + +pub(crate) const PAYLOAD_DRAIN_START: &str = "pict-rs.payload.drain.start"; +pub(crate) const PAYLOAD_DRAIN_END: &str = "pict-rs.payload.drain.end"; +pub(crate) const PAYLOAD_DRAIN_DURATION: &str = "pict-rs.payload.drain.duration"; +pub(crate) const PAYLOAD_DRAIN_FAIL_SEND: &str = "pict-rs.payload.drain.fail-send"; + +fn describe_job() { + metrics::describe_counter!( + JOB_START, + "How many times pict-rs has started processing a background job" + ); + metrics::describe_histogram!( + JOB_DURAION, + "Timings for how long background jobs take to complete" + ); + metrics::describe_counter!( + JOB_END, + "How many times pict-rs has completed processing a background-job" + ); +} + +pub(crate) const JOB_START: &str = "pict-rs.job.start"; +pub(crate) const JOB_DURAION: &str = "pict-rs.job.duration"; +pub(crate) const JOB_END: &str = "pict-rs.job.end"; + +fn describe_queue_process() { + metrics::describe_counter!( + PROCESS_START, + "How many times pict-rs has spawned a background process" + ); + metrics::describe_histogram!( + PROCESS_DURATION, + "Timings for how long background processes take to complete" + ); + metrics::describe_counter!(PROCESS_END, "How many background processes have completed"); +} + +pub(crate) const PROCESS_START: &str = "pict-rs.process.start"; +pub(crate) const PROCESS_DURATION: &str = "pict-rs.process.duration"; +pub(crate) const PROCESS_END: &str = "pict-rs.process.end"; + +fn describe_ingest() { + metrics::describe_histogram!( + INGEST_EXTERNAL_VALIDATION, + "Timings for externally validating uploaded media" + ); + metrics::describe_counter!(INGEST_END, "How many times media has been ingested"); +} + +pub(crate) const INGEST_EXTERNAL_VALIDATION: &str = "pict-rs.ingest.external-validation"; +pub(crate) const INGEST_END: &str = "pict-rs.ingest.end"; + +fn describe_backgrounded() { + metrics::describe_counter!( + BACKGROUND_UPLOAD, + "How many times an image has been proxied to storage in the background" + ); +} + +pub(crate) const BACKGROUND_UPLOAD: &str = "pict-rs.background.upload"; + +fn describe_concurrent_processor() { + metrics::describe_counter!( + PROCESS_MAP_INSERTED, + "How many times a task has claimed rights to processing a variant" + ); + metrics::describe_counter!( + PROCESS_MAP_REMOVED, + "How many times a variant has finished processing" + ); +} + +pub(crate) const PROCESS_MAP_INSERTED: &str = "pict-rs.process-map.inserted"; +pub(crate) const PROCESS_MAP_REMOVED: &str = "pict-rs.process-map.removed"; + +fn describe_repo() { + metrics::describe_counter!( + QUEUE_PUSH, + "How many jobs have been pushed into the job queue" + ); + metrics::describe_histogram!( + QUEUE_POP_DURATION, + "Timings for how long it takes to pop a job from the job queue" + ); + metrics::describe_counter!( + QUEUE_POP, + "How many jobs have been popped from the job queue" + ); + metrics::describe_histogram!( + UPLOAD_WAIT_DURATION, + "Timings for how long an upload is waited on" + ); + metrics::describe_counter!(UPLOAD_WAIT, "How many times an upload has been waited on"); +} + +pub(crate) const QUEUE_PUSH: &str = "pict-rs.queue.push"; +pub(crate) const QUEUE_POP_DURATION: &str = "pict-rs.queue.pop.duration"; +pub(crate) const QUEUE_POP: &str = "pict-rs.queue.pop"; +pub(crate) const UPLOAD_WAIT_DURATION: &str = "pict-rs.upload.wait.duration"; +pub(crate) const UPLOAD_WAIT: &str = "pict-rs.upload.wait"; + +fn describe_process() { + metrics::describe_counter!( + BACKGROUND_UPLOAD_INGEST, + "How many files have been ingested in the background" + ); + metrics::describe_histogram!( + BACKGROUND_UPLOAD_INGEST_DURATION, + "Timings for ingesting media in the background" + ); +} + +pub(crate) const BACKGROUND_UPLOAD_INGEST: &str = "pict-rs.background.upload.ingest"; +pub(crate) const BACKGROUND_UPLOAD_INGEST_DURATION: &str = + "pict-rs.background.upload.ingest.duration"; + fn describe_postgres() { metrics::describe_counter!( POSTGRES_POOL_CONNECTION_CREATE, @@ -16,7 +185,7 @@ fn describe_postgres() { ); metrics::describe_counter!( POSTGRES_POOL_GET, - "How many times a connection has been retrieved from the connection pool", + "How many times a connection has been retrieved from the connection pool" ); metrics::describe_histogram!( POSTGRES_POOL_GET_DURATION, @@ -32,7 +201,7 @@ fn describe_postgres() { ); metrics::describe_counter!( POSTGRES_NOTIFICATION, - "How many notifications pict-rs has received from postgres", + "How many notifications pict-rs has received from postgres" ); metrics::describe_histogram!( POSTGRES_HASHES_COUNT, @@ -40,39 +209,39 @@ fn describe_postgres() { ); metrics::describe_histogram!( POSTGRES_HASHES_BOUND, - "Timings for retrieving a timestamp for a given hash", + "Timings for retrieving a timestamp for a given hash" ); metrics::describe_histogram!( POSTGRES_HASHES_ORDERED_HASH, - "Timings for retrieving the most recent hash and timestamp before a provided time", + "Timings for retrieving the most recent hash and timestamp before a provided time" ); metrics::describe_histogram!( POSTGRES_HASHES_NEXT_HASHES, - "Timings for retrieving the next page of hashes given an ordered-hash bound", + "Timings for retrieving the next page of hashes given an ordered-hash bound" ); metrics::describe_histogram!( POSTGRES_HASHES_PREV_HASH, - "Timings for retrieving the hash to act as the next hash page's bound", + "Timings for retrieving the hash to act as the next hash page's bound" ); metrics::describe_histogram!( POSTGRES_HASHES_FIRST_HASHES, - "Timings for retrieving the first page of hashes", + "Timings for retrieving the first page of hashes" ); metrics::describe_histogram!( POSTGRES_HASHES_CREATE_HASH, - "Timings for inserting a new hash", + "Timings for inserting a new hash" ); metrics::describe_histogram!( POSTGRES_HASHES_UPDATE_IDENTIFIER, - "Timings for updating the identifier for a provided hash", + "Timings for updating the identifier for a provided hash" ); metrics::describe_histogram!( POSTGRES_HASHES_IDENTIFIER, - "Timings for fetching the identifier for a provided hash", + "Timings for fetching the identifier for a provided hash" ); metrics::describe_histogram!( POSTGRES_VARIANTS_RELATE_VARIANT_IDENTIFIER, - "Timings for inserting a variant and identifier for a provided hash", + "Timings for inserting a variant and identifier for a provided hash" ); metrics::describe_histogram!( POSTGRES_VARIANTS_IDENTIFIER, @@ -84,43 +253,43 @@ fn describe_postgres() { ); metrics::describe_histogram!( POSTGRES_VARIANTS_REMOVE, - "Timings for removing a variant for a provided hash", + "Timings for removing a variant for a provided hash" ); metrics::describe_histogram!( POSTGRES_HASHES_RELATE_MOTION_IDENTIFIER, - "Timings for relating a still image identifier for a provided hash representing a video", + "Timings for relating a still image identifier for a provided hash representing a video" ); metrics::describe_histogram!( POSTGRES_HASHES_MOTION_IDENTIFIER, - "Timings for fetching a still image identifier for a provided hash representing a video", + "Timings for fetching a still image identifier for a provided hash representing a video" ); metrics::describe_histogram!( POSTGRES_VARIANTS_CLEANUP, - "Timings for deleting all variants for a provided hash", + "Timings for deleting all variants for a provided hash" ); metrics::describe_histogram!( POSTGRES_HASHES_CLEANUP, - "Timings for deleting a provided hash", + "Timings for deleting a provided hash" ); metrics::describe_histogram!( POSTGRES_ALIASES_CREATE, - "Timings for creating an alias for a provided hash", + "Timings for creating an alias for a provided hash" ); metrics::describe_histogram!( POSTGRES_ALIASES_DELETE_TOKEN, - "Timings for fetching a delete token for a provided alias", + "Timings for fetching a delete token for a provided alias" ); metrics::describe_histogram!( POSTGRES_ALIASES_HASH, - "Timings for fetching a hash for a provided alias", + "Timings for fetching a hash for a provided alias" ); metrics::describe_histogram!( POSTGRES_ALIASES_FOR_HASH, - "Timings for fetching all aliases for a provided hash", + "Timings for fetching all aliases for a provided hash" ); metrics::describe_histogram!( POSTGRES_ALIASES_CLEANUP, - "Timings for deleting a provided alias", + "Timings for deleting a provided alias" ); metrics::describe_histogram!(POSTGRES_SETTINGS_SET, "Timings for setting a given setting"); metrics::describe_histogram!( @@ -137,23 +306,23 @@ fn describe_postgres() { ); metrics::describe_histogram!( POSTGRES_DETAILS_GET, - "Timings for getting details for a provided identifier", + "Timings for getting details for a provided identifier" ); metrics::describe_histogram!( POSTGRES_DETAILS_CLEANUP, - "Timings for deleting details for a provided identifier", + "Timings for deleting details for a provided identifier" ); metrics::describe_histogram!( POSTGRES_QUEUE_COUNT, - "Timings for counting the size of the job queue", + "Timings for counting the size of the job queue" ); metrics::describe_histogram!( POSTGRES_QUEUE_PUSH, - "Timings for inserting a new job into the job queue", + "Timings for inserting a new job into the job queue" ); metrics::describe_histogram!( POSTGRES_QUEUE_LISTEN, - "Timings for initializing the queue listener", + "Timings for initializing the queue listener" ); metrics::describe_histogram!( POSTGRES_QUEUE_REQUEUE, @@ -161,7 +330,7 @@ fn describe_postgres() { ); metrics::describe_histogram!( POSTGRES_QUEUE_CLAIM, - "Timings for claiming a job from the job queue", + "Timings for claiming a job from the job queue" ); metrics::describe_histogram!( POSTGRES_QUEUE_HEARTBEAT, @@ -169,19 +338,19 @@ fn describe_postgres() { ); metrics::describe_histogram!( POSTGRES_QUEUE_COMPLETE, - "Timings for removing a completed job from the queue", + "Timings for removing a completed job from the queue" ); metrics::describe_histogram!( POSTGRES_STORE_MIGRATION_COUNT, - "Timings for fetching the count of files successfully migrated between stores", + "Timings for fetching the count of files successfully migrated between stores" ); metrics::describe_histogram!( POSTGRES_STORE_MIGRATION_MARK_MIGRATED, - "Timings for marking a given identifier as having been migrated between stores", + "Timings for marking a given identifier as having been migrated between stores" ); metrics::describe_histogram!( POSTGRES_STORE_MIGRATION_IS_MIGRATED, - "Timings for checking if a given identifier has been migrated between stores", + "Timings for checking if a given identifier has been migrated between stores" ); metrics::describe_histogram!( POSTGRES_STORE_MIGRATION_CLEAR, @@ -189,59 +358,59 @@ fn describe_postgres() { ); metrics::describe_histogram!( POSTGRES_PROXY_RELATE_URL, - "Timings for relating a provided proxy URL to an alias", + "Timings for relating a provided proxy URL to an alias" ); metrics::describe_histogram!( POSTGRES_PROXY_RELATED, - "Timings for fetching a related alias for a provided proxy URL", + "Timings for fetching a related alias for a provided proxy URL" ); metrics::describe_histogram!( POSTGRES_PROXY_REMOVE_RELATION, - "Timings for removing a proxy URL for a provied alias", + "Timings for removing a proxy URL for a provied alias" ); metrics::describe_histogram!( POSTGRES_ALIAS_ACCESS_SET_ACCESSED, - "Timings for marking a given alias as having been accessed", + "Timings for marking a given alias as having been accessed" ); metrics::describe_histogram!( POSTGRES_ALIAS_ACCESS_ACCESSED_AT, - "Timings for checking when a given alias was last accessed", + "Timings for checking when a given alias was last accessed" ); metrics::describe_histogram!( POSTGRES_ALIAS_ACCESS_OLDER_ALIASES, - "Timings for fetching a page of aliases last accessed earlier than a given timestamp", + "Timings for fetching a page of aliases last accessed earlier than a given timestamp" ); metrics::describe_histogram!( POSTGRES_VARIANT_ACCESS_SET_ACCESSED, - "Timings for marking a given variant as having been accessed", + "Timings for marking a given variant as having been accessed" ); metrics::describe_histogram!( POSTGRES_VARIANT_ACCESS_ACCESSED_AT, - "Timings for checking when a given variant was last accessed", + "Timings for checking when a given variant was last accessed" ); metrics::describe_histogram!( POSTGRES_VARIANT_ACCESS_OLDER_VARIANTS, - "Timings for fetching a page of variants last accessed earlier than a given timestamp", + "Timings for fetching a page of variants last accessed earlier than a given timestamp" ); metrics::describe_histogram!( POSTGRES_UPLOADS_CREATE, - "Timings for inserting a new upload ID", + "Timings for inserting a new upload ID" ); metrics::describe_histogram!( POSTGRES_UPLOADS_LISTEN, - "Timings for initializing the upload listener", + "Timings for initializing the upload listener" ); metrics::describe_histogram!( POSTGRES_UPLOADS_WAIT, - "Timings for checking if a given upload is completed", + "Timings for checking if a given upload is completed" ); metrics::describe_histogram!( POSTGRES_UPLOADS_CLAIM, - "Timings for claiming a given completed upload", + "Timings for claiming a given completed upload" ); metrics::describe_histogram!( POSTGRES_UPLOADS_COMPLETE, - "Timings for marking a given upload as completed", + "Timings for marking a given upload as completed" ); } @@ -268,7 +437,7 @@ pub(crate) const POSTGRES_VARIANTS_RELATE_VARIANT_IDENTIFIER: &str = "pict-rs.postgres.variants.relate-variant-identifier"; pub(crate) const POSTGRES_VARIANTS_IDENTIFIER: &str = "pict-rs.postgres.variants.identifier"; pub(crate) const POSTGRES_VARIANTS_FOR_HASH: &str = "pict-rs.postgres.variants.for-hash"; -pub(crate) const POSTGRES_VARIANST_REMOVE: &str = "pict-rs.postgres.variants.remove"; +pub(crate) const POSTGRES_VARIANTS_REMOVE: &str = "pict-rs.postgres.variants.remove"; pub(crate) const POSTGRES_HASHES_RELATE_MOTION_IDENTIFIER: &str = "pict-rs.postgres.hashes.relate-motion-identifier"; pub(crate) const POSTGRES_HASHES_MOTION_IDENTIFIER: &str = @@ -361,37 +530,37 @@ pub(crate) const GENERATE_END: &str = "pict-rs.generate.end"; pub(crate) const GENERATE_PROCESS: &str = "pict-rs.generate.process"; fn describe_object_storage() { - metrics::describe_historgram!( + metrics::describe_histogram!( OBJECT_STORAGE_HEAD_BUCKET_REQUEST, "Timings for HEAD requests for the pict-rs Bucket in object storage" ); - metrics::describe_historgram!( + metrics::describe_histogram!( OBJECT_STORAGE_PUT_OBJECT_REQUEST, "Timings for PUT requests for uploading media to object storage" ); - metrics::describe_historgram!(OBJECT_STORAGE_CREATE_MULTIPART_REQUEST, "Timings for creating a multipart request to object storage. This is the first step in uploading larger files."); - metrics::describe_historgram!(OBJECT_STORAGE_CREATE_UPLOAD_PART_REQUEST, "Timings for uploading part of a large file to object storage as a multipart part. This is one step in uploading larger files."); - metrics::describe_historgram!( + metrics::describe_histogram!(OBJECT_STORAGE_CREATE_MULTIPART_REQUEST, "Timings for creating a multipart request to object storage. This is the first step in uploading larger files."); + metrics::describe_histogram!(OBJECT_STORAGE_CREATE_UPLOAD_PART_REQUEST, "Timings for uploading part of a large file to object storage as a multipart part. This is one step in uploading larger files."); + metrics::describe_histogram!( OBJECT_STORAGE_ABORT_MULTIPART_REQUEST, "Timings for aborting a multipart upload to object storage" ); - metrics::describe_historgram!( + metrics::describe_histogram!( OBJECT_STORAGE_GET_OBJECT_REQUEST, "Timings for requesting media from object storage" ); - metrics::describe_historgram!( + metrics::describe_histogram!( OBJECT_STORAGE_GET_OBJECT_REQUEST_STREAM, "Timings for streaming an object from object storage" ); - metrics::describe_historgram!( + metrics::describe_histogram!( OBJECT_STORAGE_HEAD_OBJECT_REQUEST, "Timings for requesting metadata for media from object storage" ); - metrics::describe_historgram!( + metrics::describe_histogram!( OBJECT_STORAGE_DELETE_OBJECT_REQUEST, "Timings for requesting media in object storage be deleted" ); - metrics::describe_historgram!( + metrics::describe_histogram!( OBJECT_STORAGE_COMPLETE_MULTIPART_REQUEST, "Timings for completing a multipart request to object storage" ); diff --git a/src/lib.rs b/src/lib.rs index 469e930..57cd0ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,7 +173,8 @@ impl FormData for Upload { Field::array(Field::file(move |filename, _, stream| { let state = state.clone(); - metrics::counter!("pict-rs.files", "upload" => "inline").increment(1); + metrics::counter!(crate::init_metrics::FILES, "upload" => "inline") + .increment(1); let span = tracing::info_span!("file-upload", ?filename); @@ -222,7 +223,8 @@ impl FormData for Import { Field::array(Field::file(move |filename, _, stream| { let state = state.clone(); - metrics::counter!("pict-rs.files", "import" => "inline").increment(1); + metrics::counter!(crate::init_metrics::FILES, "import" => "inline") + .increment(1); let span = tracing::info_span!("file-import", ?filename); @@ -336,7 +338,8 @@ impl FormData for BackgroundedUpload { Field::array(Field::file(move |filename, _, stream| { let state = state.clone(); - metrics::counter!("pict-rs.files", "upload" => "background").increment(1); + metrics::counter!(crate::init_metrics::FILES, "upload" => "background") + .increment(1); let span = tracing::info_span!("file-proxy", ?filename); @@ -424,7 +427,7 @@ async fn claim_upload( Ok(wait_res) => { let upload_result = wait_res?; state.repo.claim(upload_id).await?; - metrics::counter!("pict-rs.background.upload.claim").increment(1); + metrics::counter!(crate::init_metrics::BACKGROUND_UPLOAD_CLAIM).increment(1); match upload_result { UploadResult::Success { alias, token } => { @@ -515,7 +518,7 @@ async fn do_download_inline( stream: impl Stream> + 'static, state: &State, ) -> Result { - metrics::counter!("pict-rs.files", "download" => "inline").increment(1); + metrics::counter!(crate::init_metrics::FILES, "download" => "inline").increment(1); let (alias, delete_token, details) = ingest_inline(stream, state).await?; @@ -534,7 +537,7 @@ async fn do_download_backgrounded( stream: impl Stream> + 'static, state: web::Data>, ) -> Result { - metrics::counter!("pict-rs.files", "download" => "background").increment(1); + metrics::counter!(crate::init_metrics::FILES, "download" => "background").increment(1); let backgrounded = Backgrounded::proxy(&state, stream).await?; @@ -1963,6 +1966,9 @@ impl PictRsConfiguration { pub async fn run(self) -> color_eyre::Result<()> { let PictRsConfiguration { config, operation } = self; + // describe all the metrics pict-rs produces + init_metrics::init_metrics(); + let tmp_dir = TmpDir::init(&config.server.temporary_directory).await?; let policy_dir = magick::write_magick_policy(&config.media, &tmp_dir).await?; diff --git a/src/middleware/payload.rs b/src/middleware/payload.rs index ab4c342..5f017dc 100644 --- a/src/middleware/payload.rs +++ b/src/middleware/payload.rs @@ -22,7 +22,7 @@ struct MetricsGuard { impl MetricsGuard { fn guard() -> Self { - metrics::counter!("pict-rs.payload.drain.start").increment(1); + metrics::counter!(crate::init_metrics::PAYLOAD_DRAIN_START).increment(1); MetricsGuard { start: Instant::now(), @@ -37,10 +37,10 @@ impl MetricsGuard { impl Drop for MetricsGuard { fn drop(&mut self) { - metrics::counter!("pict-rs.payload.drain.end", "completed" => (!self.armed).to_string()) + metrics::counter!(crate::init_metrics::PAYLOAD_DRAIN_END, "completed" => (!self.armed).to_string()) .increment(1); - metrics::histogram!("pict-rs.payload.drain.duration", "completed" => (!self.armed).to_string()) + metrics::histogram!(crate::init_metrics::PAYLOAD_DRAIN_DURATION, "completed" => (!self.armed).to_string()) .record(self.start.elapsed().as_secs_f64()); } } @@ -137,7 +137,7 @@ impl Drop for PayloadStream { if let Some(payload) = self.inner.take() { tracing::debug!("Dropped unclosed payload, draining"); if self.sender.try_send(payload).is_err() { - metrics::counter!("pict-rs.payload.drain.fail-send").increment(1); + metrics::counter!(crate::init_metrics::PAYLOAD_DRAIN_FAIL_SEND).increment(1); tracing::error!("Failed to send unclosed payload for draining"); } } diff --git a/src/process.rs b/src/process.rs index bfcc8e0..916e1ed 100644 --- a/src/process.rs +++ b/src/process.rs @@ -27,7 +27,8 @@ struct MetricsGuard { impl MetricsGuard { fn guard(command: Arc) -> Self { - metrics::counter!("pict-rs.process.start", "command" => command.to_string()).increment(1); + metrics::counter!(crate::init_metrics::PROCESS_START, "command" => command.to_string()) + .increment(1); Self { start: Instant::now(), @@ -44,13 +45,13 @@ impl MetricsGuard { impl Drop for MetricsGuard { fn drop(&mut self) { metrics::histogram!( - "pict-rs.process.duration", + crate::init_metrics::PROCESS_DURATION, "command" => self.command.to_string(), "completed" => (!self.armed).to_string(), ) .record(self.start.elapsed().as_secs_f64()); - metrics::counter!("pict-rs.process.end", "completed" => (!self.armed).to_string() , "command" => self.command.to_string()).increment(1); + metrics::counter!(crate::init_metrics::PROCESS_END, "completed" => (!self.armed).to_string() , "command" => self.command.to_string()).increment(1); } } diff --git a/src/queue.rs b/src/queue.rs index 95afe7b..e2cbd12 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -203,7 +203,7 @@ struct MetricsGuard { impl MetricsGuard { fn guard(worker_id: uuid::Uuid, queue: &'static str) -> Self { - metrics::counter!("pict-rs.job.start", "queue" => queue, "worker-id" => worker_id.to_string()).increment(1); + metrics::counter!(crate::init_metrics::JOB_START, "queue" => queue, "worker-id" => worker_id.to_string()).increment(1); Self { worker_id, @@ -220,8 +220,8 @@ impl MetricsGuard { impl Drop for MetricsGuard { fn drop(&mut self) { - 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); + metrics::histogram!(crate::init_metrics::JOB_DURAION, "queue" => self.queue, "worker-id" => self.worker_id.to_string(), "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64()); + metrics::counter!(crate::init_metrics::JOB_END, "queue" => self.queue, "worker-id" => self.worker_id.to_string(), "completed" => (!self.armed).to_string()).increment(1); } } diff --git a/src/queue/cleanup.rs b/src/queue/cleanup.rs index 6c432a3..aa904d8 100644 --- a/src/queue/cleanup.rs +++ b/src/queue/cleanup.rs @@ -166,7 +166,7 @@ async fn outdated_variants(repo: &ArcRepo, config: &Configuration) -> Result<(), let mut count = 0; while let Some(res) = variant_stream.next().await { - metrics::counter!("pict-rs.cleanup.outdated-variant").increment(1); + metrics::counter!(crate::init_metrics::CLEANUP_OUTDATED_VARIANT).increment(1); tracing::trace!("outdated_variants: looping"); let (hash, variant) = res?; @@ -193,7 +193,7 @@ async fn outdated_proxies(repo: &ArcRepo, config: &Configuration) -> Result<(), let mut count = 0; while let Some(res) = alias_stream.next().await { - metrics::counter!("pict-rs.cleanup.outdated-proxy").increment(1); + metrics::counter!(crate::init_metrics::CLEANUP_OUTDATED_PROXY).increment(1); tracing::trace!("outdated_proxies: looping"); let alias = res?; diff --git a/src/queue/process.rs b/src/queue/process.rs index 656e2c9..5fff30f 100644 --- a/src/queue/process.rs +++ b/src/queue/process.rs @@ -87,8 +87,8 @@ impl UploadGuard { impl Drop for UploadGuard { fn drop(&mut self) { - 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()); + metrics::counter!(crate::init_metrics::BACKGROUND_UPLOAD_INGEST, "completed" => (!self.armed).to_string()).increment(1); + metrics::histogram!(crate::init_metrics::BACKGROUND_UPLOAD_INGEST_DURATION, "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_seconds_f64()); if self.armed { tracing::warn!( diff --git a/src/repo/metrics.rs b/src/repo/metrics.rs index b37418a..2e4fd04 100644 --- a/src/repo/metrics.rs +++ b/src/repo/metrics.rs @@ -55,21 +55,21 @@ impl WaitMetricsGuard { impl Drop for PushMetricsGuard { fn drop(&mut self) { - metrics::counter!("pict-rs.queue.push", "completed" => (!self.armed).to_string(), "queue" => self.queue).increment(1); + metrics::counter!(crate::init_metrics::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", "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); + metrics::histogram!(crate::init_metrics::QUEUE_POP_DURATION, "completed" => (!self.armed).to_string(), "queue" => self.queue).record(self.start.elapsed().as_secs_f64()); + metrics::counter!(crate::init_metrics::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", "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64()); - metrics::counter!("pict-rs.upload.wait", "completed" => (!self.armed).to_string()) + metrics::histogram!(crate::init_metrics::UPLOAD_WAIT_DURATION, "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64()); + metrics::counter!(crate::init_metrics::UPLOAD_WAIT, "completed" => (!self.armed).to_string()) .increment(1); } } diff --git a/src/repo/postgres.rs b/src/repo/postgres.rs index a3f9a89..3714b0f 100644 --- a/src/repo/postgres.rs +++ b/src/repo/postgres.rs @@ -357,7 +357,7 @@ impl Drop for GetConnectionMetricsGuard { fn drop(&mut self) { metrics::counter!(crate::init_metrics::POSTGRES_POOL_GET, "completed" => (!self.armed).to_string()) .increment(1); - metrics::histogram!(crate::init_metrics::POSTGRES_POOL_GET_DURATION, => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64()); + metrics::histogram!(crate::init_metrics::POSTGRES_POOL_GET_DURATION, "completed" => (!self.armed).to_string()).record(self.start.elapsed().as_secs_f64()); } } @@ -1439,7 +1439,7 @@ impl QueueRepo for PostgresRepo { ) .set(heartbeat.eq(timestamp)) .execute(&mut conn) - .with_metrics(crate::init_metrics::POSGRES_QUEUE_HEARTBEAT) + .with_metrics(crate::init_metrics::POSTGRES_QUEUE_HEARTBEAT) .with_timeout(Duration::from_secs(5)) .await .map_err(|_| PostgresError::DbTimeout)?