-
Notifications
You must be signed in to change notification settings - Fork 62
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
Rules API: Add e2e test #198
Conversation
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far 👍 Will wait on the remaining parts of the PR.
test/e2e/rules_test.go
Outdated
|
||
api, err := newObservatoriumAPIService( | ||
e, | ||
withMetricsEndpoints("", "", "http://"+rulesEndpoint), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might need to provide some write/read endpoint, otherwise API will complain that neither metrics nor logs endpoints are provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the test environment, since is using https://github.com/observatorium/api/blob/main/test/e2e/services.go#L224 this does not apply? It seems to append in case they are not empty: https://github.com/observatorium/api/blob/main/test/e2e/services.go#L250-L253 but no validation in case they are empty.
I also searched in the test output for this error message "Neither logging nor metrics endpoints are enabled. Specifying at least a logging or a metrics endpoint is mandatory"
from https://github.com/observatorium/api/blob/main/main.go#L199-L202 but I haven't found any matches
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
test/e2e/rules_test.go
Outdated
assertResponse(t, bodyStr, "alert: ManyInstancesDown") | ||
}) | ||
|
||
t.Run("put-invalid-rules", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@onprem for the case that invalid rules are submitted, I keep receiving no error/200 HTTP response status code, instead of https://github.com/observatorium/rules-objstore/blob/main/pkg/server/server.go#L80
I got this in the test output:
17:10:54 rules_objstore: level=debug name=rules-objstore ts=2022-01-19T20:10:54.115959093Z caller=server.go:81 component=server handler=setrules tenant=test-oidc msg="request body failed rule group validation" errs="unsupported value type"
17:10:54 observatorium_api: level=debug name=observatorium ts=2022-01-19T20:10:54.116175567Z caller=instrumentation.go:36 request=observatorium_api/NKsl1S6qrw-000009 proto=HTTP/1.1 method=PUT status=200 content= path=/api/metrics/v1/test-oidc/api/v1/rules/raw duration=1.492672ms bytes=42
I'll try to take a better look on this tomorrow, but I think either obs API is not fetching err/status code or rules-objstore is not returning/propagating them properly
test/e2e/configs.go
Outdated
@@ -18,6 +18,7 @@ type testType string | |||
|
|||
const ( | |||
metrics testType = "metrics" | |||
rules testType = "rules" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make format
should fix these rogue whitespaces 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weirdly if I run make format
locally I get:
jessica@cupsofwonder:~/workspace/api|rules-add-e2e ⇒ make format
/home/jessica/go/bin/golangci-lint-v1.21.0 run --fix --enable-all -c .golangci.yml
WARN [runner/nolint] Found unknown linters in //nolint directives: cyclop, exhaustivestruct, goerr113, gomnd, intefacer, paralleltest, testpackage
so somehow it did not give any more output than that and also did not change any of the files.
I then tried to run with my local golangci-lint
(with the latest version - 1.43.0) and it found some issues in the code, so I think we may tackle this separately? I wonder if would be good to also update the golangci-lint
version (with the latest version I get also some warnings of linters that are deprecated and we use them in the nolinter
directive (e.g. WARN [runner/nolint] Found unknown linters in //nolint directives: intefacer
)
Should I create a separate issue for that? Maybe makes sense to also link to this issue @matej-g already opened: #212
For now I run manually gofmt
to this config file, so the whitespaces should be fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, shouldn't the lint step fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be fixed now 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean the whitespaces or make format
?
To fix the whitespaces I ran gofmt
manually, but I thought would be fixed by running make format
instead (which does not seem to be the case) :(
test/e2e/rules_test.go
Outdated
Transport: &tokenRoundTripper{rt: tr, token: token}, | ||
} | ||
|
||
t.Run("get-put-recording-rules", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get-put-recording-rules
this is kind of confusing to me as to what the test is aiming to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed to read-write-recording-rules
(also to the further ones) - hopefully now is clearer?
It basically tests the reading (GET
) / writing (PUT
) of rules via the rules API defined in observatorium/api going through rules-objectstore
https://github.com/observatorium/api/pull/198/files#diff-368252fd7020798243fc9b3793b03207f23440bf25424123e38b77eabf42c3d3R28
test/e2e/rules_test.go
Outdated
testutil.Ok(t, err) | ||
testutil.Ok(t, e2e.StartAndWaitReady(api)) | ||
|
||
rulesEndpointURL := "https://" + api.Endpoint("https") + "/api/metrics/v1/test-oidc/api/v1/rules/raw" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the test-oidc
tenant name defined anywhere else? I just imagine if we change that we'll unexpectedly break this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point..we define it manually everywhere in the tests: https://github.com/observatorium/api/search?q=test-oidc
maybe makes sense to define it as a constant in configs.go
and use its value? I could open another pr for that or just already change it here (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added as a constant here: 0b60005
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
body, err := ioutil.ReadAll(res.Body) | ||
bodyStr := string(body) | ||
|
||
assertResponse(t, bodyStr, "sum by (job) (http_inprogress_requests)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea to check for tenant labels here? 🙂
With something like: assertResponse(t, bodyStr, "tenant_id: 1610b0c3-c509-4592-a256-a1871353dbfa")
(id taken from here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea! added here: 7d50a67
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of non-blocking naming nits & ticket to be created.
LGTM 🎉
test/e2e/rules_test.go
Outdated
Transport: &tokenRoundTripper{rt: tr, token: token}, | ||
} | ||
|
||
t.Run("read-write-recording-rules", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be a pedant with this - but the actual flow is more write-then-read-recording-rules
in the test happy path which would be the most accurate description. Not a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually for this test case is more like read-then-write-then-read
(because we read first, even though we have no rules submitted yet) but I'd prefer your suggestion too :)
test/e2e/rules_test.go
Outdated
assertResponse(t, bodyStr, "tenant_id: "+defaultTenantID) | ||
}) | ||
|
||
t.Run("read-write-alerting-rules", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto - write-then-read-alerting-rules
would be my first choice but not a blocker.
test/e2e/rules_test.go
Outdated
) | ||
testutil.Ok(t, err) | ||
res, err := client.Do(r) | ||
//TODO: an error/http status code is not being returned to the API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're not fixing this issue in this PR then please let's create a ticket and reference it so we don't loose sight of this problem :)
TODO (MON-XXXX) - an error/http...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, I've removed the test case for now and will create a ticket by EOD :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a bug ticket here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should get fixed by #218. 🙂
Also - we can see that your tests are passing in CI here! |
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is looking great, nice job @jessicalins 🎉
|
||
defaultTenantID = "1610b0c3-c509-4592-a256-a1871353dbfa" | ||
mtlsTenantID = "845cdfd9-f936-443c-979c-2ee7dc91f646" | ||
|
||
defaultTenantName = "test-oidc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍 👍
test/e2e/rules_test.go
Outdated
assertResponse(t, bodyStr, "alert: ManyInstancesDown") | ||
assertResponse(t, bodyStr, "tenant_id: "+defaultTenantID) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Missing newline
This reverts commit ccd9a59.
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
Signed-off-by: Jéssica Lins <jessicaalins@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we addressed everything, thanks again @jessicalins 🎉
This PR
starts toadds an e2e test to the Rules API.Already opening as a draft to get some feedback about the overall structure.What is currently missing:- Test thanos-ruler-syncer flow- after talking with @onprem we thought not adding a test here since this is already covered in the other repos (rules-objstore
/thanos-rule-syncer
)- Test 'unhappy' cases