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

Stop using Discovery service to find reporting service #926

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Platform 2.96

* Reporting

ReportingClientModule no longer uses the Discovery service to find the reporting service.
The URI of the reporting service must now be specified through the "service-client.reporting.uri"
configuration property.

Platform 2.95

* Discovery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,34 @@ public BalancingHttpClientBindingBuilder bindBalancingHttpClient(String name, An
return createBalancingHttpClientBindingBuilder(privateBinder, name, annotation, serviceName);
}

/**
* Binds an {@link HttpClient} to an implementation that takes relative
* {@link URI}s. The requests are balanced against the set of prefixes
* specified in configuration.
*
* See the EDSL examples at {@link HttpClientBinder}.
*
* @param name The configuration prefix. Should be lowercase hyphen-separated.
* @param annotation The binding annotation.
* @param serviceName The name of the service being balanced.
* Used in metrics and in the configuration prefix for the service balancer.
* Ordinarily this is the value of the binding annotation.
*/
public BalancingHttpClientBindingBuilder bindBalancingHttpClient(String name, Class<? extends Annotation> annotation, String serviceName)
{
requireNonNull(name, "name is null");
requireNonNull(annotation, "annotation is null");

bindConfig(binder).bind(HttpServiceBalancerConfig.class).annotatedWith(annotation).prefixedWith("service-client." + serviceName);
bindConfig(binder).bind(HttpServiceBalancerUriConfig.class).annotatedWith(annotation).prefixedWith("service-client." + serviceName);
PrivateBinder privateBinder = binder.newPrivateBinder();
privateBinder.bind(HttpServiceBalancer.class).annotatedWith(ForBalancingHttpClient.class)
.toProvider(new ConfiguredStaticHttpServiceBalancerProvider(serviceName,
Key.get(HttpServiceBalancerConfig.class, annotation),
Key.get(HttpServiceBalancerUriConfig.class, annotation)));
return createBalancingHttpClientBindingBuilder(privateBinder, name, annotation, serviceName);
}

private BalancingHttpClientBindingBuilder createBalancingHttpClientBindingBuilder(PrivateBinder privateBinder, String name, Class<? extends Annotation> annotation)
{
HttpClientBindingBuilder delegateBindingBuilder = httpClientPrivateBinder(privateBinder, binder).bindHttpClient(name, ForBalancingHttpClient.class);
Expand Down Expand Up @@ -416,6 +444,23 @@ private BalancingHttpClientBindingBuilder createBalancingHttpClientBindingBuilde
return new BalancingHttpClientBindingBuilder(binder, annotation, delegateBindingBuilder);
}

private BalancingHttpClientBindingBuilder createBalancingHttpClientBindingBuilder(PrivateBinder privateBinder, String name, Class<? extends Annotation> annotation, String serviceName)
{
HttpClientBindingBuilder delegateBindingBuilder = httpClientPrivateBinder(privateBinder, binder).bindHttpClient(name, ForBalancingHttpClient.class);
bindConfig(privateBinder).bind(BalancingHttpClientConfig.class).prefixedWith(name);
privateBinder.bind(HttpClient.class).annotatedWith(annotation).to(BalancingHttpClient.class).in(Scopes.SINGLETON);
privateBinder.expose(HttpClient.class).annotatedWith(annotation);
reportBinder(binder).export(HttpClient.class).annotatedWith(annotation).withNamePrefix("HttpClient." + serviceName);
newExporter(binder).export(HttpClient.class).annotatedWith(annotation).as(new ObjectNameBuilder(HttpClient.class.getPackage().getName())
.withProperty("type", "HttpClient")
.withProperty("name", serviceName)
.build()
);
binder.bind(ScheduledExecutorService.class).annotatedWith(ForBalancingHttpClient.class).toProvider(RetryExecutorProvider.class);

return new BalancingHttpClientBindingBuilder(binder, annotation, delegateBindingBuilder);
}

public static class HttpClientBindingBuilder
{
private final HttpClientModule module;
Expand Down
2 changes: 1 addition & 1 deletion reporting-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dependencies>
<dependency>
<groupId>com.proofpoint.platform</groupId>
<artifactId>discovery</artifactId>
<artifactId>bootstrap</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static com.google.inject.Scopes.SINGLETON;
import static com.proofpoint.concurrent.Threads.daemonThreadsNamed;
import static com.proofpoint.configuration.ConfigBinder.bindConfig;
import static com.proofpoint.discovery.client.DiscoveryBinder.discoveryBinder;
import static com.proofpoint.http.client.HttpClientBinder.httpClientBinder;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;

public class ReportingClientModule
Expand All @@ -43,7 +43,7 @@ public void configure(Binder binder)
binder.bind(ReportSink.class).to(ReportQueue.class).in(SINGLETON);
binder.bind(ReportClient.class).in(SINGLETON);

discoveryBinder(binder).bindDiscoveredHttpClient("reporting", ForReportClient.class);
httpClientBinder(binder).bindBalancingHttpClient("reporting", ForReportClient.class, "reporting");
bindConfig(binder).bind(ReportClientConfig.class);

binder.install(new ReportingBaseMetricsModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.inject.Injector;
import com.proofpoint.configuration.ConfigurationFactory;
import com.proofpoint.configuration.ConfigurationModule;
import com.proofpoint.discovery.client.testing.TestingDiscoveryModule;
import com.proofpoint.json.JsonModule;
import com.proofpoint.node.ApplicationNameModule;
import com.proofpoint.node.testing.TestingNodeModule;
Expand Down Expand Up @@ -76,8 +75,9 @@ public void testReportingModule()
Injector injector = Guice.createInjector(
new ApplicationNameModule("test-application"),
new TestingNodeModule(),
new TestingDiscoveryModule(),
new ConfigurationModule(new ConfigurationFactory(ImmutableMap.of())),
new ConfigurationModule(new ConfigurationFactory(ImmutableMap.of(
"service-client.reporting.uri", "https://reporting.invalid"
))),
new JsonModule(),
new ReportingModule(),
new ReportingClientModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.google.inject.Injector;
import com.proofpoint.bootstrap.LifeCycleManager;
import com.proofpoint.discovery.client.testing.TestingDiscoveryModule;
import com.proofpoint.json.JsonModule;
import com.proofpoint.node.testing.TestingNodeModule;
import org.testng.annotations.Test;
Expand All @@ -35,9 +34,9 @@ public void testCreateInjector()
new ReportingModule(),
new JsonModule(),
new TestingNodeModule(),
new TestingDiscoveryModule(),
new ReportingClientModule()
)
.setRequiredConfigurationProperty("service-client.reporting.uri", "https://reporting.invalid")
.initialize();

injector.getInstance(LifeCycleManager.class).stop();
Expand Down
Loading