Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Yaroms
Copy link
Collaborator

@Yaroms Yaroms commented Dec 22, 2024

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...

  • read the contribution guide
  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the main branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers 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...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@Yaroms Yaroms marked this pull request as ready for review December 22, 2024 15:35
Copy link

Test Results

2 268 tests   - 120   2 265 ✅  - 123   25m 43s ⏱️ +6s
  120 suites  -   2       1 💤 +  1 
    6 files    -   1       2 ❌ +  2 

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.
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheExpirationMultiplier
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheExpirationMultiplier/Multiplier_of_1
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheExpirationMultiplier/Multiplier_of_1.2
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheExpirationMultiplier/Multiplier_of_2
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheExpirationMultiplier/Multiplier_of_2.5
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheExpirationMultiplier/Multiplier_of_200
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheFailSetWithInvalidRequestBlock
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheFailSetWithInvalidRequestBlock/Finalized_After_delay_No_Hash
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheFailSetWithInvalidRequestBlock/Finalized_After_delay_No_Hash#01
github.com/lavanet/lava/v4/ecosystem/cache ‑ TestCacheFailSetWithInvalidRequestBlock/Finalized_After_delay_With_Hash
…
github.com/lavanet/lava/v4/protocol/monitoring ‑ TestTelegramAlerting_Integration
github.com/lavanet/lava/v4/protocol/monitoring ‑ TestTelegramAlerting_SendTelegramAlert
github.com/lavanet/lava/v4/protocol/monitoring ‑ TestTelegramAlerting_SendTelegramAlert/missing_configuration
github.com/lavanet/lava/v4/protocol/monitoring ‑ TestTelegramAlerting_SendTelegramAlert/server_error
github.com/lavanet/lava/v4/protocol/monitoring ‑ TestTelegramAlerting_SendTelegramAlert/successful_alert

@@ -81,6 +82,7 @@ type Alerting struct {
suppressedAlerts uint64 // monitoring
payload map[string]interface{}
colorToggle bool
TelegramAlerting TelegramAlertingOptions
Copy link
Collaborator

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?

Comment on lines +55 to +56
telegramBotTokenFlagName = "telegram-bot-token"
telegramChannelIDFlagName = "telegram-channel-id"
Copy link
Collaborator

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

Comment on lines +252 to +253
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)")
Copy link
Collaborator

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

Comment on lines +166 to +168
if al.TelegramAlerting.TelegramBotToken != "" && al.TelegramAlerting.TelegramChannelID != "" {
al.SendTelegramAlert(alert, attrs)
}
Copy link
Collaborator

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)
Copy link
Collaborator

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()
Copy link
Collaborator

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 ...

Comment on lines +39 to +55
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")
},
Copy link
Collaborator

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?

Comment on lines +105 to +107
assert.Error(t, err)
} else {
assert.NoError(t, err)
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants