Skip to content

Commit

Permalink
Use Prometheus metrics prefix
Browse files Browse the repository at this point in the history
Even though it is considered an anti-pattern to add a prefix with the name of the software or component to metrics (according to the official Prometheus documentation), I have decided to add a prefix. I’ve found that this makes it much easier to find relevant metrics. The main disadvantage of per-component prefixes queries become slightly more complex if you want to query the same metric (e.g. HTTP request duration) across multiple components. This isn’t super important in our case though, so I think the trade-off is acceptable.
  • Loading branch information
tillprochaska committed Nov 17, 2023
1 parent dbe519a commit 31df0f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions ingestors/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@

log = logging.getLogger(__name__)

INGEST_SUCCEEDED = Counter(
"ingest_succeeded_total",
INGESTIONS_SUCCEEDED = Counter(
"ingestfile_ingestions_succeeded_total",
"Successful ingestions",
["ingestor"],
)
INGEST_FAILED = Counter(
"ingest_failed_total",
INGESTIONS_FAILED = Counter(
"ingestfile_ingestions_failed_total",
"Failed ingestions",
["ingestor"],
)
INGEST_DURATION = Histogram(
"ingest_duration_seconds",
INGESTION_DURATION = Histogram(
"ingestfile_ingestion_duration_seconds",
"Ingest duration by ingestor",
["ingestor"],
# The bucket sizes are a rough guess right now, we might want to adjust
# them later based on observed durations
buckets=[
0.005
0.005,
0.01,
0.025,
0.05,
Expand All @@ -57,8 +57,8 @@
15 * 60,
],
)
INGEST_INGESTED_BYTES = Counter(
"ingest_ingested_bytes_total",
INGESTED_BYTES = Counter(
"ingestfile_ingested_bytes_total",
"Total number of bytes ingested",
["ingestor"],
)
Expand Down Expand Up @@ -205,20 +205,20 @@ def ingest(self, file_path, entity, **kwargs):
self.delegate(ingestor_class, file_path, entity)
duration = max(0, default_timer() - start_time)

INGEST_SUCCEEDED.labels(ingestor_name).inc()
INGEST_DURATION.labels(ingestor_name).observe(duration)
INGESTIONS_SUCCEEDED.labels(ingestor_name).inc()
INGESTION_DURATION.labels(ingestor_name).observe(duration)

if file_size is not None:
INGEST_INGESTED_BYTES.labels(ingestor_name).inc(file_size)
INGESTED_BYTES.labels(ingestor_name).inc(file_size)

entity.set("processingStatus", self.STATUS_SUCCESS)
except ProcessingException as pexc:
log.exception("[%r] Failed to process: %s", entity, pexc)

if ingestor_name:
INGEST_FAILED.labels(ingestor_name).inc()
INGESTIONS_FAILED.labels(ingestor_name).inc()
else:
INGEST_FAILED.labels(None).inc()
INGESTIONS_FAILED.labels(None).inc()

entity.set("processingError", stringify(pexc))
capture_exception(pexc)
Expand Down
8 changes: 4 additions & 4 deletions ingestors/support/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
TIMEOUT = 3600 # seconds
CONVERT_RETRIES = 5

INGEST_PDF_CACHE_ACCESSED = Counter(
"ingest_pdf_cache_accessed",
PDF_CACHE_ACCESSED = Counter(
"ingestfile_pdf_cache_accessed",
"Number of times the PDF cache has been accessed, by cache status",
["status"],
)
Expand All @@ -32,12 +32,12 @@ def document_to_pdf(self, unique_tmpdir, file_path, entity):
file_name = entity_filename(entity, extension="pdf")
path = self.manager.load(pdf_hash, file_name=file_name)
if path is not None:
INGEST_PDF_CACHE_ACCESSED.labels("hit").inc()
PDF_CACHE_ACCESSED.labels("hit").inc()
log.info("Using PDF cache: %s", file_name)
entity.set("pdfHash", pdf_hash)
return path

INGEST_PDF_CACHE_ACCESSED.labels("miss").inc()
PDF_CACHE_ACCESSED.labels("miss").inc()
pdf_file = self._document_to_pdf(unique_tmpdir, file_path, entity)
if pdf_file is not None:
content_hash = self.manager.store(pdf_file)
Expand Down

0 comments on commit 31df0f4

Please sign in to comment.