You need to add Prometheus metrics to a Python batch job that runs every 10 minutes. How?
IntermediateScenarioTesting, CI/CD, packaging & services
Answer
Situation read → Short-lived process; Prometheus cannot scrape it reliably.
What I'd do →
- Use a dedicated
CollectorRegistry, recordjob_duration_seconds,job_items_processed_totalandjob_last_success_timestamp_seconds. push_to_gateway("pushgateway.monitoring:9091", job="reconciler", registry=reg)at the end (also on failure, with a failure gauge).- Alert:
time() - job_last_success_timestamp_seconds > 1800. - If it runs on a host with node exporter, the textfile collector is an alternative.
Why → Pushgateway is designed for batch jobs; the last-success timestamp catches every failure mode.
Interview tip → Say Pushgateway is only for batch jobs, not for services.
More on Testing, CI/CD, packaging & services
You join a team whose Python automation repo has no tests. Where do you start?BeginnerYour pytest suite takes 12 minutes. How do you speed it up?IntermediateA test passes locally but fails in CI only when run with the rest of the suite. What do you suspect?IntermediateYou want a reusable CI pipeline for 15 Python tool repos. What goes in it?IntermediateYour Python Docker image is 1.1 GB. How do you shrink it?IntermediateYou want to distribute an internal CLI to 200 engineers. What are your options?Intermediate