-
Notifications
You must be signed in to change notification settings - Fork 2k
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
AER: include encodedTraces
only once to prevent duplicates
#2040
Changes from 7 commits
5f9f86b
2188b50
a71f7ad
0f956b5
844563a
a027334
f756174
36c46bc
b533e45
f45c549
04ba11a
2f590d1
05a2e4b
307c4f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
protobuf.d.ts | ||
protobuf.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as protobuf from './protobuf'; | ||
|
||
// Override the generated protobuf Traces.encode function so that it will look | ||
// for Traces that are already encoded to Buffer as well as unencoded | ||
// Traces. This amortizes the protobuf encoding time over each generated Trace | ||
// instead of bunching it all up at once at sendReport time. In load tests, this | ||
// change improved p99 end-to-end HTTP response times by a factor of 11 without | ||
// a casually noticeable effect on p50 times. This also makes it easier for us | ||
// to implement maxUncompressedReportSize as we know the encoded size of traces | ||
// as we go. | ||
const originalTracesEncode = protobuf.Traces.encode; | ||
protobuf.Traces.encode = function(message, originalWriter) { | ||
const writer = originalTracesEncode(message, originalWriter); | ||
const encodedTraces = (message as any).encodedTraces; | ||
if (encodedTraces != null && encodedTraces.length) { | ||
for (let i = 0; i < encodedTraces.length; ++i) { | ||
writer.uint32(/* id 1, wireType 2 =*/ 10); | ||
writer.bytes(encodedTraces[i]); | ||
} | ||
} | ||
return writer; | ||
}; | ||
|
||
export = protobuf; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've seen this syntax before, but you are more familiar with modern TS/JS than me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the TypeScript way of expressing |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./dist" | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["src/protobuf.d.ts", "src/protobuf.js"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this is wishful thinking on my part, but this |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,27 +17,6 @@ import { | |
GraphQLServiceContext, | ||
} from 'apollo-server-core/dist/requestPipelineAPI'; | ||
|
||
// Override the generated protobuf Traces.encode function so that it will look | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that there is a reference to this comment later where encodedTraces is written which should be updated to point to the other file. |
||
// for Traces that are already encoded to Buffer as well as unencoded | ||
// Traces. This amortizes the protobuf encoding time over each generated Trace | ||
// instead of bunching it all up at once at sendReport time. In load tests, this | ||
// change improved p99 end-to-end HTTP response times by a factor of 11 without | ||
// a casually noticeable effect on p50 times. This also makes it easier for us | ||
// to implement maxUncompressedReportSize as we know the encoded size of traces | ||
// as we go. | ||
const originalTracesEncode = Traces.encode; | ||
Traces.encode = function(message, originalWriter) { | ||
const writer = originalTracesEncode(message, originalWriter); | ||
const encodedTraces = (message as any).encodedTraces; | ||
if (encodedTraces != null && encodedTraces.length) { | ||
for (let i = 0; i < encodedTraces.length; ++i) { | ||
writer.uint32(/* id 1, wireType 2 =*/ 10); | ||
writer.bytes(encodedTraces[i]); | ||
} | ||
} | ||
return writer; | ||
}; | ||
|
||
export interface ClientInfo { | ||
clientName?: string; | ||
clientVersion?: string; | ||
|
@@ -190,8 +169,8 @@ export class EngineReportingAgent<TContext = any> { | |
this.report.tracesPerQuery[statsReportKey] = new Traces(); | ||
(this.report.tracesPerQuery[statsReportKey] as any).encodedTraces = []; | ||
} | ||
// See comment on our override of Traces.encode to learn more about this | ||
// strategy. | ||
// See comment on our override of Traces.encode inside of | ||
// apollo-engine-reporting-protobuf to learn more about this strategy. | ||
(this.report.tracesPerQuery[statsReportKey] as any).encodedTraces.push( | ||
encodedTrace, | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these files in
src
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're generated to be in
src
whenapollo-engine-reporting-protobuf
isnpm prepare
d. I think it's better that thereports.proto
file is the source of truth and we exclude allprotobuf.d.ts
. Are you suggesting that we should be excludingsrc/protobuf.d.ts
rather than allprotobuf.d.ts
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it would make sense to be more explicit about the specific file you're excluding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why
reports.proto
wouldn't move into this newly introducedsrc
directory?As a general principle, I find it strange that
protobuf.d.ts
(or anything) inside thesrc/
tree is Git ignored or generated. The previous implementation here didn't violate that expectation since everything was generated intodist/
.