-
Notifications
You must be signed in to change notification settings - Fork 795
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
Support gzip compression for node exporter collector #2337
Support gzip compression for node exporter collector #2337
Conversation
a10c50e
to
bc475d1
Compare
Codecov Report
@@ Coverage Diff @@
## main #2337 +/- ##
==========================================
+ Coverage 92.35% 92.64% +0.29%
==========================================
Files 128 142 +14
Lines 4249 5101 +852
Branches 868 1050 +182
==========================================
+ Hits 3924 4726 +802
- Misses 325 375 +50
|
62c11b4
to
508f7e8
Compare
packages/opentelemetry-exporter-collector/src/platform/node/types.ts
Outdated
Show resolved
Hide resolved
30d2300
to
446c71b
Compare
httpAgentOptions?: http.AgentOptions | https.AgentOptions; | ||
} | ||
|
||
export enum CompressionAlgorithm { |
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.
General comment, why define the enum values as strings?
Why not just a numeric value as the "NAME" will still be available is the resulting code and if required we can always look it up in config via uppercasing ... Just a thought.
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.
Generally i advise using string to avoid problem when trying to update available value (that can share the same number even if values are different across versions)
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.
as far as I know normal enums are hard to use for non typescript users.
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.
@Flarna I know that's true for const enum
s but I'm not sure it's the case for regular enums. Do you have a particular case you're thinking of?
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 think I know what you mean after thinking a little more. You're not thinking they can't do CompressionAlgorithm.GZIP
but that 1
doesn't mean anything to them and passing a string 'gzip'
is more clear?
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.
Normal enums are exported as objects so a JS user can use CompressionAlgorithm.GZIP
. A JS user can also use the underlying constant (e.g. gzip
).
The main difference is documentation. A typescript user can't to much wrong as editor will tell the allowed values to use and compiler checks again.
For JS users it's needed to document that an object named CompressionAlgorithm
is exported incl. the properties (GZIP
and NONE
) referring to the constants to use.
This works fine but often JS APIs document the actual values to use instead referring to an object holding the constants (would be gzip
/none
here).
Standard const enums are really bad as JS users have to use the numeric values then.
const enums with strings as values would require JS users to use these strings in their code.
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 think we should not depend on zlib directly. We should create a config param and accepts a defined object with 2 function (zip, unzip) as interface. This can be compatible with zlib. This way people might be using any library with any version. ZLIB is quite popular people might have it already in their repo with different version etc. That's why I think we should define an interface that will allow more freedom to choose and will not create a strict dependency on 3rd party.
packages/opentelemetry-exporter-collector/src/platform/node/CollectorExporterNodeBase.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-exporter-collector/src/platform/node/util.ts
Outdated
Show resolved
Hide resolved
zlib is a part of nodejs. It is not a 3rd party lib. |
Oh you are absolutely right, :) |
…nstance in sendWithHttp
this is general approach, if user is able to pass a headers to the config, those headers should take precedence over other things, there can be edge cases which we are not aware of, but we should not prevent user from overriding things if for any reason wants to do that. |
Not sure I agree. Sure, the user can set headers, but that doesn't mean we can't override them. The content-length header is a good example of one that the user could technically pass to the headers object but we would be incorrect not to overwrite. Since the user can't affect the encoding, I'm not sure it makes sense to preserve the value they set for the content-encoding header. |
well in linux if you want to run |
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 miss an update of the Readme to explain the new options.
This would be also a good place to explain that it may be a bad idea for the user to set e.g. a Content-Encoding
or Content-Length
header.
Might be a concern for another PR: compression is meant to be configurable through environment variables (e.g., |
If there is an option to compress the body accepted by
|
Retrigger CLA |
Fixes #1637,
I was not sure this is the right approach to address this issue. Please let me know if it is wrong.
Which problem is this PR solving?
Short description of the changes
compress
has been added toCollectorExporterNodeConfigBase
. It is an optional boolean. The default behavior is to not compress the request body.util.ts
which pipes the body through a gzip instance. The code is inspired from here.Passthrough
stream instead. UsingPassthrough
we can work with a real stream (readable and writable) which provides more control on the tests.TODO
Content-Length
header should be correct in case of compression enabled.