Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
Adrian Cole committed May 14, 2024
1 parent 25396a7 commit 8965e6e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
4 changes: 2 additions & 2 deletions webflux6-micrometer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<jre.version>21</jre.version>
<maven.compiler.release>17</maven.compiler.release>

<spring-boot.version>3.3.0-M3</spring-boot.version>
<micrometer.version>1.3.0-RC1</micrometer.version>
<spring-boot.version>3.3.0-RC1</spring-boot.version>
<micrometer.version>1.3.0</micrometer.version>
</properties>

<!-- Temporary until Spring boot 3.3.0 -->
Expand Down
11 changes: 7 additions & 4 deletions webflux6-micrometer/src/main/java/brave/example/Backend.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package brave.example;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -27,9 +31,8 @@ public Mono<String> printDate(@RequestHeader("user_name") Optional<String> usern
}

public static void main(String[] args) {
SpringApplication.run(Backend.class,
"--spring.application.name=backend",
"--server.port=9000"
);
new SpringApplicationBuilder(Backend.class)
.properties(ZipkinDiscoveryConfiguration.discoveryProperties())
.run("--spring.application.name=backend", "--server.port=9000");
}
}
11 changes: 6 additions & 5 deletions webflux6-micrometer/src/main/java/brave/example/Frontend.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -29,9 +29,10 @@ public class Frontend {
}

public static void main(String[] args) {
SpringApplication.run(Frontend.class,
"--spring.application.name=frontend",
"--server.port=8081"
);
new SpringApplicationBuilder(Frontend.class)
.properties(ZipkinDiscoveryConfiguration.discoveryProperties())
.run("--spring.application.name=frontend",
"--server.port=8081"
);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package brave.example;

import java.net.URI;
import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import zipkin2.reporter.HttpEndpointSupplier;
import zipkin2.reporter.HttpEndpointSuppliers;

// TODO: make this conditional on configuration, to prevent crashes looking up Eureka.
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("EUREKA_SERVICE_URL")
public class ZipkinDiscoveryConfiguration {

/**
* It is very difficult to stop loadbalancer or discovery from initializing when starters are on
* the classpath. This is a workaround to disable it when EUREKA_SERVICE_URL is not set.
*/
static Map<String, Object> discoveryProperties() {
Map<String, Object> properties = new LinkedHashMap<>();
String eurekaServiceUrl = System.getenv("EUREKA_SERVICE_URL");
boolean eurekaEnabled = eurekaServiceUrl != null && !eurekaServiceUrl.isEmpty();
if (eurekaEnabled) {
properties.put("eureka.client.serviceUrl.defaultZone", eurekaServiceUrl);
}
properties.put("spring.cloud.loadbalancer.enabled", eurekaEnabled);
properties.put("spring.cloud.discovery.enabled", eurekaEnabled);
return properties;
}

@Bean HttpEndpointSupplier.Factory loadbalancerEndpoints(LoadBalancerClient loadBalancerClient) {
LoadBalancerHttpEndpointSupplier.Factory httpEndpointSupplierFactory =
new LoadBalancerHttpEndpointSupplier.Factory(loadBalancerClient);
Expand Down
4 changes: 0 additions & 4 deletions webflux6-micrometer/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ management:
tracing:
# Note: There is no property to bind ${brave.localServiceName:${spring.application.name}}
endpoint: ${zipkin.baseUrl:http://127.0.0.1:9411}/api/v2/spans
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
cloud:
compatibilityVerifier:
Expand Down

0 comments on commit 8965e6e

Please sign in to comment.