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

Alertmanager: Update to latest main #7103

Merged
merged 13 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

### Grafana Mimir

* [CHANGE] Alertmanager: Deprecates the `v1` API. All `v1` API endpoints now respond with a JSON deprecation notice and a status code of `410`. All endpoints have a `v2` equivalent. The list of endpoints is:
* `<alertmanager-web.external-url>/api/v1/alerts`
* `<alertmanager-web.external-url>/api/v1/receivers`
* `<alertmanager-web.external-url>/api/v1/silence/{id}`
* `<alertmanager-web.external-url>/api/v1/silences`
* `<alertmanager-web.external-url>/api/v1/status`
* [CHANGE] Ingester: Increase default value of `-blocks-storage.tsdb.head-postings-for-matchers-cache-max-bytes` and `-blocks-storage.tsdb.block-postings-for-matchers-cache-max-bytes` to 100 MiB (previous default value was 10 MiB). #6764
* [CHANGE] Validate tenant IDs according to [documented behavior](https://grafana.com/docs/mimir/latest/configure/about-tenant-ids/) even when tenant federation is not enabled. Note that this will cause some previously accepted tenant IDs to be rejected such as those longer than 150 bytes or containing `|` characters. #6959
* [CHANGE] Ruler: don't use backoff retry on remote evaluation in case of `4xx` errors. #7004
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/opentracing-contrib/go-stdlib v1.0.0
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b
github.com/pkg/errors v0.9.1
github.com/prometheus/alertmanager v0.26.1-0.20231117200754-ca5089d33eab
github.com/prometheus/alertmanager v0.26.1-0.20240119104350-f92a08d07386
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_model v0.5.0
github.com/prometheus/common v0.46.0
Expand Down Expand Up @@ -184,7 +184,7 @@ require (
github.com/hashicorp/go-msgpack v1.1.5 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.6 // indirect
github.com/hashicorp/memberlist v0.5.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/hashicorp/vault/api/auth/approle v0.5.0
Expand Down Expand Up @@ -217,7 +217,7 @@ require (
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97 // indirect
github.com/prometheus/exporter-toolkit v0.11.0 // indirect
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/rs/xid v1.5.0 // indirect
Expand Down Expand Up @@ -250,7 +250,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/telebot.v3 v3.1.3 // indirect
gopkg.in/telebot.v3 v3.2.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230711102312-30195339c3c7 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,9 @@ github.com/hashicorp/go-secure-stdlib/strutil v0.1.1/go.mod h1:gKOamz3EwoIoJq7ml
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts=
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc=
github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A=
github.com/hashicorp/go-sockaddr v1.0.6 h1:RSG8rKU28VTUTvEKghe5gIhIQpv8evvNpnDEyqO4u9I=
github.com/hashicorp/go-sockaddr v1.0.6/go.mod h1:uoUUmtwU7n9Dv3O4SNLeFvg0SxQ3lyjsj6+CCykpaxI=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
Expand Down Expand Up @@ -829,8 +830,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
github.com/prometheus/alertmanager v0.26.1-0.20231117200754-ca5089d33eab h1:639j+0he3vXZWIfy8RgphuZC3iCKGRe4qM23fymWrkE=
github.com/prometheus/alertmanager v0.26.1-0.20231117200754-ca5089d33eab/go.mod h1:d9ELeFBjQ7xxGYb+0Xh+ygxMUBwM6579tojeH6xb0qE=
github.com/prometheus/alertmanager v0.26.1-0.20240119104350-f92a08d07386 h1:jcyYvVOHEllcJsH23+TU7MFPUaNHga4TJ43v+Zt4Zts=
github.com/prometheus/alertmanager v0.26.1-0.20240119104350-f92a08d07386/go.mod h1:pT85bjw8Hkt/ZfVpa/b0gLWQc015Yjbi02eCYD0yRl4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
Expand All @@ -854,8 +855,8 @@ github.com/prometheus/common v0.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqSc
github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ=
github.com/prometheus/common/sigv4 v0.1.0 h1:qoVebwtwwEhS85Czm2dSROY5fTo2PAPEVdDeppTwGX4=
github.com/prometheus/common/sigv4 v0.1.0/go.mod h1:2Jkxxk9yYvCkE5G1sQT7GuEXm57JrvHu9k5YwTjsNtI=
github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97 h1:oHcfzdJnM/SFppy2aUlvomk37GI33x9vgJULihE5Dt8=
github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97/go.mod h1:LoBCZeRh+5hX+fSULNyFnagYlQG/gBsyA/deNzROkq8=
github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g=
github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
Expand Down Expand Up @@ -1581,8 +1582,8 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/telebot.v3 v3.1.3 h1:T+CTyOWpZMqp3ALHSweNgp1awQ9nMXdRAMpe/r6x9/s=
gopkg.in/telebot.v3 v3.1.3/go.mod h1:GJKwwWqp9nSkIVN51eRKU78aB5f5OnQuWdwiIZfPbko=
gopkg.in/telebot.v3 v3.2.1 h1:3I4LohaAyJBiivGmkfB+CiVu7QFOWkuZ4+KHgO/G3rs=
gopkg.in/telebot.v3 v3.2.1/go.mod h1:GJKwwWqp9nSkIVN51eRKU78aB5f5OnQuWdwiIZfPbko=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
110 changes: 59 additions & 51 deletions integration/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package integration
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -125,6 +126,56 @@ func TestAlertmanager(t *testing.T) {
require.Equal(t, "Accept-Encoding", res.Header.Get("Vary"))
}

func TestAlertmanagerV1Deprecated(t *testing.T) {
s, err := e2e.NewScenario(networkName)
require.NoError(t, err)
defer s.Close()

consul := e2edb.NewConsul()
require.NoError(t, s.StartAndWaitReady(consul))

require.NoError(t, writeFileToSharedDir(s, "alertmanager_configs/user-1.yaml", []byte(mimirAlertmanagerUserConfigYaml)))

alertmanager := e2emimir.NewAlertmanager(
"alertmanager",
mergeFlags(
AlertmanagerFlags(),
AlertmanagerLocalFlags(),
AlertmanagerShardingFlags(consul.NetworkHTTPEndpoint(), 1),
),
)
require.NoError(t, s.StartAndWaitReady(alertmanager))

endpoints := []string{
"alerts",
"receivers",
"silence/id",
"silences",
"status",
}
for _, endpoint := range endpoints {
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/alertmanager/api/v1/%s", alertmanager.HTTPEndpoint(), endpoint), nil)
require.NoError(t, err)
req.Header.Set("X-Scope-OrgID", "user-1")
req.Header.Set("Accept-Encoding", "gzip")

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Execute HTTP request
res, err := http.DefaultClient.Do(req.WithContext(ctx))
require.NoError(t, err)
require.Equal(t, http.StatusGone, res.StatusCode)

var response = struct {
Status string `json:"status"`
Error string `json:"error"`
}{}
require.NoError(t, json.NewDecoder(res.Body).Decode(&response))
require.Equal(t, "deprecated", response.Status)
require.Equal(t, "The Alertmanager v1 API was deprecated in version 0.16.0 and is removed as of version 0.28.0 - please use the equivalent route in the v2 API", response.Error)
}
}

func TestAlertmanagerLocalStore(t *testing.T) {
s, err := e2e.NewScenario(networkName)
require.NoError(t, err)
Expand Down Expand Up @@ -387,58 +438,29 @@ func TestAlertmanagerSharding(t *testing.T) {
assert.Equal(t, s3, ids[id3].Status.State)
}

// Endpoint: GET /v1/silences
{
for _, c := range clients {
list, err := c.GetSilencesV1(context.Background())
require.NoError(t, err)
assertSilences(list, types.SilenceStateActive, types.SilenceStateActive, types.SilenceStateActive)
}
}

// Endpoint: GET /v2/silences
{
for _, c := range clients {
list, err := c.GetSilencesV2(context.Background())
list, err := c.GetSilences(context.Background())
require.NoError(t, err)
assertSilences(list, types.SilenceStateActive, types.SilenceStateActive, types.SilenceStateActive)
}
}

// Endpoint: GET /v1/silence/{id}
{
for _, c := range clients {
sil1, err := c.GetSilenceV1(context.Background(), id1)
require.NoError(t, err)
assert.Equal(t, comment(1), sil1.Comment)
assert.Equal(t, types.SilenceStateActive, sil1.Status.State)

sil2, err := c.GetSilenceV1(context.Background(), id2)
require.NoError(t, err)
assert.Equal(t, comment(2), sil2.Comment)
assert.Equal(t, types.SilenceStateActive, sil2.Status.State)

sil3, err := c.GetSilenceV1(context.Background(), id3)
require.NoError(t, err)
assert.Equal(t, comment(3), sil3.Comment)
assert.Equal(t, types.SilenceStateActive, sil3.Status.State)
}
}

// Endpoint: GET /v2/silence/{id}
{
for _, c := range clients {
sil1, err := c.GetSilenceV2(context.Background(), id1)
sil1, err := c.GetSilence(context.Background(), id1)
require.NoError(t, err)
assert.Equal(t, comment(1), sil1.Comment)
assert.Equal(t, types.SilenceStateActive, sil1.Status.State)

sil2, err := c.GetSilenceV2(context.Background(), id2)
sil2, err := c.GetSilence(context.Background(), id2)
require.NoError(t, err)
assert.Equal(t, comment(2), sil2.Comment)
assert.Equal(t, types.SilenceStateActive, sil2.Status.State)

sil3, err := c.GetSilenceV2(context.Background(), id3)
sil3, err := c.GetSilence(context.Background(), id3)
require.NoError(t, err)
assert.Equal(t, comment(3), sil3.Comment)
assert.Equal(t, types.SilenceStateActive, sil3.Status.State)
Expand Down Expand Up @@ -483,7 +505,7 @@ func TestAlertmanagerSharding(t *testing.T) {
require.NoError(t, waitForSilences("expired", 1*testCfg.replicationFactor))

for _, c := range clients {
list, err := c.GetSilencesV2(context.Background())
list, err := c.GetSilences(context.Background())
require.NoError(t, err)
assertSilences(list, types.SilenceStateActive, types.SilenceStateExpired, types.SilenceStateActive)
}
Expand All @@ -493,7 +515,7 @@ func TestAlertmanagerSharding(t *testing.T) {
require.NoError(t, waitForSilences("expired", 2*testCfg.replicationFactor))

for _, c := range clients {
list, err := c.GetSilencesV2(context.Background())
list, err := c.GetSilences(context.Background())
require.NoError(t, err)
assertSilences(list, types.SilenceStateActive, types.SilenceStateExpired, types.SilenceStateExpired)
}
Expand All @@ -503,7 +525,7 @@ func TestAlertmanagerSharding(t *testing.T) {
require.NoError(t, waitForSilences("expired", 3*testCfg.replicationFactor))

for _, c := range clients {
list, err := c.GetSilencesV2(context.Background())
list, err := c.GetSilences(context.Background())
require.NoError(t, err)
assertSilences(list, types.SilenceStateExpired, types.SilenceStateExpired, types.SilenceStateExpired)
}
Expand Down Expand Up @@ -543,22 +565,10 @@ func TestAlertmanagerSharding(t *testing.T) {
e2e.SkipMissingMetrics))
}

// Endpoint: GET /v1/alerts
{
// Reads will query at least two replicas and merge the results.
// Therefore, the alerts we posted should always be visible.

for _, c := range clients {
list, err := c.GetAlertsV1(context.Background())
require.NoError(t, err)
assert.ElementsMatch(t, []string{"alert_1", "alert_2", "alert_3"}, alertNames(list))
}
}

// Endpoint: GET /v2/alerts
{
for _, c := range clients {
list, err := c.GetAlertsV2(context.Background())
list, err := c.GetAlerts(context.Background())
require.NoError(t, err)
assert.ElementsMatch(t, []string{"alert_1", "alert_2", "alert_3"}, alertNames(list))
}
Expand All @@ -581,8 +591,6 @@ func TestAlertmanagerSharding(t *testing.T) {
require.Contains(t, groups, "group_2")
assert.ElementsMatch(t, []string{"alert_3"}, alertNames(groups["group_2"]))
}

// Note: /v1/alerts/groups does not exist.
}

// Check the alerts were eventually written to every replica.
Expand Down
Loading
Loading