grafana / oncall

Developer-friendly incident response with brilliant Slack integration
GNU Affero General Public License v3.0
3.44k stars 277 forks source link

Telegram: show a human readable error on empty Telegram token #939

Open vadimkerr opened 1 year ago

vadimkerr commented 1 year ago

Currently the Telegram webook endpoint returns 500 and TypeError: 'NoneType' object is not iterable error in logs when TELEGRAM_TOKEN is unset. The error should be human-readable and suggest to set the TELEGRAM_TOKEN env variable.

Example:

2022-12-02 10:34:24 source=engine:app google_trace_id=none logger=django.request Internal Server Error: /telegram/
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/etc/app/apps/telegram/views.py", line 15, in post
    UpdateManager.process_request(request)
  File "/etc/app/apps/telegram/updates/update_manager.py", line 45, in process_request
    update = Update.de_json(request.data, bot=Bot(live_settings.TELEGRAM_TOKEN))
  File "/usr/local/lib/python3.9/site-packages/telegram/bot.py", line 194, in __init__
    self.token = self._validate_token(token)
  File "/usr/local/lib/python3.9/site-packages/telegram/bot.py", line 353, in _validate_token
    if any(x.isspace() for x in token):
TypeError: 'NoneType' object is not iterable
2022-12-02 10:34:24 source=engine:app google_trace_id=none logger=root inbound latency=0.608257 status=500 method=POST path=/telegram/ content-length=969 slow=0
Matvey-Kuk commented 1 year ago

This issue will already make this problem googlable :)

shampoon commented 1 year ago

I got this problem. After the failed deployment, telegram was sending once per minute POST messages. I cleaned everything in oncall and made a new deployment, but telegram continued to send POST requests and this caused my oncall to work incorrectly: I could not bind a telegram channel to oncall, alerts did not have "Acknowledgement", "Resolve" buttons ... I had to change the external port to another one so that old POST messages do not arrive on the port that the oncall engine is listening on. After that I was able to run oncall without errors

MrPlap commented 1 year ago

I got this problem. After the failed deployment, telegram was sending once per minute POST messages. I cleaned everything in oncall and made a new deployment, but telegram continued to send POST requests and this caused my oncall to work incorrectly: I could not bind a telegram channel to oncall, alerts did not have "Acknowledgement", "Resolve" buttons ... I had to change the external port to another one so that old POST messages do not arrive on the port that the oncall engine is listening on. After that I was able to run oncall without errors

I have the same problem. Alerts are sent to the channel, but there are no messages/buttons in the discussion