vladvasiliu/kibana-prometheus-exporter-py

Ensure `LISTEN_PORT` type

mapshen opened this issue · 1 comments

Can we try to check the type of LISTEN_PORT on this line and if not, try converting it to integer?

We deploy this using ansible's docker_container module, which only allows you pass envs as strings, other wise, you will get errors like:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Non-string value found for env option. Ambiguous env options must be wrapped in quotes to avoid them being interpreted. Key: LISTEN_PORT"}

And when passing LISTEN_PORT as type str, we get this error when the app starts up:

WARNING:kibana_collector:Got a HTTP error 404 while trying to contact Kibana:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/venv/kibana_prometheus_exporter/__main__.py", line 27, in <module>
    start_http_server(config.listen_port)
  File "/venv/lib/python3.7/site-packages/prometheus_client/exposition.py", line 192, in start_http_server
    httpd = _ThreadingSimpleServer((addr, port), CustomMetricsHandler)
  File "/usr/local/lib/python3.7/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/local/lib/python3.7/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/local/lib/python3.7/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
TypeError: an integer is required (got type str)

I've fixed this in dev. I've also added some more configuration checks.
I expect to merge this in master and create a new release during the weekend.