Skip to content

Commit

Permalink
Enable setting ThreadId for telegram notifications
Browse files Browse the repository at this point in the history
Fix the typo

Signed-off-by: Gokhan Sari <gokhan@sari.me>

Update tests

Signed-off-by: Gokhan Sari <gokhan@sari.me>

Update documentation

Signed-off-by: Gokhan Sari <gokhan@sari.me>

Update notifiers_test.go

Signed-off-by: Gokhan Sari <gokhan@sari.me>

Update notifiers_test.go

Signed-off-by: Gokhan Sari <gokhan@sari.me>

Use int32 instead of int64 for MessageThreadID

Signed-off-by: Gokhan Sari <gokhan@sari.me>

Bump github.com/go-openapi/swag from 0.22.4 to 0.22.7 (prometheus#3655)

Bumps [github.com/go-openapi/swag](https://github.com/go-openapi/swag) from 0.22.4 to 0.22.7.
- [Commits](go-openapi/swag@v0.22.4...v0.22.7)

---
updated-dependencies:
- dependency-name: github.com/go-openapi/swag
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Gokhan Sari <gokhan@sari.me>

Support UTF-8 label matchers: Add metrics to matchers compat package (prometheus#3658)

* Add metrics to matchers compat package

This commit adds the following metrics to the compat package:

  alertmanager_matchers_parse
  alertmanager_matchers_disagree
  alertmanager_matchers_incompatible
  alertmanager_matchers_invalid

With a label called origin to differentiate the different sources
of inputs: the configuration file, the API, and amtool.

The disagree_total metric is incremented when an input is invalid
in both parsers, but results in different parsed representations,
then there is disagreement. This should not happen, and suggests
their is either a bug in one of the parsers or a mistake in the
backwards compatible guarantees of the matchers/parse parser.

The incompatible_total metric is incremented when an input is valid
in pkg/labels, but not the UTF-8 parser in matchers/parse. In such
case, the matcher should be updated to be compatible. This often
means adding double quotes around the right hand side of the matcher.
For example, foo="bar".

The invalid_total metric is incremented when an input is invalid
in both parsers. This was never a valid input.

The tests have been updated to check the metrics are incremented
as expected.

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
Signed-off-by: Gokhan Sari <gokhan@sari.me>

Change compat metrics to counters (prometheus#3686)

This commit changes the metrics in the compat package from gauges
to counters. The reason for this is that in some cases the gauge
should behave like a gauge (i.e. loading configurations) but in
other cases should behave like a counter (i.e. HTTP requests).

Second, because the compat package is a global package
(due to how config.Load works), in tenanted systems like Cortex
and Mimir it was non-trivial to reset the gauges per tenant
each time their configuration was reloaded.

Instead, it's easier to compute the rate of increase as 0 instead
of check that the gauge is 0 to know if UTF-8 strict mode can be
enabled.

Signed-off-by: George Robinson <george.robinson@grafana.com>
Signed-off-by: Gokhan Sari <gokhan@sari.me>

Bump github.com/go-openapi/errors from 0.20.4 to 0.21.0

Bumps [github.com/go-openapi/errors](https://github.com/go-openapi/errors) from 0.20.4 to 0.21.0.
- [Commits](go-openapi/errors@v0.20.4...v0.21.0)

---
updated-dependencies:
- dependency-name: github.com/go-openapi/errors
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Gokhan Sari <gokhan@sari.me>

Bump github.com/go-openapi/swag from 0.22.7 to 0.22.9

Bumps [github.com/go-openapi/swag](https://github.com/go-openapi/swag) from 0.22.7 to 0.22.9.
- [Commits](go-openapi/swag@v0.22.7...v0.22.9)

---
updated-dependencies:
- dependency-name: github.com/go-openapi/swag
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Gokhan Sari <gokhan@sari.me>

Bump eslint from 8.35.0 to 8.56.0 in /ui/react-app (prometheus#3692)

Bumps [eslint](https://github.com/eslint/eslint) from 8.35.0 to 8.56.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.35.0...v8.56.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Gokhan Sari <gokhan@sari.me>

Do not register compat metrics in amtool (prometheus#3713)

There is no need to register these metrics in amtool, so use
compat.NewMetrics(nil) instead of compat.RegisteredMetrics.

Signed-off-by: George Robinson <george.robinson@grafana.com>
Signed-off-by: Gokhan Sari <gokhan@sari.me>

Remove metrics from compat package (prometheus#3714)

This commit removes the metrics from the compat package
in favour of the existing logging and the additional tools
at hand, such as amtool, to validate Alertmanager configurations.

Due to the global nature of the compat package, a consequence
of config.Load, these metrics have proven to be less useful
in practice than expected, both in Alertmanager and other projects
such as Mimir.

There are a number of reasons for this:

1. Because the compat package is global, these metrics cannot be
   reset each time config.Load is called, as in multi-tenant
   projects like Mimir loading a config for one tenant would reset
   the metrics for all tenants. This is also the reason the metrics
   are counters and not gauges.

2. Since the metrics are counters, it is difficult to create
   meaningful dashboards for Alertmanager as, unlike in Mimir,
   configurations are not reloaded at fixed intervals, and as such,
   operators cannot use rate to track configuration changes
   over time.

In Alertmanager, there are much better tools available to validate
that an Alertmanager configuration is compatible with the UTF-8
parser, including both the existing logging from Alertmanager
server and amtool check-config.

In other projects like Mimir, we can track configurations for
individual tenants using log aggregation and storage systems
such as Loki. This gives operators far more information than
what is possible with the metrics, including the timestamp,
input and ID of tenant configurations that are incompatible
or have disagreement.

Signed-off-by: George Robinson <george.robinson@grafana.com>
Signed-off-by: Gokhan Sari <gokhan@sari.me>

Fix the typo

Revert changes in unintended files
  • Loading branch information
th0th committed Apr 18, 2024
1 parent cb9724d commit 7ab5ae6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ type TelegramConfig struct {
BotToken Secret `yaml:"bot_token,omitempty" json:"token,omitempty"`
BotTokenFile string `yaml:"bot_token_file,omitempty" json:"token_file,omitempty"`
ChatID int64 `yaml:"chat_id,omitempty" json:"chat,omitempty"`
MessageThreadID int32 `yaml:"message_thread_id,omitempty" json:"message_thread_id,omitempty"`
Message string `yaml:"message,omitempty" json:"message,omitempty"`
DisableNotifications bool `yaml:"disable_notifications,omitempty" json:"disable_notifications,omitempty"`
ParseMode string `yaml:"parse_mode,omitempty" json:"parse_mode,omitempty"`
Expand Down
9 changes: 8 additions & 1 deletion config/notifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

"github.com/stretchr/testify/require"

"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -1046,6 +1045,14 @@ bot_token_file: ''
in: `
bot_token: xyz
chat_id: 123
`,
},
{
name: "with bot_token, chat_id and message_thread_id set - it succeeds",
in: `
bot_token: xyz
chat_id: 123
message_thread_id: 456
`,
},
{
Expand Down
3 changes: 3 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,9 @@ attributes:
# ID of the chat where to send the messages.
[ chat_id: <int> ]

# Optional ID of the message thread where to send the messages.
[ message_thread_id: <int> ]

# Message template.
[ message: <tmpl_string> default = '{{ template "telegram.default.message" .}}' ]

Expand Down
1 change: 1 addition & 0 deletions notify/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err
message, err := n.client.Send(telebot.ChatID(n.conf.ChatID), messageText, &telebot.SendOptions{
DisableNotification: n.conf.DisableNotifications,
DisableWebPagePreview: true,
ThreadID: int(n.conf.MessageThreadID),
})
if err != nil {
return true, err
Expand Down
2 changes: 2 additions & 0 deletions notify/telegram/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ receivers:
telegram_configs:
- chat_id: 1234
bot_token: secret
message_thread_id: 1357
`
var c config.Config
err := yaml.Unmarshal([]byte(in), &c)
Expand All @@ -57,6 +58,7 @@ receivers:
require.Equal(t, "https://api.telegram.org", c.Receivers[0].TelegramConfigs[0].APIUrl.String())
require.Equal(t, config.Secret("secret"), c.Receivers[0].TelegramConfigs[0].BotToken)
require.Equal(t, int64(1234), c.Receivers[0].TelegramConfigs[0].ChatID)
require.Equal(t, int64(1357), c.Receivers[0].TelegramConfigs[0].MessageThreadID)
require.Equal(t, "HTML", c.Receivers[0].TelegramConfigs[0].ParseMode)
}

Expand Down

0 comments on commit 7ab5ae6

Please sign in to comment.