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 2783905
Showing 1 changed file with 14 additions and 14 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

0 comments on commit 2783905

Please sign in to comment.