Skip to content

Commit 2783905

Browse files
committed
Use Prometheus metrics prefix
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.
1 parent dbe519a commit 2783905

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

ingestors/manager.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@
2525

2626
log = logging.getLogger(__name__)
2727

28-
INGEST_SUCCEEDED = Counter(
29-
"ingest_succeeded_total",
28+
INGESTIONS_SUCCEEDED = Counter(
29+
"ingestfile_ingestions_succeeded_total",
3030
"Successful ingestions",
3131
["ingestor"],
3232
)
33-
INGEST_FAILED = Counter(
34-
"ingest_failed_total",
33+
INGESTIONS_FAILED = Counter(
34+
"ingestfile_ingestions_failed_total",
3535
"Failed ingestions",
3636
["ingestor"],
3737
)
38-
INGEST_DURATION = Histogram(
39-
"ingest_duration_seconds",
38+
INGESTION_DURATION = Histogram(
39+
"ingestfile_ingestion_duration_seconds",
4040
"Ingest duration by ingestor",
4141
["ingestor"],
4242
# The bucket sizes are a rough guess right now, we might want to adjust
4343
# them later based on observed durations
4444
buckets=[
45-
0.005
45+
0.005,
4646
0.01,
4747
0.025,
4848
0.05,
@@ -57,8 +57,8 @@
5757
15 * 60,
5858
],
5959
)
60-
INGEST_INGESTED_BYTES = Counter(
61-
"ingest_ingested_bytes_total",
60+
INGESTED_BYTES = Counter(
61+
"ingestfile_ingested_bytes_total",
6262
"Total number of bytes ingested",
6363
["ingestor"],
6464
)
@@ -205,20 +205,20 @@ def ingest(self, file_path, entity, **kwargs):
205205
self.delegate(ingestor_class, file_path, entity)
206206
duration = max(0, default_timer() - start_time)
207207

208-
INGEST_SUCCEEDED.labels(ingestor_name).inc()
209-
INGEST_DURATION.labels(ingestor_name).observe(duration)
208+
INGESTIONS_SUCCEEDED.labels(ingestor_name).inc()
209+
INGESTION_DURATION.labels(ingestor_name).observe(duration)
210210

211211
if file_size is not None:
212-
INGEST_INGESTED_BYTES.labels(ingestor_name).inc(file_size)
212+
INGESTED_BYTES.labels(ingestor_name).inc(file_size)
213213

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

218218
if ingestor_name:
219-
INGEST_FAILED.labels(ingestor_name).inc()
219+
INGESTIONS_FAILED.labels(ingestor_name).inc()
220220
else:
221-
INGEST_FAILED.labels(None).inc()
221+
INGESTIONS_FAILED.labels(None).inc()
222222

223223
entity.set("processingError", stringify(pexc))
224224
capture_exception(pexc)

0 commit comments

Comments
 (0)