-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start e2e test Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Fix flag, command Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Fix s3 file Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Dynamically create yaml file Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Start to add test Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Fix endpoint path Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Create rules_test, leaner yaml Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Finish first test cases Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Update test image, add more test cases Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Code review suggestions, add startServicesForRules function Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Update flag syntax Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Format, rewrite test names Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Check for tenant labels Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Create defaultTenantName const Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Rename test cases, remove write invalid rules case for now Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Remove unused invalidRulesYamlTpl Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Revert "Remove unused invalidRulesYamlTpl" This reverts commit ccd9a59. * Readd invalid rules test Signed-off-by: Jéssica Lins <jessicaalins@gmail.com> * Add missing new line Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
- Loading branch information
1 parent
cff5981
commit e486b89
Showing
8 changed files
with
321 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// +build integration | ||
|
||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/efficientgo/e2e" | ||
"github.com/efficientgo/tools/core/pkg/testutil" | ||
) | ||
|
||
func TestRulesAPI(t *testing.T) { | ||
t.Parallel() | ||
|
||
e, err := e2e.NewDockerEnvironment(envRulesAPIName) | ||
testutil.Ok(t, err) | ||
t.Cleanup(e.Close) | ||
|
||
prepareConfigsAndCerts(t, rules, e) | ||
_, token, rateLimiterAddr := startBaseServices(t, e, rules) | ||
rulesEndpoint := startServicesForRules(t, e) | ||
|
||
api, err := newObservatoriumAPIService( | ||
e, | ||
withRulesEndpoint("http://"+rulesEndpoint), | ||
withRateLimiter(rateLimiterAddr), | ||
) | ||
testutil.Ok(t, err) | ||
testutil.Ok(t, e2e.StartAndWaitReady(api)) | ||
|
||
rulesEndpointURL := "https://" + api.Endpoint("https") + "/api/metrics/v1/"+defaultTenantName+"/api/v1/rules/raw" | ||
tr := &http.Transport{ | ||
TLSClientConfig: getTLSClientConfig(t, e), | ||
} | ||
|
||
client := &http.Client{ | ||
Transport: &tokenRoundTripper{rt: tr, token: token}, | ||
} | ||
|
||
t.Run("write-then-read-recording-rules", func(t *testing.T) { | ||
// Try to list rules | ||
r, err := http.NewRequest( | ||
http.MethodGet, | ||
rulesEndpointURL, | ||
nil, | ||
) | ||
testutil.Ok(t, err) | ||
|
||
res, err := client.Do(r) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, http.StatusNotFound, res.StatusCode) | ||
|
||
// Set a file containing a recording rule | ||
recordingRule := []byte(recordingRuleYamlTpl) | ||
r, err = http.NewRequest( | ||
http.MethodPut, | ||
rulesEndpointURL, | ||
bytes.NewReader(recordingRule), | ||
) | ||
testutil.Ok(t, err) | ||
|
||
res, err = client.Do(r) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, http.StatusOK, res.StatusCode) | ||
|
||
// Check if recording rule is listed | ||
r, err = http.NewRequest( | ||
http.MethodGet, | ||
rulesEndpointURL, | ||
nil, | ||
) | ||
testutil.Ok(t, err) | ||
|
||
res, err = client.Do(r) | ||
defer res.Body.Close() | ||
|
||
testutil.Ok(t, err) | ||
testutil.Equals(t, http.StatusOK, res.StatusCode) | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
bodyStr := string(body) | ||
|
||
assertResponse(t, bodyStr, "sum by (job) (http_inprogress_requests)") | ||
assertResponse(t, bodyStr, "tenant_id: "+defaultTenantID) | ||
}) | ||
|
||
t.Run("write-then-read-alerting-rules", func(t *testing.T) { | ||
// Set a file containing an alerting rule | ||
alertingRule := []byte(alertingRuleYamlTpl) | ||
r, err := http.NewRequest( | ||
http.MethodPut, | ||
rulesEndpointURL, | ||
bytes.NewReader(alertingRule), | ||
) | ||
testutil.Ok(t, err) | ||
|
||
res, err := client.Do(r) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, http.StatusOK, res.StatusCode) | ||
|
||
// Check if the alerting rule is listed | ||
r, err = http.NewRequest( | ||
http.MethodGet, | ||
rulesEndpointURL, | ||
nil, | ||
) | ||
testutil.Ok(t, err) | ||
|
||
res, err = client.Do(r) | ||
defer res.Body.Close() | ||
|
||
testutil.Ok(t, err) | ||
testutil.Equals(t, http.StatusOK, res.StatusCode) | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
bodyStr := string(body) | ||
assertResponse(t, bodyStr, "alert: HighRequestLatency") | ||
assertResponse(t, bodyStr, "tenant_id: "+defaultTenantID) | ||
}) | ||
|
||
t.Run("write-then-read-recording-and-alerting-rules", func(t *testing.T) { | ||
// Set a file containing both recording and alerting rules | ||
recordAndAlertingRules := []byte(recordAndAlertingRulesYamlTpl) | ||
r, err := http.NewRequest( | ||
http.MethodPut, | ||
rulesEndpointURL, | ||
bytes.NewReader(recordAndAlertingRules), | ||
) | ||
testutil.Ok(t, err) | ||
|
||
res, err := client.Do(r) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, http.StatusOK, res.StatusCode) | ||
|
||
// Check if both recording and alerting rules are listed | ||
r, err = http.NewRequest( | ||
http.MethodGet, | ||
rulesEndpointURL, | ||
nil, | ||
) | ||
testutil.Ok(t, err) | ||
|
||
res, err = client.Do(r) | ||
defer res.Body.Close() | ||
|
||
testutil.Ok(t, err) | ||
testutil.Equals(t, http.StatusOK, res.StatusCode) | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
bodyStr := string(body) | ||
assertResponse(t, bodyStr, "record: job:up:avg") | ||
assertResponse(t, bodyStr, "alert: ManyInstancesDown") | ||
assertResponse(t, bodyStr, "tenant_id: "+defaultTenantID) | ||
}) | ||
t.Run("write-invalid-rules", func(t *testing.T) { | ||
// Set an invalid rules file | ||
invalidRules := []byte(invalidRulesYamlTpl) | ||
r, err := http.NewRequest( | ||
http.MethodPut, | ||
rulesEndpointURL, | ||
bytes.NewReader(invalidRules), | ||
) | ||
testutil.Ok(t, err) | ||
|
||
res, err := client.Do(r) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, http.StatusBadRequest, res.StatusCode) | ||
}) | ||
} | ||
|
Oops, something went wrong.