A package that exists to add one route
Twenty-four lines of Python wrapped around somebody else's exporter, and the three entry points it took to get them to start.
The whole package
wireless_query_exporter is two files. __init__.py is a docstring, a version and a re-export (165 bytes); main.py is this:
import sys
from aiohttp.web import Application, Request, Response, json_response
from query_exporter.main import QueryExporterScript # type: ignore
class HealthQueryExporterScript(QueryExporterScript):
async def on_application_startup(self, application: Application):
application.router.add_get("/health", self._handle_health)
await super().on_application_startup(application)
async def _handle_health(self, request: Request) -> Response:
return json_response({"status": "OK"})
def main(args=None):
script = HealthQueryExporterScript()
parser = script.get_parser()
namespace = parser.parse_args(args=args)
script.main(namespace)
That is the architecture. Upstream query-exporter serves /metrics on 8080 and nothing else; the readiness probe wants a cheap endpoint (GET /health, a flat JSON body) that answers without touching Postgres. So one subclass overrides one hook, registers one route, and calls super() — the route goes on before the parent builds the rest of the application, which is the only reason the override has to be on_application_startup and not __init__.
Everything else about this service is YAML. The queries, the metrics, the DSNs and the intervals live in configuration files (three of them, concatenated at validation time) that upstream already reads. Keeping all of that out of Python is the only design decision here worth defending, and it is why the package stayed at twenty-four lines through four tickets.
The rename, and what it broke
The package first shipped under a house prefix, inherited from the internal repository it was forked from. Renaming it to wireless_query_exporter was a pure file move (two files, zero line changes), and the move itself was fine. The next commit is the interesting one, because it had to repair three things the rename exposed.
The Dockerfile had been doing this:
COPY . /app
ENV PYTHONPATH=/app
PYTHONPATH makes imports work and makes nothing else work (no distribution, no metadata, no scripts). There is no distribution, so there is no console script, no metadata and no way for s6 to start the service by name — the old module name had been wired into the run script by hand, and a rename breaks a hand-wired path silently. The repair is an install, plus a setup.py to install from (name, version, find_packages(), two requirements):
COPY . /app
RUN pip install -e .
entry_points={
"console_scripts": [
"wireless-query-exporter=wireless_query_exporter.main:main",
],
},
pip install -e . in a container is odd — editable installs exist for development and there is no source to edit here. It does the job — a .pth file plus the entry-point script, with nothing copied — but it is not what I would write today.
Three entry points for one function
main() was written three ways in two days, and the round trip is the useful part.
It started as the argparse form: ask the script object for its parser, parse, hand the namespace to script.main(). Then it became the callable form:
def main(args=None):
script = HealthQueryExporterScript()
if args is None:
args = sys.argv[1:]
script(*args)
Shorter, and wrong (three lines saved, one contract broken). QueryExporterScript is callable, so this runs, but calling it bypasses get_parser() — the config path and the log level stop being parsed as options and arrive as positional arguments. Worse, a console_scripts shim calls main() with no arguments at all, so the function has to go to sys.argv itself. That is argument parsing, reimplemented badly, inside the one function whose job was to avoid it.
The next day it went back:
parser = script.get_parser()
namespace = parser.parse_args(args=args)
script.main(namespace)
Four lines longer and correct. The rule it encodes is narrow: when you subclass a tool, use the tool's parser, never your own idea of its arguments. get_parser() knows every flag upstream accepts and will still know them after an upgrade; sys.argv[1:] knows nothing, and it does not fail loudly when upstream adds an option.
What it cost
A rename, a packaging fix, and an entry point that went out and came back. The net change is a setup.py, one line of Dockerfile, and a main() that is textually identical to the one I started with (17 lines, same four statements).
The thing I would keep is the ratio. Twenty-four lines of Python, four YAML files, and a subclass that overrides one method — a thinner wrapper would have meant patching upstream, and a thicker one would have meant owning a query engine.