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

dynamic EUM host #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;


Expand Down Expand Up @@ -65,6 +67,9 @@ public WebClient.Builder loadBalancedWebClientBuilder() {
@Value("classpath:/static/index.html")
private Resource indexHtml;

@Value("${EUM_HOST:localhost}")
private String eumHost;

/**
* workaround solution for forwarding to index.html
* @see <a href="https://github.com/spring-projects/spring-boot/issues/9785">#9785</a>
Expand All @@ -73,10 +78,27 @@ public WebClient.Builder loadBalancedWebClientBuilder() {
RouterFunction<?> routerFunction() {
RouterFunction router = RouterFunctions.resources("/**", new ClassPathResource("static/"))
.andRoute(RequestPredicates.GET("/"),
request -> ServerResponse.ok().contentType(MediaType.TEXT_HTML).bodyValue(indexHtml));
request -> ServerResponse.ok().contentType(MediaType.TEXT_HTML)
.bodyValue(injectDynamicEumHost())
);
return router;
}

/**
* workaround solution to use dynamic hosts for EUM instead of just localhost
* @return content of index.html with injected EUM-Host
*/
private String injectDynamicEumHost() {
try {
String indexHtmlContent = new String(indexHtml.getInputStream().readAllBytes(), StandardCharsets.UTF_8);

// Replace the placeholder with the actual host value
return indexHtmlContent.replace("${EUM_HOST}", eumHost);
} catch (IOException e) {
throw new RuntimeException("Could not read index.html");
}
}

/**
* Default Resilience4j circuit breaker configuration
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@
<script src="/scripts/infrastructure/infrastructure.js"></script>
<script src="/scripts/infrastructure/httpErrorHandlingInterceptor.js"></script>

<script src="http://localhost:8085/boomerang/boomerang.js"></script>
<script src="http://localhost:8085/boomerang/plugins/boomerang-opentelemetry.js"></script>
<script src="http://localhost:8085/boomerang/plugins/rt.js"></script>
<script src="http://localhost:8085/boomerang/plugins/auto-xhr.js"></script>
<script src="http://localhost:8085/boomerang/plugins/spa.js"></script>
<script src="http://localhost:8085/boomerang/plugins/history.js"></script>
<!-- ${EUM_HOST} will be replaced with an actual host, while loading the file -->
<!-- see ApiGatewayApplication#injectDynamicEumHost() -->
<script src="http://${EUM_HOST}:8085/boomerang/boomerang.js"></script>
<script src="http://${EUM_HOST}:8085/boomerang/plugins/boomerang-opentelemetry.js"></script>
<script src="http://${EUM_HOST}:8085/boomerang/plugins/rt.js"></script>
<script src="http://${EUM_HOST}:8085/boomerang/plugins/auto-xhr.js"></script>
<script src="http://${EUM_HOST}:8085/boomerang/plugins/spa.js"></script>
<script src="http://${EUM_HOST}:8085/boomerang/plugins/history.js"></script>
<script>
BOOMR.init({
beacon_url: "http://localhost:8085/beacon/"
beacon_url: "http://${EUM_HOST}:8085/beacon/"
});
</script>

Expand Down