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

[Ingest Manager] Add more Fleet concurrency tests #71744 #72338

Merged
merged 6 commits into from
Jul 22, 2020

Conversation

jfsiii
Copy link
Contributor

@jfsiii jfsiii commented Jul 17, 2020

Summary

refs #71744

The limited concurrency is enforced by a global preAuth interceptor. limited_concurrency.ts exports createLimitedPreAuthHandler which allows to configure the "middleware" then make calls to it with mock data;

Looking for 👀& feedback on the approach & two JS/TS issues:

(1) see // @ts-ignore error re: mockPreAuthToolkit return type comments
(2)

TypeError: Invalid event target for request.events.aborted$

  console.warn
    TypeError: Invalid event target
        at setupSubscription (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/observable/fromEvent.ts:229:11)
        at Observable._subscribe (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/observable/fromEvent.ts:204:5)
        at Observable.Object.<anonymous>.Observable._trySubscribe (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/Observable.ts:238:19)
        at Observable.Object.<anonymous>.Observable.subscribe (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/Observable.ts:219:14)
        at TakeOperator.Object.<anonymous>.TakeOperator.call (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/operators/take.ts:72:19)
        at Observable.Object.<anonymous>.Observable.subscribe (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/Observable.ts:214:25)
        at ThrowIfEmptyOperator.Object.<anonymous>.ThrowIfEmptyOperator.call (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/operators/throwIfEmpty.ts:48:19)
        at Observable.Object.<anonymous>.Observable.subscribe (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/Observable.ts:214:25)
        at TakeUntilOperator.Object.<anonymous>.TakeUntilOperator.call (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/operators/takeUntil.ts:64:21)
        at Observable.Object.<anonymous>.Observable.subscribe (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/Observable.ts:214:25)
        at /Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/Observable.ts:360:12
        at new Promise (<anonymous>)
        at Observable.toPromise (/Users/jfsiii/work/kibana/node_modules/rxjs/src/internal/Observable.ts:358:12)
        at preAuthHandler (/Users/jfsiii/work/kibana/x-pack/plugins/ingest_manager/server/routes/limited_concurrency.ts:71:29)
        at Object.test (/Users/jfsiii/work/kibana/x-pack/plugins/ingest_manager/server/routes/limited_concurrency.test.ts:113:11)
        at Promise (/Users/jfsiii/work/kibana/node_modules/jest-circus/build/utils.js:198:28)
        at new Promise (<anonymous>)
        at callAsyncCircusFn (/Users/jfsiii/work/kibana/node_modules/jest-circus/build/utils.js:162:10)
        at _callCircusTest (/Users/jfsiii/work/kibana/node_modules/jest-circus/build/run.js:205:40)

      69 |     // requests.events.aborted$ has a bug (but has test which explicitly verifies) where it's fired even when the request completes
      70 |     // https://github.com/elastic/kibana/pull/70495#issuecomment-656288766
    > 71 |     request.events.aborted$.toPromise().then(() => {
         |                             ^
      72 |       maxCounter.decrease();
      73 |     });
      74 |

      at Observable.Object.<anonymous>.Observable._trySubscribe (../node_modules/rxjs/src/internal/Observable.ts:247:17)
      at Observable.Object.<anonymous>.Observable.subscribe (../node_modules/rxjs/src/internal/Observable.ts:219:14)
      at TakeOperator.Object.<anonymous>.TakeOperator.call (../node_modules/rxjs/src/internal/operators/take.ts:72:19)
      at Observable.Object.<anonymous>.Observable.subscribe (../node_modules/rxjs/src/internal/Observable.ts:214:25)
      at ThrowIfEmptyOperator.Object.<anonymous>.ThrowIfEmptyOperator.call (../node_modules/rxjs/src/internal/operators/throwIfEmpty.ts:48:19)
      at Observable.Object.<anonymous>.Observable.subscribe (../node_modules/rxjs/src/internal/Observable.ts:214:25)
      at TakeUntilOperator.Object.<anonymous>.TakeUntilOperator.call (../node_modules/rxjs/src/internal/operators/takeUntil.ts:64:21)
      at Observable.Object.<anonymous>.Observable.subscribe (../node_modules/rxjs/src/internal/Observable.ts:214:25)
      at ../node_modules/rxjs/src/internal/Observable.ts:360:12
      at Observable.toPromise (../node_modules/rxjs/src/internal/Observable.ts:358:12)
      at preAuthHandler (plugins/ingest_manager/server/routes/limited_concurrency.ts:71:29)
      at Object.test (plugins/ingest_manager/server/routes/limited_concurrency.test.ts:113:11)

(2) seems to prevent decrease() from being called in the tests, but it is called in the app code.

Checklist

@jfsiii jfsiii added Team:Fleet Team label for Observability Data Collection Fleet team [zube]: In Progress labels Jul 17, 2020
@jfsiii
Copy link
Contributor Author

jfsiii commented Jul 18, 2020

@elasticmachine merge upstream

@jfsiii jfsiii marked this pull request as ready for review July 20, 2020 17:24
@jfsiii jfsiii requested a review from a team July 20, 2020 17:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/ingest-management (Team:Ingest Management)

@jfsiii
Copy link
Contributor Author

jfsiii commented Jul 20, 2020

@elastic/kibana-platform Can someone take a look at the two TS/JS issues I mention in the description? Let me know if I can give more information or pointers for any changes I should make to my code or platform code to fix/avoid them.

@jfsiii
Copy link
Contributor Author

jfsiii commented Jul 20, 2020

@elasticmachine merge upstream

@jfsiii jfsiii added release_note:skip Skip the PR/issue when compiling release notes v7.9.0 v8.0.0 labels Jul 20, 2020
@pgayvallet
Copy link
Contributor

