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

TNT-46700 Add proxy configuration #116

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
"lerna": "^4.0.0",
"prettier": "^2.7.1",
"pretty-quick": "^3.1.3"
},
"dependencies": {
"undici": "^5.18.0"
}
}
1 change: 1 addition & 0 deletions packages/target-decisioning-engine/src/artifactProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function ArtifactProvider(config, telemetryProvider) {

const fetchWithRetry = getFetchWithRetry(
fetchApi,
config.proxyAgent,
NUM_FETCH_RETRIES,
errorMessage => Messages.ERROR_MAX_RETRY(NUM_FETCH_RETRIES, errorMessage),
error => eventEmitter(ARTIFACT_DOWNLOAD_FAILED, { artifactLocation, error })
Expand Down
10 changes: 7 additions & 3 deletions packages/target-decisioning-engine/src/geoProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ export function GeoProvider(config, artifact) {
headers[HTTP_HEADER_FORWARDED_FOR] = geoRequestContext.ipAddress;
}

return fetchApi(geoLookupPath, {
headers
})
const options = { headers };

if (config.proxyAgent != null) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest simplifying a bit

Suggested change
if (config.proxyAgent != null) {
if (config.proxyAgent) {

Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency let's use isDefined please.

if(isDefined(config.proxyAgent)) {

options.dispatcher = config.proxyAgent;
}

return fetchApi(geoLookupPath, options)
.then(geoResponse =>
geoResponse
.json()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DecisioningArtifact } from "./DecisioningArtifact";
import { ParseDomainFunc } from "./DecisioningContext";
import { ProxyAgent } from "undici";

export interface DecisioningConfig {
/**
Expand Down Expand Up @@ -86,4 +87,9 @@ export interface DecisioningConfig {
* Function used to parse domains
*/
parseDomainImpl?: ParseDomainFunc;

/**
* Proxy Agent to specify a proxy for the fetch implementation
*/
proxyAgent: ProxyAgent;
Copy link
Member

Choose a reason for hiding this comment

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

Should probably also be nullable

Suggested change
proxyAgent: ProxyAgent;
proxyAgent?: ProxyAgent;

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add undici as a dependency and use this ProxyAgent object? What is the benefit? It is a standard? I wonder if we can define a basic proxy of our own in target tools.

Copy link
Contributor Author

@ericfichtel ericfichtel Feb 10, 2023

Choose a reason for hiding this comment

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

undici fetch is expecting an undici Dispatcher in fetch.options.dispatcher, which is the recommended solution for adding a proxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dispatcher extends node's events.EventEmitter, so it could be possible to omit the undici dependency through extending that, but that seems like it would be out of the scope of this ticket

}
Loading