-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add telegram bot to lavap health #1862
base: main
Are you sure you want to change the base?
Conversation
Test Results2 268 tests - 120 2 265 ✅ - 123 25m 43s ⏱️ +6s For more details on these failures, see this check. Results for commit edbfa9b. ± Comparison against base commit 537c7ca. This pull request removes 125 and adds 5 tests. Note that renamed tests count towards both.
|
@@ -81,6 +82,7 @@ type Alerting struct { | |||
suppressedAlerts uint64 // monitoring | |||
payload map[string]interface{} | |||
colorToggle bool | |||
TelegramAlerting TelegramAlertingOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you inherit and holding a TelegramAlertingOptions?
telegramBotTokenFlagName = "telegram-bot-token" | ||
telegramChannelIDFlagName = "telegram-channel-id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to telegram-alert-bot-token
and telegram-alert-channel-id
cmdTestHealth.Flags().String(telegramBotTokenFlagName, "", "telegram bot token used for sending alerts to telegram channels (obtain from @BotFather)") | ||
cmdTestHealth.Flags().String(telegramChannelIDFlagName, "", "telegram channel ID where alerts will be sent (must start with -100)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where do you read this flag
if al.TelegramAlerting.TelegramBotToken != "" && al.TelegramAlerting.TelegramChannelID != "" { | ||
al.SendTelegramAlert(alert, attrs) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You check this inside SendTelegramAlert
@@ -161,6 +163,9 @@ func (al *Alerting) SendAlert(alert string, attributes []AlertAttribute) { | |||
if al.url != "" { | |||
go al.AppendUrlAlert(alert, attrs) | |||
} | |||
if al.TelegramAlerting.TelegramBotToken != "" && al.TelegramAlerting.TelegramChannelID != "" { | |||
al.SendTelegramAlert(alert, attrs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't do anything with the returned error?
if err != nil { | ||
return fmt.Errorf("failed to send telegram alert: %v", err) | ||
} | ||
defer resp.Body.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the defer to line 48, right after resp, err := http.Post(url ...
checkRequest: func(t *testing.T, r *http.Request) { | ||
// Check method and content type | ||
assert.Equal(t, "POST", r.Method) | ||
assert.Equal(t, "application/json", r.Header.Get("Content-Type")) | ||
|
||
// Read and verify request body | ||
body, err := io.ReadAll(r.Body) | ||
require.NoError(t, err) | ||
|
||
// Check if body contains expected content | ||
bodyStr := string(body) | ||
assert.Contains(t, bodyStr, "Test Alert") | ||
assert.Contains(t, bodyStr, "severity") | ||
assert.Contains(t, bodyStr, "high") | ||
assert.Contains(t, bodyStr, "service") | ||
assert.Contains(t, bodyStr, "test-service") | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this here and not inside the test itself?
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use require instead of assert
Description
Closes: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changemain
branchReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...