diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d91a86329f..95085da8bac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Allow an optional function to resolve the `rootValue`, passing the `DocumentNode` AST to determine the value. [PR #1555](https://github.com/apollographql/apollo-server/pull/1555) - Follow-up on the work in [PR #1516](https://github.com/apollographql/apollo-server/pull/1516) to also fix missing insertion cursor/caret when a custom GraphQL configuration is specified which doesn't specify its own `cursorShape` property. [PR #1607](https://github.com/apollographql/apollo-server/pull/1607) - Allow JSON parsing in `RESTDataSource` of Content Type `application/hal+json`. [PR ##185](https://github.com/apollographql/apollo-server/pull/1853) +- Add support for a `requestAgent` configuration parameter within the `engine` configuration. This can be utilized when a proxy is necessary to transmit tracing and metrics data to Apollo Engine. It accepts either an [`http.Agent`](https://nodejs.org/docs/latest-v8.x/api/http.html#http_class_http_agent) or [`https.Agent`](https://nodejs.org/docs/latest-v8.x/api/https.html#https_class_https_agent) and behaves the same as the `agent` parameter to Node.js' [`http.request`](https://nodejs.org/docs/latest-v8.x/api/http.html#http_http_request_options_callback). [PR #1879](https://github.com/apollographql/apollo-server/pull/1879) ### v2.1.0 diff --git a/docs/source/api/apollo-server.md b/docs/source/api/apollo-server.md index 3b39fc456f6..06a88fc7fc6 100644 --- a/docs/source/api/apollo-server.md +++ b/docs/source/api/apollo-server.md @@ -322,6 +322,10 @@ addMockFunctionsToSchema({ The URL of the Engine report ingress server. +* `requestAgent`: `http.Agent | https.Agent | false` + + HTTP(s) agent to be used for Apollo Engine metrics reporting. This accepts either an [`http.Agent`](https://nodejs.org/docs/latest-v10.x/api/http.html#http_class_http_agent) or [`https.Agent`](https://nodejs.org/docs/latest-v10.x/api/https.html#https_class_https_agent) and behaves the same as the `agent` parameter to Node.js' [`http.request`](https://nodejs.org/docs/latest-v8.x/api/http.html#http_http_request_options_callback). + * `debugPrintReports`: boolean If set, prints all reports as JSON when they are sent. diff --git a/packages/apollo-engine-reporting/src/agent.ts b/packages/apollo-engine-reporting/src/agent.ts index 8d2587fe5be..83c67b4e7ec 100644 --- a/packages/apollo-engine-reporting/src/agent.ts +++ b/packages/apollo-engine-reporting/src/agent.ts @@ -8,7 +8,7 @@ import { Trace, } from 'apollo-engine-reporting-protobuf'; -import { fetch, Response } from 'apollo-server-env'; +import { fetch, RequestAgent, Response } from 'apollo-server-env'; import retry from 'async-retry'; import { EngineReportingExtension } from './extension'; @@ -60,6 +60,8 @@ export interface EngineReportingOptions { endpointUrl?: string; // If set, prints all reports as JSON when they are sent. debugPrintReports?: boolean; + // HTTP(s) agent to be used on the fetch call to apollo-engine metrics endpoint + requestAgent?: RequestAgent | false; // Reporting is retried with exponential backoff up to this many times // (including the original request). Defaults to 5. maxAttempts?: number; @@ -256,6 +258,7 @@ export class EngineReportingAgent { 'content-encoding': 'gzip', }, body: compressed, + agent: this.options.requestAgent, }); if (curResponse.status >= 500 && curResponse.status < 600) { diff --git a/packages/apollo-server-env/src/fetch.d.ts b/packages/apollo-server-env/src/fetch.d.ts index be422134a8d..6d138daea2b 100644 --- a/packages/apollo-server-env/src/fetch.d.ts +++ b/packages/apollo-server-env/src/fetch.d.ts @@ -1,10 +1,13 @@ -import { Agent } from 'http'; +import { Agent as HttpAgent } from 'http'; +import { Agent as HttpsAgent } from 'https'; export declare function fetch( input?: RequestInfo, init?: RequestInit, ): Promise; +export type RequestAgent = HttpAgent | HttpsAgent; + export type RequestInfo = Request | string; export declare class Headers implements Iterable<[string, string]> { @@ -58,7 +61,7 @@ export interface RequestInit { timeout?: number; compress?: boolean; size?: number; - agent?: Agent; + agent?: RequestAgent | false; // Cloudflare Workers accept a `cf` property to control Cloudflare features // See https://developers.cloudflare.com/workers/reference/cloudflare-features/ diff --git a/packages/apollo-server-env/src/global.d.ts b/packages/apollo-server-env/src/global.d.ts index c38e01e7d09..82813030cb7 100644 --- a/packages/apollo-server-env/src/global.d.ts +++ b/packages/apollo-server-env/src/global.d.ts @@ -12,6 +12,7 @@ type Headers = import('./fetch').Headers; type HeadersInit = import('./fetch').HeadersInit; type Body = import('./fetch').Body; type Request = import('./fetch').Request; +type RequestAgent = import('./fetch').RequestAgent; type RequestInit = import('./fetch').RequestInit; type RequestMode = import('./fetch').RequestMode; type RequestCredentials = import('./fetch').RequestCredentials;