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

Replace PublisherInterface with Publisher #900

Merged
merged 13 commits into from
Jan 26, 2022
Merged

Conversation

elefeint
Copy link
Contributor

@elefeint elefeint commented Jan 21, 2022

After the discussion in googleapis/java-pubsub#949, reverting back to using Publisher for all API return types. I've ported the trace header injection functionality from TracingPublisher into TracingPublisherFactory.

The Trace information will now get into a standard Publisher through a builder callback PubsubMessage.Builder.setTransform().

This PR is a pre-requisite for fixing #864.

Fixes #790

@elefeint
Copy link
Contributor Author

I think I might be able to remove TracingPublisherFactory and the new PublisherFactory constructor if I allow an extra customizable field in DefaultPublisherFactory.

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

My main concern here is that the PublisherCustomizer is part of the public API now, and nothing really requires it to be used for trace instrumentation only. There is a risk that users will provide a PublisherCustomizer and inadvertently disable tracing during publishing. You might be able to get around this by supporting multiple PublisherCustomizer beans, but then things get a bit more complicated.

@@ -347,7 +348,8 @@ public PublisherFactory defaultPublisherFactory(
@Qualifier("publisherBatchSettings") ObjectProvider<BatchingSettings> batchingSettings,
@Qualifier("publisherRetrySettings") ObjectProvider<RetrySettings> retrySettings,
@Qualifier("publisherTransportChannelProvider")
TransportChannelProvider publisherTransportChannelProvider) {
TransportChannelProvider publisherTransportChannelProvider,
Optional<PublisherCustomizer> customizer) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not ObjectProvider like the other arguments? Also, do we need to add the @Qualifier like for the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ObjectProvider is useful when you don't know whether you have one or multiple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Qualifier is there for non-pubsub-specific types, to distinguish, for example, a Spanner RetrySettings object from a Pub/Sub one. PublisherCustomizer is already a pubsub-specific interface.

Copy link
Member

Choose a reason for hiding this comment

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

Why do you think there will never be multiple? It's a very generic customizer.

PublisherFactory factory =
ctx.getBean("defaultPublisherFactory", PublisherFactory.class);
Publisher testPublisher = factory.createPublisher("unused");
assertThat(testPublisher.getBatchingSettings()).isSameAs(testBatchingSettings);
Copy link
Member

Choose a reason for hiding this comment

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

Should you also verify that endpoint is "unused:433"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a result of an older experiment; I'll remove the line that sets it.
There is no getter for host/port, and while it's possible to use reflection, I went with something that's easy to validate.


@Bean
@ConditionalOnMissingBean
PublisherCustomizer publisherCustomizer(PubSubTracing pubSubTracing) {
Copy link
Member

Choose a reason for hiding this comment

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

This is specifically the tracePublisherCustomizer. So, I think it needs to be named that way.

@meltsufin
Copy link
Member

@elefeint Maybe what you can do is just keep TracingPublisherFactory, but add the customizer to it rather than the DefaultPublisherFactory.

Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

Looks good, aside from missing documentation, which you might want to do in a separate PR. Up to you.

@sonarcloud
Copy link

sonarcloud bot commented Jan 26, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

96.4% 96.4% Coverage
0.0% 0.0% Duplication

@elefeint elefeint merged commit 07d7500 into main Jan 26, 2022
@elefeint elefeint deleted the remove-publisher-interface branch January 26, 2022 23:31
elefeint added a commit that referenced this pull request May 25, 2022
After the discussion in googleapis/java-pubsub#949, reverting back to using `Publisher` for all API return types. I've ported the trace header injection functionality from `TracingPublisher` into `TracingPublisherFactory`.

The Trace information will now get into a standard `Publisher` through a builder callback `PubsubMessage.Builder.setTransform()`.
kateryna216 added a commit to kateryna216/spring-cloud-gcp that referenced this pull request Oct 20, 2022
After the discussion in googleapis/java-pubsub#949, reverting back to using `Publisher` for all API return types. I've ported the trace header injection functionality from `TracingPublisher` into `TracingPublisherFactory`.

The Trace information will now get into a standard `Publisher` through a builder callback `PubsubMessage.Builder.setTransform()`.
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.

PublisherFactory returns PublisherInterface instead of Publisher
2 participants