Skip to content

Conversation

@rochdev
Copy link
Member

@rochdev rochdev commented Jun 14, 2022

This PR removes the hard dependency on Protobuf. The library can be used just to capture metrics as histograms without serialization, in which case this large dependency is pulled unnecessarily. If Protobuf is needed, then having an explicit dependency on it by the app instead will still make it available, and otherwise calling the methods that need it will error out.

This is a breaking change for any app that is not explicitly depending on protobufjs so a 2.0 release would be needed.

A few open questions about the implementation:

  1. Should a more helpful error be thrown when protobufjs is missing instead of just the standard missing module error?
  2. Should the API be changed to introduce the concept of serializers instead of having fromProto and toProto methods?

@rochdev rochdev force-pushed the rochdev/remove-protobuf-dependency branch from 43fefb3 to f9f6e2d Compare August 5, 2022 18:31
@rochdev rochdev requested a review from brimtown August 5, 2022 18:32
@rochdev
Copy link
Member Author

rochdev commented Aug 5, 2022

Discussed offline with @brimtown and for now the dependency will simply be removed and become optional. The API can be revisited in a future version if needed to support additional serialization formats.

This is now ready for review.

}

toProto(): IStore {
const ProtoStore = require('../proto/compiled').Store;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of curiosity, did you try to get these to work with dynamic import? Benefit would be not needing the lint override.

Copy link
Member Author

Choose a reason for hiding this comment

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

This would change the API since it makes the call asynchronous and uses a promise.

README.md Outdated
```sh
# NPM
npm install @datadog/sketches-js
npm install --save @datadog/sketches-js
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this? Wasn't familiar with it, but seems like this has been the default behavior for a while (source).

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't use npm for years and wasn't aware of the change, good catch!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

}

toProto(): IIndexMapping {
const ProtoIndexMapping = require('../proto/compiled').IndexMapping;
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are still some static imports to /proto/compiled at the top of this file, does that matter? I would sort of expect that any one of those would cause the module missing error, regardless of if an end user is invoking toProto / fromProto.

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems that the TypeScript compiler is able to understand that actual code isn't used and not add the require call.

@rochdev rochdev merged commit 33ac6ca into master Aug 8, 2022
@rochdev rochdev deleted the rochdev/remove-protobuf-dependency branch August 8, 2022 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants