POC Monitoring & Reporting Tools 2 — Questions and Answers
Question 1: Which Python library provides a `RotatingFileHandler` to automatically rotate log files when they reach a specified size?
- loguru
- logging (Correct answer)
- structlog
- logbook
Correct answer: logging
The built-in `logging` module includes `RotatingFileHandler` in `logging.handlers` to rotate files based on size.
Question 2: In Python's `logging` module, what numeric level corresponds to `WARNING`?
- 20
- 30 (Correct answer)
- 40
- 50
Correct answer: 30
WARNING maps to level 30; DEBUG=10, INFO=20, ERROR=40, CRITICAL=50.
Question 3: Which method of a `logging.Logger` object logs a message only if the logger's effective level is DEBUG or lower?
- logger.info()
- logger.debug() (Correct answer)
- logger.warning()
- logger.verbose()
Correct answer: logger.debug()
`logger.debug()` emits a log record at level DEBUG (10), the lowest standard level.
Question 4: What does the `Prometheus` Python client library use to expose metrics by default?
- A gRPC endpoint on port 50051
- An HTTP /metrics endpoint (Correct answer)
- A WebSocket stream
- A file in /var/log/prometheus/
Correct answer: An HTTP /metrics endpoint
The `prometheus_client` library starts an HTTP server exposing metrics at `/metrics`, which Prometheus scrapes.
Question 5: Which `logging.Formatter` directive inserts the logger's name into a log message?
- %(levelname)s
- %(name)s (Correct answer)
- %(module)s
- %(funcName)s
Correct answer: %(name)s
`%(name)s` is replaced with the name passed to `logging.getLogger(name)`.
Question 6: When using `unittest` in Python, which method generates a test report showing pass/fail counts to stdout?
- unittest.TextTestRunner().run(suite) (Correct answer)
- unittest.HTMLTestRunner().run(suite)
- unittest.report(suite)
- unittest.summarize(suite)
Correct answer: unittest.TextTestRunner().run(suite)
`TextTestRunner` prints a plain-text report including dots, errors, failures, and a summary count.
Question 7: Which Python package is commonly used to send application metrics and traces to Datadog?
- ddtrace (Correct answer)
- datadog-sdk
- dd-metrics
- py-datadog
Correct answer: ddtrace
`ddtrace` is the official Datadog APM Python library for tracing and metrics.
Which Python library provides a `RotatingFileHandler` to automatically rotate log files when they reach a specified size?