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

BatchSettings.builder().build() encourages failure by making required arguments optional #2542

Closed
kir-titievsky opened this issue Oct 20, 2017 · 6 comments
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@kir-titievsky
Copy link

Current pubsub Publisher settings seem to require an instance of BatchingSettings with multiple values set to non-null values. However, the builder pattern encourages setting a single setting at a time. For example, I wanted to make sure that messages were batched into 100 messages batches. So I did this:

publisher = Publisher.defaultBuilder(topicName).setBatchingSettings( BatchingSettings.newBuilder().setElementCountThreshold(100L).build()).build();
which fails with a NullPointerException .
Turns out I must set all other values of BatchingSettings to set one since the call above produces an object like this:
BatchingSettings{elementCountThreshold=100, requestByteThreshold=null, delayThreshold=null, isEnabled=true, flowControlSettings=FlowControlSettings{maxOutstandingElementCount=null, maxOutstandingRequestBytes=null, limitExceededBehavior=Ignore}}

Which took me a good 20 minutes to figure out.

What I wish we did here was an API that required all required parameters, like so (for example):
BatchingSettings.newBuilder().setThresholds(elementCount, requestByte, delay)

@garrettjonesgoogle
Copy link
Member

What about giving everything defaults, so that it's ok if you only set one value?

@vam-google vam-google added api: pubsub Issues related to the Pub/Sub API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Oct 23, 2017
@pongad
Copy link
Contributor

pongad commented Oct 24, 2017

Proposal:
I think we should fix this by documentation.

  1. Give error message so at least the user knows what we're complaining about.

  2. Expose either DEFAULT_BATCHING_SETTINGS or defaultBatchingSettings(), and recommend users to call builder.setBatchingSettings(DEFAULT_BATCHING_SETTINGS.toBuilder().setElementCountThreshold(100L).build()). This call will work and keep all other parameters default.

WDYT?

@garrettjonesgoogle
Copy link
Member

I think we should just set defaults in newBuilder().

@pongad
Copy link
Contributor

pongad commented Oct 27, 2017

Note that there are two defaults at play here. One is BatchingSettings.DEFAULT and another is Subscriber.DEFAULT_BATCHING_SETTINGS.

I think Subscriber.DEFAULT_BATCHING_SETTINGS can stay as is.

BatchingSettings.DEFAULT defaulted to null for "never trigger". Eg, if you set element count to null, batch will only trigger on number of bytes and duration. What should default be here, Long.MAX?

@garrettjonesgoogle
Copy link
Member

I think the default for BatchingSettings should be the values for no batching (send one at a time).

@kir-titievsky
Copy link
Author

kir-titievsky commented Oct 27, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants