Merge pull request #3190 from prometheus/release-0.25

Release 0.25
This commit is contained in:
Simon Pasquier 2023-01-05 14:35:35 +01:00 committed by GitHub
commit ebcea59acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 3 deletions

View File

@ -139,7 +139,7 @@ workflows:
branches:
only: /^(main|release-.*|.*build-all.*)$/
tags:
only: /^v2(\.[0-9]+){2}(-.+|[^-.]*)$/
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
- mixin:
filters:
tags:

View File

@ -1,4 +1,4 @@
## 0.25.0-rc.0 / 2022-12-16
## 0.25.0 / 2022-12-22
* [CHANGE] Change the default `parse_mode` value from `MarkdownV2` to `HTML` for Telegram. #2981
* [CHANGE] Make `api_url` field optional for Telegram. #2981
@ -31,6 +31,7 @@
* [BUGFIX] amtool: Avoid panic when the label value matcher is empty. #2968
* [BUGFIX] Fail configuration loading if `api_url` is empty for OpsGenie. #2910
* [BUGFIX] Fix email template for resolved notifications. #3166
* [BUGFIX] Use the HTML template engine when the parse mode is HTML for Telegram. #3183
## 0.24.0 / 2022-03-24

View File

@ -1 +1 @@
0.25.0-rc.0
0.25.0

View File

@ -69,6 +69,10 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err
tmpl = notify.TmplText(n.tmpl, data, &err)
)
if n.conf.ParseMode == "HTML" {
tmpl = notify.TmplHTML(n.tmpl, data, &err)
}
key, ok := notify.GroupKey(ctx)
if !ok {
return false, fmt.Errorf("group key missing")

View File

@ -14,17 +14,26 @@
package telegram
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"
"github.com/go-kit/log"
commoncfg "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/notify/test"
"github.com/prometheus/alertmanager/types"
)
func TestTelegramUnmarshal(t *testing.T) {
@ -73,3 +82,71 @@ func TestTelegramRetry(t *testing.T) {
require.Equal(t, expected, actual, fmt.Sprintf("error on status %d", statusCode))
}
}
func TestTelegramNotify(t *testing.T) {
for _, tc := range []struct {
name string
cfg config.TelegramConfig
expText string
}{
{
name: "No escaping by default",
cfg: config.TelegramConfig{
Message: "<code>x < y</code>",
HTTPConfig: &commoncfg.HTTPClientConfig{},
},
expText: "<code>x < y</code>",
},
{
name: "Characters escaped in HTML mode",
cfg: config.TelegramConfig{
ParseMode: "HTML",
Message: "<code>x < y</code>",
HTTPConfig: &commoncfg.HTTPClientConfig{},
},
expText: "<code>x &lt; y</code>",
},
} {
t.Run(tc.name, func(t *testing.T) {
var out []byte
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var err error
out, err = io.ReadAll(r.Body)
require.NoError(t, err)
w.Write([]byte(`{"ok":true,"result":{"chat":{}}}`))
}))
defer srv.Close()
u, _ := url.Parse(srv.URL)
tc.cfg.APIUrl = &config.URL{URL: u}
notifier, err := New(&tc.cfg, test.CreateTmpl(t), log.NewNopLogger())
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ctx = notify.WithGroupKey(ctx, "1")
retry, err := notifier.Notify(ctx, []*types.Alert{
{
Alert: model.Alert{
Labels: model.LabelSet{
"lbl1": "val1",
"lbl3": "val3",
},
StartsAt: time.Now(),
EndsAt: time.Now().Add(time.Hour),
},
},
}...)
require.False(t, retry)
require.NoError(t, err)
req := map[string]string{}
err = json.Unmarshal(out, &req)
require.NoError(t, err)
require.Equal(t, tc.expText, req["text"])
})
}
}