Skip to content

Commit

Permalink
Re-enable e2e test for ruler
Browse files Browse the repository at this point in the history
E2E tests for ruler are currently marked as skip. This re-enables the test until it breaks again
and we are able to catch the flakiness.

Also, it removes the test for AlertManager HTTP client pending when we can improve on implementation
(see thanos-io#4056).

Signed-off-by: Michael Okoko <okokomichaels@outlook.com>
  • Loading branch information
idoqo committed May 31, 2021
1 parent 73e7c88 commit 7f41aa5
Showing 1 changed file with 0 additions and 101 deletions.
101 changes: 0 additions & 101 deletions test/e2e/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
"bytes"
"context"
"encoding/json"
"encoding/pem"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"sync"
Expand All @@ -29,7 +27,6 @@ import (
"github.com/thanos-io/thanos/pkg/promclient"
"github.com/thanos-io/thanos/pkg/query"
"github.com/thanos-io/thanos/pkg/rules/rulespb"
"github.com/thanos-io/thanos/pkg/runutil"
"github.com/thanos-io/thanos/pkg/testutil"
"github.com/thanos-io/thanos/test/e2e/e2ethanos"
)
Expand Down Expand Up @@ -223,105 +220,7 @@ func (m *mockAlertmanager) ServeHTTP(resp http.ResponseWriter, req *http.Request
m.mtx.Unlock()
}

// TestRule_AlertmanagerHTTPClient verifies that Thanos Ruler can send alerts to
// Alertmanager in various setups:
// * Plain HTTP.
// * HTTPS with custom CA.
// * API with a prefix.
// * API protected by bearer token authentication.
//
// Because Alertmanager supports HTTP only and no authentication, the test uses
// a mocked server instead of the "real" Alertmanager service.
// The other end-to-end tests exercise against the "real" Alertmanager
// implementation.
func TestRule_AlertmanagerHTTPClient(t *testing.T) {
t.Skip("TODO: Allow HTTP ports from binaries running on host to be accessible.")

s, err := e2e.NewScenario("e2e_test_rule_am_http_client")
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, s))

tlsSubDir := filepath.Join("tls")
testutil.Ok(t, os.MkdirAll(filepath.Join(s.SharedDir(), tlsSubDir), os.ModePerm))

// API v1 with plain HTTP and a prefix.
handler1 := newMockAlertmanager("/prefix/api/v1/alerts", "")
srv1 := httptest.NewServer(handler1)
t.Cleanup(srv1.Close)

// API v2 with HTTPS and authentication.
handler2 := newMockAlertmanager("/api/v2/alerts", "secret")
srv2 := httptest.NewTLSServer(handler2)
t.Cleanup(srv2.Close)

var out bytes.Buffer
testutil.Ok(t, pem.Encode(&out, &pem.Block{Type: "CERTIFICATE", Bytes: srv2.TLS.Certificates[0].Certificate[0]}))
caFile := filepath.Join(s.SharedDir(), tlsSubDir, "ca.crt")
testutil.Ok(t, ioutil.WriteFile(caFile, out.Bytes(), 0640))

rulesSubDir := filepath.Join("rules")
testutil.Ok(t, os.MkdirAll(filepath.Join(s.SharedDir(), rulesSubDir), os.ModePerm))
createRuleFiles(t, filepath.Join(s.SharedDir(), rulesSubDir))

r, err := e2ethanos.NewRuler(s.SharedDir(), "1", rulesSubDir, []alert.AlertmanagerConfig{
{
EndpointsConfig: http_util.EndpointsConfig{
StaticAddresses: []string{srv1.Listener.Addr().String()},
Scheme: "http",
PathPrefix: "/prefix/",
},
Timeout: model.Duration(time.Second),
APIVersion: alert.APIv1,
},
{
HTTPClientConfig: http_util.ClientConfig{
TLSConfig: http_util.TLSConfig{
CAFile: filepath.Join(e2e.ContainerSharedDir, tlsSubDir, "ca.crt"),
},
BearerToken: "secret",
},
EndpointsConfig: http_util.EndpointsConfig{
StaticAddresses: []string{srv2.Listener.Addr().String()},
Scheme: "https",
},
Timeout: model.Duration(time.Second),
APIVersion: alert.APIv2,
},
}, []query.Config{
{
EndpointsConfig: http_util.EndpointsConfig{
StaticAddresses: func() []string {
q, err := e2ethanos.NewQuerier(s.SharedDir(), "1", nil, nil, nil, nil, nil, nil, "", "")
testutil.Ok(t, err)
return []string{q.NetworkHTTPEndpointFor(s.NetworkName())}
}(),
Scheme: "http",
},
},
})
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(r))

q, err := e2ethanos.NewQuerier(s.SharedDir(), "1", []string{r.GRPCNetworkEndpoint()}, nil, nil, nil, nil, nil, "", "")
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(q))

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
t.Cleanup(cancel)

testutil.Ok(t, runutil.Retry(5*time.Second, ctx.Done(), func() (err error) {
for i, am := range []*mockAlertmanager{handler1, handler2} {
if len(am.Alerts()) == 0 {
return errors.Errorf("no alert received from handler%d, last error: %v", i, am.LastError())
}
}

return nil
}))
}

func TestRule(t *testing.T) {
t.Skip("Flaky test. Fix it. See: https://github.com/thanos-io/thanos/issues/3425.")
t.Parallel()

s, err := e2e.NewScenario("e2e_test_rule")
Expand Down

0 comments on commit 7f41aa5

Please sign in to comment.