Embed Kibana UI in Spring Boot 2

I have a Spring Boot 2 app that wants to embed Kibana UI in the page. I use an iframe to embed the UI. The iframe url is set to /kibana. In the backend, I use HTTP-Proxy-Servlet to proxy the requests to the actual Kibana server.

Kibana version is 6.5.4 and Spring Boot version is 2.0.8.RELEASE.

Include the HTTP-Proxy-Servlet library first.

1
2
3
4
5
<dependency>
<groupId>org.mitre.dsmiley.httpproxy</groupId>
<artifactId>smiley-http-proxy-servlet</artifactId>
<version>1.11</version>
</dependency>

Then add proxy config to application.yml.

1
2
3
4
proxy:
kibana:
servletUrl: /kibana/*
targetUrl: http://localhost:5601/kibana

Finally, create the ProxyServlet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@Configuration
class ProxyConfig : EnvironmentAware {
private lateinit var environment: Environment

override fun setEnvironment(environment: Environment) {
this.environment = environment
}

@Bean
fun kibanaProxyServletRegistrationBean() = createProxyServlet("proxy.kibana")

@Bean
fun kibanaFilterRegistrationBean(filter: HiddenHttpMethodFilter): FilterRegistrationBean<HiddenHttpMethodFilter> {
val registration = FilterRegistrationBean(filter)
registration.isEnabled = false
return registration
}

private fun createProxyServlet(propertyPath: String): ServletRegistrationBean<ProxyServlet> {
val servletRegistrationBean = ServletRegistrationBean(ProxyServlet(), environment.get("$propertyPath.servletUrl"))
servletRegistrationBean.addInitParameter("targetUri", environment.get("$propertyPath.targetUrl"))
servletRegistrationBean.addInitParameter(ProxyServlet.P_HANDLEREDIRECTS, "true")
servletRegistrationBean.addInitParameter(ProxyServlet.P_LOG, "false")
return servletRegistrationBean
}
}

Now accessing http://localhost:8080/kibana shows the Kibana UI.

You need to update Kibana config kibana.yml to set the base path. Check that you can access http://localhost:5601/kibana. This url matches the targetUrl value in application.yml.

1
2
server.basePath: "/kibana"
server.rewriteBasePath: true
Comments