Repository navigation
A11Y-13909: forward the Test Observability collector to the remote reporter #1210
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
Open
manish-bothra
wants to merge
12
commits into
browserstack:master
Choose a base branch
from
manish-bothra:A11Y-13909-forward-observability-api-url
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
024cd0a
Forward the Test Observability collector URL to the remote reporter
manish-bothra bf87243
Allow a separate collector for the remote reporter
manish-bothra 0166a03
Require https for the collector overrides and isolate the env vars in…
manish-bothra e7d01ac
Parse the collector override as a URL and reject a query or fragment
manish-bothra fc37d26
Normalise the collector override and keep its value out of errors
manish-bothra c40a12b
Cover the request destination, not just the forwarded env var
manish-bothra 3bf5017
Read the collector override lazily and validate it on the runs path
manish-bothra 7169d3d
Validate the general collector override too, not only the remote one
manish-bothra 068bbe8
A11Y-13909: warn on a remote-only collector, and make the load-safety…
manish-bothra 1c70e71
A11Y-13909: keep the collector value out of the log, and share the en…
manish-bothra 632b2c5
A11Y-13909: name only the collector host in the split-collector warning
manish-bothra 8513d91
Merge branch 'master' into A11Y-13909-forward-observability-api-url
manish-bothra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
| 'use strict'; | ||
| const chai = require('chai'); | ||
| const expect = chai.expect; | ||
| const sinon = require('sinon'); | ||
| const proxyquire = require('proxyquire').noPreserveCache(); | ||
|
|
||
| const API_URL_ENV = 'BROWSERSTACK_TEST_OBSERVABILITY_API_URL'; | ||
| const DEFAULT_API_URL = 'https://collector-observability.browserstack.com'; | ||
| const HELPER_PATH = '../../../../bin/testObservability/helper/helper'; | ||
| const CONSTANTS_PATH = '../../../../bin/testObservability/helper/constants'; | ||
|
|
||
| // A11Y-13909: the reporter runs on the BrowserStack machine from its own install of this package, | ||
| // so the collector it posts to has to come from the environment the launching cli forwards. These | ||
| // pin the request destination itself, not just the forwarding done by setSystemEnvs. | ||
| describe('observability collector url', () => { | ||
| let savedApiUrl; | ||
|
|
||
| beforeEach(() => { | ||
| savedApiUrl = process.env[API_URL_ENV]; | ||
| delete process.env[API_URL_ENV]; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (savedApiUrl === undefined) { | ||
| delete process.env[API_URL_ENV]; | ||
| } else { | ||
| process.env[API_URL_ENV] = savedApiUrl; | ||
| } | ||
| }); | ||
|
|
||
| const loadHelperWithAxios = () => { | ||
| const axiosStub = sinon.stub().resolves({ status: 200, data: '{}' }); | ||
| axiosStub['@noCallThru'] = true; | ||
| // proxyquire clears only the proxied module and its stubs, and the url is resolved in | ||
| // constants.js, so without this the url code is a cache hit and a module-load-time | ||
| // regression there would never turn these red. | ||
| delete require.cache[require.resolve(CONSTANTS_PATH)]; | ||
| const helper = proxyquire(HELPER_PATH, { axios: axiosStub }); | ||
| return { helper, axiosStub }; | ||
| }; | ||
|
|
||
| it('sends requests to the overridden collector', async () => { | ||
| const { helper, axiosStub } = loadHelperWithAxios(); | ||
| process.env[API_URL_ENV] = 'https://collector-example.bsstag.com'; | ||
|
|
||
| await helper.nodeRequest('POST', 'api/v1/batch', {}, { headers: {} }); | ||
|
|
||
| expect(axiosStub.firstCall.args[0].url).to.equal('https://collector-example.bsstag.com/api/v1/batch'); | ||
| }); | ||
|
|
||
| it('sends requests to the default collector when no override is set', async () => { | ||
| const { helper, axiosStub } = loadHelperWithAxios(); | ||
|
|
||
| await helper.nodeRequest('POST', 'api/v1/batch', {}, { headers: {} }); | ||
|
|
||
| expect(axiosStub.firstCall.args[0].url).to.equal(`${DEFAULT_API_URL}/api/v1/batch`); | ||
| }); | ||
|
|
||
| // Loading this module must never throw on a bad value: every command loads it through | ||
| // bin/helpers/utils.js, so init, info and stop would die at startup, as would the reporter. | ||
| it('does not reject an invalid collector url until a request is made', async () => { | ||
| process.env[API_URL_ENV] = 'http://collector-example.bsstag.com'; | ||
|
|
||
| let loaded; | ||
| expect(() => { loaded = loadHelperWithAxios(); }).to.not.throw(); | ||
| const { helper } = loaded; | ||
|
|
||
| let thrown; | ||
| await helper.nodeRequest('POST', 'api/v1/batch', {}, { headers: {} }).catch((err) => { thrown = err; }); | ||
| expect(String(thrown)).to.match(/must be an https:\/\/ URL/); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.