Skip to content

Commit 570a1a0

Browse files
committed
fixing more tests
Signed-off-by: alanprot <alanprot@gmail.com>
1 parent d1a2139 commit 570a1a0

File tree

7 files changed

+46
-66
lines changed

7 files changed

+46
-66
lines changed

docs/configuration/config-file-reference.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,10 +4079,6 @@ ruler_client:
40794079
# CLI flag: -ruler.alertmanager-refresh-interval
40804080
[alertmanager_refresh_interval: <duration> | default = 1m]
40814081
4082-
# If enabled requests to Alertmanager will utilize the V2 API.
4083-
# CLI flag: -ruler.alertmanager-use-v2
4084-
[enable_alertmanager_v2: <boolean> | default = false]
4085-
40864082
# Capacity of the queue for notifications to be sent to the Alertmanager.
40874083
# CLI flag: -ruler.notification-queue-capacity
40884084
[notification_queue_capacity: <int> | default = 10000]

integration/alertmanager_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"bytes"
88
"context"
99
"fmt"
10-
"net/http"
1110
"strings"
1211
"testing"
1312
"time"
@@ -68,25 +67,6 @@ func TestAlertmanager(t *testing.T) {
6867

6968
// Ensure no service-specific metrics prefix is used by the wrong service.
7069
assertServiceMetricsPrefixes(t, AlertManager, alertmanager)
71-
72-
// Test compression by inspecting the response Headers
73-
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/api/v2/alerts", alertmanager.HTTPEndpoint()), nil)
74-
require.NoError(t, err)
75-
76-
req.Header.Set("X-Scope-OrgID", "user-1")
77-
req.Header.Set("Accept-Encoding", "gzip")
78-
79-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
80-
defer cancel()
81-
82-
// Execute HTTP request
83-
res, err := http.DefaultClient.Do(req.WithContext(ctx))
84-
require.NoError(t, err)
85-
86-
defer res.Body.Close()
87-
// We assert on the Vary header as the minimum response size for enabling compression is 1500 bytes.
88-
// This is enough to know whenever the handler for compression is enabled or not.
89-
require.Equal(t, "Accept-Encoding", res.Header.Get("Vary"))
9070
}
9171

9272
func TestAlertmanagerStoreAPI(t *testing.T) {

integration/e2ecortex/client.go

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/gogo/protobuf/proto"
1616
"github.com/golang/snappy"
17+
open_api_models "github.com/prometheus/alertmanager/api/v2/models"
1718
alertConfig "github.com/prometheus/alertmanager/config"
1819
"github.com/prometheus/alertmanager/types"
1920
promapi "github.com/prometheus/client_golang/api"
@@ -614,7 +615,7 @@ func (c *Client) getRawPage(ctx context.Context, url string) ([]byte, error) {
614615

615616
// GetAlertmanagerConfig gets the status of an alertmanager instance
616617
func (c *Client) GetAlertmanagerConfig(ctx context.Context) (*alertConfig.Config, error) {
617-
u := c.alertmanagerClient.URL("/api/prom/api/v1/status", nil)
618+
u := c.alertmanagerClient.URL("/api/prom/api/v2/status", nil)
618619

619620
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
620621
if err != nil {
@@ -634,16 +635,17 @@ func (c *Client) GetAlertmanagerConfig(ctx context.Context) (*alertConfig.Config
634635
return nil, fmt.Errorf("getting config failed with status %d and error %v", resp.StatusCode, string(body))
635636
}
636637

637-
var ss *ServerStatus
638-
err = json.Unmarshal(body, &ss)
638+
cfg := &open_api_models.AlertmanagerStatus{}
639+
err = yaml.Unmarshal(body, cfg)
640+
639641
if err != nil {
640642
return nil, err
641643
}
642644

643-
cfg := &alertConfig.Config{}
644-
err = yaml.Unmarshal([]byte(ss.Data.ConfigYaml), cfg)
645+
original := &alertConfig.Config{}
646+
err = yaml.Unmarshal([]byte(*cfg.Config.Original), original)
645647

646-
return cfg, err
648+
return original, err
647649
}
648650

649651
// SetAlertmanagerConfig gets the status of an alertmanager instance
@@ -817,22 +819,14 @@ func (c *Client) CreateSilence(ctx context.Context, silence types.Silence) (stri
817819
}
818820

819821
type response struct {
820-
Status string `json:"status"`
821-
Data struct {
822-
SilenceID string `json:"silenceID"`
823-
} `json:"data"`
822+
SilenceID string `json:"silenceID"`
824823
}
825824

826825
decoded := &response{}
827826
if err := json.Unmarshal(body, decoded); err != nil {
828827
return "", err
829828
}
830-
831-
if decoded.Status != "success" {
832-
return "", fmt.Errorf("unexpected response status '%s'", decoded.Status)
833-
}
834-
835-
return decoded.Data.SilenceID, nil
829+
return decoded.SilenceID, nil
836830
}
837831

838832
func (c *Client) GetSilencesV2(ctx context.Context) ([]types.Silence, error) {
@@ -894,7 +888,7 @@ func (c *Client) GetSilenceV2(ctx context.Context, id string) (types.Silence, er
894888
}
895889

896890
func (c *Client) DeleteSilence(ctx context.Context, id string) error {
897-
u := c.alertmanagerClient.URL(fmt.Sprintf("api/prom/api/v1/silence/%s", url.PathEscape(id)), nil)
891+
u := c.alertmanagerClient.URL(fmt.Sprintf("api/prom/api/v2/silence/%s", url.PathEscape(id)), nil)
898892

899893
req, err := http.NewRequest(http.MethodDelete, u.String(), nil)
900894
if err != nil {
@@ -918,7 +912,7 @@ func (c *Client) DeleteSilence(ctx context.Context, id string) error {
918912
}
919913

920914
func (c *Client) GetReceivers(ctx context.Context) ([]string, error) {
921-
u := c.alertmanagerClient.URL("api/prom/api/v1/receivers", nil)
915+
u := c.alertmanagerClient.URL("api/prom/api/v2/receivers", nil)
922916

923917
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
924918
if err != nil {
@@ -938,21 +932,21 @@ func (c *Client) GetReceivers(ctx context.Context) ([]string, error) {
938932
return nil, fmt.Errorf("getting receivers failed with status %d and error %v", resp.StatusCode, string(body))
939933
}
940934

935+
r := []string{}
941936
type response struct {
942-
Status string `json:"status"`
943-
Data []string `json:"data"`
937+
Name string `json:"name"`
944938
}
945939

946-
decoded := &response{}
947-
if err := json.Unmarshal(body, decoded); err != nil {
940+
decoded := []response{}
941+
if err := json.Unmarshal(body, &decoded); err != nil {
948942
return nil, err
949943
}
950944

951-
if decoded.Status != "success" {
952-
return nil, fmt.Errorf("unexpected response status '%s'", decoded.Status)
945+
for _, d := range decoded {
946+
r = append(r, d.Name)
953947
}
954948

955-
return decoded.Data, nil
949+
return r, nil
956950
}
957951

958952
func (c *Client) PostRequest(url string, body io.Reader) (*http.Response, error) {

pkg/api/api.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,6 @@ func (a *API) RegisterAlertmanager(am *alertmanager.MultitenantAlertmanager, tar
221221
a.RegisterRoutesWithPrefix(a.cfg.AlertmanagerHTTPPrefix, am, true)
222222
level.Debug(a.logger).Log("msg", "api: registering alertmanager", "path_prefix", a.cfg.AlertmanagerHTTPPrefix)
223223

224-
// MultiTenant Alertmanager Experimental API routes
225-
if apiEnabled {
226-
a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.GetUserConfig), true, "GET")
227-
a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.SetUserConfig), true, "POST")
228-
a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.DeleteUserConfig), true, "DELETE")
229-
}
230-
231224
// If the target is Alertmanager, enable the legacy behaviour. Otherwise only enable
232225
// the component routed API.
233226
if target {

pkg/ingester/client/compat_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,27 @@ func TestQueryRequest(t *testing.T) {
5454
if !reflect.DeepEqual(haveTo, to) {
5555
t.Fatalf("Bad to FromQueryRequest(ToQueryRequest) round trip")
5656
}
57-
if !reflect.DeepEqual(haveMatchers, matchers) {
57+
if !matchersEqual(haveMatchers, matchers) {
5858
t.Fatalf("Bad have FromQueryRequest(ToQueryRequest) round trip - %v != %v", haveMatchers, matchers)
5959
}
6060
}
6161

62+
func matchersEqual(expected, actual []*labels.Matcher) bool {
63+
if len(expected) != len(actual) {
64+
return false
65+
}
66+
67+
for i := 0; i < len(expected); i++ {
68+
a := actual[i]
69+
e := expected[i]
70+
if a.Name != e.Name || a.Value != e.Value || a.Type != e.Type {
71+
return false
72+
}
73+
}
74+
75+
return true
76+
}
77+
6278
func buildTestMatrix(numSeries int, samplesPerSeries int, offset int) model.Matrix {
6379
m := make(model.Matrix, 0, numSeries)
6480
for i := 0; i < numSeries; i++ {

pkg/ruler/notifier_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestBuildNotifierConfig(t *testing.T) {
3737
AlertingConfig: config.AlertingConfig{
3838
AlertmanagerConfigs: []*config.AlertmanagerConfig{
3939
{
40-
APIVersion: "v1",
40+
APIVersion: "v2",
4141
Scheme: "http",
4242
PathPrefix: "/alertmanager",
4343
ServiceDiscoveryConfigs: discovery.Configs{
@@ -63,7 +63,7 @@ func TestBuildNotifierConfig(t *testing.T) {
6363
AlertingConfig: config.AlertingConfig{
6464
AlertmanagerConfigs: []*config.AlertmanagerConfig{
6565
{
66-
APIVersion: "v1",
66+
APIVersion: "v2",
6767
Scheme: "http",
6868
PathPrefix: "/alertmanager",
6969
ServiceDiscoveryConfigs: discovery.Configs{
@@ -96,7 +96,7 @@ func TestBuildNotifierConfig(t *testing.T) {
9696
AlertingConfig: config.AlertingConfig{
9797
AlertmanagerConfigs: []*config.AlertmanagerConfig{
9898
{
99-
APIVersion: "v1",
99+
APIVersion: "v2",
100100
Scheme: "http",
101101
PathPrefix: "/alertmanager",
102102
ServiceDiscoveryConfigs: discovery.Configs{
@@ -107,7 +107,7 @@ func TestBuildNotifierConfig(t *testing.T) {
107107
},
108108
},
109109
{
110-
APIVersion: "v1",
110+
APIVersion: "v2",
111111
Scheme: "http",
112112
PathPrefix: "/alertmanager",
113113
ServiceDiscoveryConfigs: discovery.Configs{
@@ -132,7 +132,7 @@ func TestBuildNotifierConfig(t *testing.T) {
132132
AlertingConfig: config.AlertingConfig{
133133
AlertmanagerConfigs: []*config.AlertmanagerConfig{
134134
{
135-
APIVersion: "v1",
135+
APIVersion: "v2",
136136
Scheme: "http",
137137
PathPrefix: "/alertmanager",
138138
ServiceDiscoveryConfigs: discovery.Configs{
@@ -145,7 +145,7 @@ func TestBuildNotifierConfig(t *testing.T) {
145145
},
146146
},
147147
{
148-
APIVersion: "v1",
148+
APIVersion: "v2",
149149
Scheme: "http",
150150
PathPrefix: "/alertmanager",
151151
ServiceDiscoveryConfigs: discovery.Configs{
@@ -173,7 +173,7 @@ func TestBuildNotifierConfig(t *testing.T) {
173173
HTTPClientConfig: config_util.HTTPClientConfig{
174174
BasicAuth: &config_util.BasicAuth{Username: "marco", Password: "hunter2"},
175175
},
176-
APIVersion: "v1",
176+
APIVersion: "v2",
177177
Scheme: "http",
178178
PathPrefix: "/alertmanager",
179179
ServiceDiscoveryConfigs: discovery.Configs{
@@ -206,7 +206,7 @@ func TestBuildNotifierConfig(t *testing.T) {
206206
HTTPClientConfig: config_util.HTTPClientConfig{
207207
BasicAuth: &config_util.BasicAuth{Username: "jacob", Password: "test"},
208208
},
209-
APIVersion: "v1",
209+
APIVersion: "v2",
210210
Scheme: "http",
211211
PathPrefix: "/alertmanager",
212212
ServiceDiscoveryConfigs: discovery.Configs{
@@ -233,7 +233,7 @@ func TestBuildNotifierConfig(t *testing.T) {
233233
AlertingConfig: config.AlertingConfig{
234234
AlertmanagerConfigs: []*config.AlertmanagerConfig{
235235
{
236-
APIVersion: "v1",
236+
APIVersion: "v2",
237237
Scheme: "http",
238238
PathPrefix: "/alertmanager",
239239
ServiceDiscoveryConfigs: discovery.Configs{

pkg/ruler/ruler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
175175
flagext.DeprecatedFlag(f, "ruler.group-timeout", "This flag is no longer functional.", util_log.Logger)
176176
//lint:ignore faillint Need to pass the global logger like this for warning on deprecated methods
177177
flagext.DeprecatedFlag(f, "ruler.num-workers", "This flag is no longer functional. For increased concurrency horizontal sharding is recommended", util_log.Logger)
178+
//lint:ignore faillint Need to pass the global logger like this for warning on deprecated methods
178179
flagext.DeprecatedFlag(f, "ruler.alertmanager-use-v2", "This flag is no longer functional. V1 API is deprecated and removed", util_log.Logger)
179180

180181
cfg.ExternalURL.URL, _ = url.Parse("") // Must be non-nil

0 commit comments

Comments
 (0)