pgayvallet commented Jul 21, 2020

1/ mockPreAuthToolkit return type

We mixed something up when we added the preAuth hook, the mock doesnt return the correct thing:

const createOnPreAuthToolkitMock = (): jest.Mocked<OnPreRoutingToolkit> => ({
next: jest.fn(),
rewriteUrl: jest.fn(),
});

2/ TypeError: Invalid event target for request.events.aborted$

I confirm I can reproduce the error

import { httpServerMock } from './http_server.mocks';

describe('foo', () => {
  it('bar', async () => {
    const req = httpServerMock.createKibanaRequest();
    await req.events.aborted$.toPromise();
  });
});

causes

 TypeError: Invalid event target
        at setupSubscription (/Users/pierregayvallet/DEV/workspaces/elastic/kibana/node_modules/rxjs/src/internal/observable/fromEvent.ts:229:11)
        at Observable._subscribe (/Users/pierregayvallet/DEV/workspaces/elastic/kibana/node_modules/rxjs/src/internal/observable/fromEvent.ts:204:5)
        at Observable.Object.<anonymous>.Observable._trySubscribe (/Users/pierregayvallet/DEV/workspaces/elastic/kibana/node_modules/rxjs/src/internal/Observable.ts:238:19)

3/ 2) seems to prevent decrease() from being called in the tests, but it is called in the app code.

Fixing the mock implementation to no longer throw is quite easy, however you have to keep in mind that the req.events.aborted$ observable will never emit from a mocked request in a jest unit test environment, meaning that decrease will not be called anyway.

cc @restrry

@pgayvallet
Copy link
Contributor

Created #72663

@jfsiii
Copy link
Contributor Author

jfsiii commented Jul 21, 2020

@jen-huang wdyt?

Copy link
Contributor

@jen-huang jen-huang left a comment

Choose a reason for hiding this comment

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

This test suite looks good based on the above limitations that we have.

Fixing the mock implementation to no longer throw is quite easy, however you have to keep in mind that the req.events.aborted$ observable will never emit from a mocked request in a jest unit test environment, meaning that decrease will not be called anyway.

@pgayvallet How can we prevent TypeError: Invalid event target from being thrown? @jfsiii I'd like to fix this aspect before merging, as the current error causes the test suite output to be quite noisy.

});

const mockRequest = httpServerMock.createKibanaRequest({
path: '/no/match',
Copy link
Contributor

Choose a reason for hiding this comment

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

based on the description, this looks like it should have a non-matching routeTags specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could have tags which do not match or, like this case, no tags at all. I could add some

@mshustov
Copy link
Contributor

How can we prevent TypeError: Invalid event target from being thrown?

@jen-huang Isn't it fixed in #72663 ?

@pgayvallet
Copy link
Contributor

Isn't it fixed in #72663 ?

It is, and the PR has just been merged. Could you please merge master and confirm both issues are resolved?

@jfsiii
Copy link
Contributor Author

jfsiii commented Jul 22, 2020

@jen-huang since the doesn't require any changes to the test code I'd like to merge now

@jfsiii
Copy link
Contributor Author

jfsiii commented Jul 22, 2020

@elasticmachine merge upstream

Copy link
Contributor

@jen-huang jen-huang left a comment

Choose a reason for hiding this comment

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

I misunderstood where the work needed to be done for the error not to be thrown :)

LGTM. Thanks for adding these tests!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

@jfsiii jfsiii merged commit 1343643 into elastic:master Jul 22, 2020
@jen-huang jen-huang removed the v7.9.0 label Jul 22, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 23, 2020
* master: (35 commits)
  Migrated karma tests to jest (elastic#72649)
  Migrate status page app to core (elastic#72017)
  Failing test: Jest Tests.src/plugins/vis_type_vega/public (elastic#71834)
  Fix Firefox TSVB flaky test with switch index patterns (elastic#72882)
  [ML] Fixing link to index management from file data visualizer (elastic#72863)
  test: 💍 add test for sub-expression variables (elastic#71644)
  fix bug (elastic#72809)
  [keystore] use get_keystore in server cli (elastic#72954)
  Show step number instead of incomplete step. (elastic#72866)
  Fix bug where user can't add an exception when "close alert" is checked (elastic#72919)
  [Monitoring] Fix issues displaying alerts (elastic#72891)
  [Ingest Manager] Add more Fleet concurrency tests elastic#71744 (elastic#72338)
  [Security Solution][Exceptions] - Update UI exceptions builder nested logic (elastic#72490)
  disable renovate masterIssue
  [ML] API integration tests for UPDATE data frame analytics endpoint (elastic#72710)
  [Uptime] Fix accessibility issue in Uptime app nav links (elastic#72926)
  [Maps] fix removing global filter from layer can cause app to start thrashing (elastic#72763)
  [Maps] fix blended layer aggregation error when using composite aggregation (elastic#72759)
  fix unexpected arguments to unload command
  Limits the upload size of lists to 9 meg size (elastic#72898)
  ...
@jen-huang
Copy link
Contributor

Don't forget backport :) As this is adding more test coverage (rather than fixing an existing test that impacts other branches, etc), I updated the label to just 7.10 instead of all the way back to 7.9.

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jul 23, 2020
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 72338 or prevent reminders by adding the backport:skip label.

jfsiii pushed a commit to jfsiii/kibana that referenced this pull request Jul 24, 2020
…tic#72338)

* Refactor to make more testable. Add more tests.

* Remove ts-ignores. Add comment re: testing limitation

Co-authored-by: Elastic Machine <[email protected]>
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jul 24, 2020
jfsiii pushed a commit that referenced this pull request Jul 24, 2020
…3213)

* Refactor to make more testable. Add more tests.

* Remove ts-ignores. Add comment re: testing limitation

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants