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

Allow schema reporting via environment variable #4206

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The version headers in this history reflect the versions of Apollo Server itself
- [__CHANGELOG for `@apollo/gateway`__](https://github.com/apollographql/apollo-server/blob/master/packages/apollo-gateway/CHANGELOG.md)
- [__CHANGELOG for `@apollo/federation`__](https://github.com/apollographql/apollo-server/blob/master/packages/apollo-federation/CHANGELOG.md)

### vNext

- `apollo-engine-reporting`: Add environment variable `APOLLO_SCHEMA_REPORTING` that can enable schema reporting. If `experimental__schemaReporting` is set it will override the environment variables.

### v2.14.3

- This release only includes patch updates to dependencies.
Expand Down
16 changes: 7 additions & 9 deletions packages/apollo-engine-reporting/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ describe('schema reporting', () => {

it('starts reporting if enabled', async () => {
const pluginInstance = plugin(
{
experimental_schemaReporting: true,
},
{},
addTrace,
{
startSchemaReporting,
executableSchemaIdGenerator,
},
schemaReport: true,
}
);

await pluginTestHarness({
Expand Down Expand Up @@ -97,13 +96,13 @@ describe('schema reporting', () => {
it('uses the override schema', async () => {
const pluginInstance = plugin(
{
experimental_schemaReporting: true,
experimental_overrideReportedSchema: typeDefs,
},
addTrace,
{
startSchemaReporting,
executableSchemaIdGenerator,
schemaReport: true,
},
);

Expand Down Expand Up @@ -145,14 +144,13 @@ describe('schema reporting', () => {

it('uses the same executable schema id for metric reporting', async () => {
const pluginInstance = plugin(
{
experimental_schemaReporting: true,
},
{},
addTrace,
{
startSchemaReporting,
executableSchemaIdGenerator,
},
schemaReport: true,
}
);

await pluginTestHarness({
Expand Down
9 changes: 9 additions & 0 deletions packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export class EngineReportingAgent<TContext = any> {
};

private readonly tracesEndpointUrl: string;
private readonly schemaReport: boolean;

public constructor(options: EngineReportingOptions<TContext> = {}) {
this.options = options;
Expand All @@ -407,6 +408,13 @@ export class EngineReportingAgent<TContext = any> {
);
}


if (options.experimental_schemaReporting !== undefined) {
this.schemaReport = options.experimental_schemaReporting;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also add an options.schemaReporting as well and deprecate the old one, or do you want to do that in another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather deprecate the field in a different PR. I think it should be in 2.15

} else {
this.schemaReport = process.env.APOLLO_SCHEMA_REPORTING === "true"
}

// Since calculating the signature for Engine reporting is potentially an
// expensive operation, we'll cache the signatures we generate and re-use
// them based on repeated traces for the same `queryHash`.
Expand Down Expand Up @@ -469,6 +477,7 @@ export class EngineReportingAgent<TContext = any> {
return plugin(this.options, this.addTrace.bind(this), {
startSchemaReporting: this.startSchemaReporting.bind(this),
executableSchemaIdGenerator: this.executableSchemaIdGenerator.bind(this),
schemaReport: this.schemaReport,
});
}

Expand Down
4 changes: 3 additions & 1 deletion packages/apollo-engine-reporting/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const plugin = <TContext>(
{
startSchemaReporting,
executableSchemaIdGenerator,
schemaReport,
}: {
startSchemaReporting: ({
executableSchema,
Expand All @@ -43,6 +44,7 @@ export const plugin = <TContext>(
executableSchemaId: string;
}) => void;
executableSchemaIdGenerator: (schema: string | GraphQLSchema) => string;
schemaReport: boolean;
},
): ApolloServerPlugin<TContext> => {
/**
Expand All @@ -57,7 +59,7 @@ export const plugin = <TContext>(

return {
serverWillStart: function({ schema }) {
if (!options.experimental_schemaReporting) return;
if (!schemaReport) return;
startSchemaReporting({
executableSchema:
options.experimental_overrideReportedSchema || printSchema(schema),
Expand Down