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

[Flaky tests] Metric's server collector's integration tests #127139

Merged
merged 3 commits into from
Mar 9, 2022

Conversation

afharo
Copy link
Member

@afharo afharo commented Mar 8, 2022

Summary

Resolves #59234.

It uses the aborted$ event to identify when the requests' abort actually happen instead of relying on delays that proved to be flaky.

NOTE: There's the risk that the aborted$ emitter wouldn't work as expected #125240. But it should be fixed at the emitter's level. IMO, these tests should consider the emitter just works.

Checklist

For maintainers

Backporting strategy

I think it's safe to backport these to the active branches 8.1 and 7.17 because it's only reenabling the tests, and it will provide our releases with more confidence in test coverage. Should we also backport it to 8.0 or is it OK to leave that gap?

@afharo afharo added release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated: Automatically backport this PR after it's merged v8.2.0 v8.1.1 v7.17.2 labels Mar 8, 2022
@afharo afharo requested a review from a team as a code owner March 8, 2022 12:30
Copy link
Member Author

@afharo afharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review


router.get({ path: '/', validate: false }, async (ctx, req, res) => {
return res.ok({ body: '' });
});
router.get({ path: '/disconnect', validate: false }, async (ctx, req, res) => {
hitSubject.next(hitSubject.value + 1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for a plain Subject vs. BehaviourSubject(counter) just in case it was affected by concurrent read/writes:

  1. The 2 /disconnect requests occur at a similar time
  2. This line is executed when hitSubject.value still holds 0 for both requests.

IMO, for the purpose of the test, it's enough relying on the .pipe(take(2)) approach. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hitSubject.next(hitSubject.value + 1); is synchronous, so 'atomical' for the event loop. I don't think there's any risk for concurrency problems. But using a plain subject and counting the emissions works fine too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining! I was mostly concerned if calling .next would synchronously update .value to consider it atomic. Since it's a RxJS internal implementation, I was not sure. Glad to know that's the case!

Copy link
Contributor

@pgayvallet pgayvallet Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mostly concerned if calling .next would synchronously update .value to consider it atomic

AFAIK it does (it even call the current subscribers synchronously), but I agree that we should probably consider this as an implementation detail of RXJS

@@ -125,7 +121,8 @@ describe.skip('ServerMetricsCollector', () => {
);

discoReq2.abort();
await delay(requestWaitDelay);
// Wait for the aborted$ event
await disconnectAborted$.pipe(take(1)).toPromise();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my previous comment: we could use a BehaviourSubject(counter). It could seem more explicit since we would check the counter === 2 vs. this approach that looks for increments. However, it feels concurrently safer this approach.

What do you think?

@afharo
Copy link
Member Author

afharo commented Mar 8, 2022

@elasticmachine merge upstream


router.get({ path: '/', validate: false }, async (ctx, req, res) => {
return res.ok({ body: '' });
});
router.get({ path: '/disconnect', validate: false }, async (ctx, req, res) => {
hitSubject.next(hitSubject.value + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hitSubject.next(hitSubject.value + 1); is synchronous, so 'atomical' for the event loop. I don't think there's any risk for concurrency problems. But using a plain subject and counting the emissions works fine too.

Comment on lines 96 to 100
const discoReq1 = sendGet('/disconnect').end();
const discoReq2 = sendGet('/disconnect').end();

// Wait for 2 requests to /disconnect
await disconnectRequested$.pipe(take(2)).toPromise();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: we're subscribing to the observable after having sent the requests. I think the risk of missing an emission is kinda non-existent, but just to be safe, I'd either use a replay effect on disconnectRequested$, or:

const disconnectRequested = disconnectRequested$.pipe(take(2)).toPromise();
const discoReq1 = sendGet('/disconnect').end();
const discoReq2 = sendGet('/disconnect').end();
await disconnectRequested;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll make sure to subscribe before triggering any event.

@afharo afharo enabled auto-merge (squash) March 9, 2022 09:53
@afharo afharo merged commit 6bcce44 into elastic:main Mar 9, 2022
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@afharo afharo deleted the flaky-test-metrics-server_collector branch March 9, 2022 11:19
kibanamachine pushed a commit that referenced this pull request Mar 9, 2022
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 6bcce44)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.1
7.17 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 127139

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 9, 2022
…#127263)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 6bcce44)

Co-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co>
afharo added a commit that referenced this pull request Mar 9, 2022
…#127264)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 6bcce44)

# Conflicts:
#	src/core/server/metrics/integration_tests/server_collector.test.ts

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated: Automatically backport this PR after it's merged release_note:skip Skip the PR/issue when compiling release notes v7.17.2 v8.1.1 v8.2.0
Projects
None yet
4 participants