Skip to content

Commit

Permalink
Use keyword args to set Prometheus metric labels
Browse files Browse the repository at this point in the history
As suggested by @stchris
  • Loading branch information
tillprochaska committed Nov 20, 2023
1 parent b6ec5e0 commit 6f3a99d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions ingestors/manager.py
Original file line number Diff line number Diff line change
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)

INGESTIONS_SUCCEEDED.labels(ingestor_name).inc()
INGESTION_DURATION.labels(ingestor_name).observe(duration)
INGESTIONS_SUCCEEDED.labels(ingestor=ingestor_name).inc()
INGESTION_DURATION.labels(ingestor=ingestor_name).observe(duration)

if file_size is not None:
INGESTED_BYTES.labels(ingestor_name).inc(file_size)
INGESTED_BYTES.labels(ingestor=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:
INGESTIONS_FAILED.labels(ingestor_name).inc()
INGESTIONS_FAILED.labels(ingestor=ingestor_name).inc()
else:
INGESTIONS_FAILED.labels(None).inc()
INGESTIONS_FAILED.labels(ingestor=None).inc()

entity.set("processingError", stringify(pexc))
capture_exception(pexc)
Expand Down
4 changes: 2 additions & 2 deletions ingestors/support/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
PDF_CACHE_ACCESSED.labels("hit").inc()
PDF_CACHE_ACCESSED.labels(status="hit").inc()
log.info("Using PDF cache: %s", file_name)
entity.set("pdfHash", pdf_hash)
return path

PDF_CACHE_ACCESSED.labels("miss").inc()
PDF_CACHE_ACCESSED.labels(status="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 6f3a99d

Please sign in to comment.