inCaller / prometheus_bot

Telegram bot for prometheus alerting
MIT License
394 stars 182 forks source link

prometheus_bot fails with panic with newly created bot #11

Open rutsky opened 7 years ago

rutsky commented 7 years ago

I'm trying prometheus_bot from master branch (271ff171) compiled with Go 1.6.2 from Ubuntu 16.04 64-bit and have observed panic during handling of first requests with newly created Telegram bot.

I can't reproduce this issue currently and I believe the issue is related to freshly created Telegram bot or some issue on Telegram side. I want to leave this issue here for the reference, in case anyone else will observe it later.

Here is what I've done.

  1. Created new Telegram bot.
  2. Created new Chat, invited myself and bot in it.
  3. Started ./prometheus_bot -c config.yml
  4. Run make test without specification of TELEGRAM_CHATID:
$ make test
bash t/curl.t
1..2
not ok 1 - simpe.json
# 404
not ok 2 - noGenURL.json
# 404

This lead to 404 responses from prometheus_bot.

  1. Found out Chat Id and run tests with TELEGRAM_CHATID:
$ make test TELEGRAM_CHATID=-...
bash t/curl.t
1..2
not ok 1 - simpe.json
not ok 2 - noGenURL.json

This lead to panic. Here is prometheus_bot log for the whole session:

$ ./prometheus_bot -c config.yml
Authorized on account SomeBot
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /ping/:chatid             --> main.GET_Handling (3 handlers)
[GIN-debug] POST   /alert/:chatid            --> main.POST_Handling (3 handlers)
[GIN-debug] Listening and serving HTTP on :9087
[GIN] 2017/03/06 - 22:17:30 | 404 |         645ns | 127.0.0.1 |   POST    /alert/
[GIN] 2017/03/06 - 22:17:30 | 404 |         628ns | 127.0.0.1 |   POST    /alert/
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0xc8 pc=0x4012aa]

goroutine 50 [running]:
panic(0x8f5180, 0xc820010170)
        /usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
main.telegramBot(0xc8200771a0)
        /home/bob/stuff/kubernetes/prometheus_bot/main.go:88 +0x2aa
created by main.main
        /home/bob/stuff/kubernetes/prometheus_bot/main.go:138 +0x8f7
powerman commented 7 years ago

@hryamzik: looks like update.Message should be checked for nil at main.go:88.

hryamzik commented 7 years ago

We can check it for nil but what should we do? If token is invalid there's no reason to run.

powerman commented 7 years ago

what should we do?

Do. Not. Crash. :)

rutsky commented 7 years ago

If token is invalid there's no reason to run.

Well, if configuration is incorrect it should be handled and reported (probably with message and service exit with non-zero code).

BTW, bot token hasn't changed between described here failure and successful usage in the following runs, so I don't think this error is caused by incorrect bot access token.

hryamzik commented 7 years ago

@leominov because you can ask bot for chat ID.

@rutsky I believe crash results in non-zero exit code. PRs are welcomed. ;-)