Skip to content

Commit e9a011b

Browse files
bygui86Crim
authored andcommitted
Kube-Series-1: Features/prometheus metrics (#198)
* Added Micrometer Prometheus to Maven pom * Updated WebConfig to include a StringHttpMessageConverter in order to properly manage "Accept: text/plain" header in requests * Updated "dev" config to setup advanced Spring Actuator properties - Added WebServer config to allow secondary port on tomcat and fix Spring Actuator login page redirection failure * Updated README - Removed commented dev property * Added property to export all Tomcat metrics * Fixed Actuator login issue * Moved Actuator-related properties from dev.yml to base.yml * Added missing javadoc comment
1 parent bc038be commit e9a011b

File tree

6 files changed

+96
-4
lines changed

6 files changed

+96
-4
lines changed

kafka-webview-ui/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
<groupId>org.springframework.boot</groupId>
125125
<artifactId>spring-boot-starter-actuator</artifactId>
126126
</dependency>
127+
<!-- Micrometer Prometheus registry -->
128+
<dependency>
129+
<groupId>io.micrometer</groupId>
130+
<artifactId>micrometer-registry-prometheus</artifactId>
131+
</dependency>
127132

128133
<dependency>
129134
<groupId>javax.interceptor</groupId>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2017, 2018, 2019 SourceLab.org (https://github.com/SourceLabOrg/kafka-webview/)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package org.sourcelab.kafka.webview.ui.configuration;
26+
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
import org.springframework.context.annotation.Configuration;
30+
import org.springframework.core.annotation.Order;
31+
import org.springframework.http.HttpMethod;
32+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
33+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
34+
35+
/**
36+
* Manages Actuator Security Configuration.
37+
*/
38+
@Configuration
39+
@Order(1000)
40+
public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {
41+
42+
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
43+
44+
@Override
45+
protected void configure(HttpSecurity http) throws Exception {
46+
logger.info("Configuring Actuator access.");
47+
48+
// Actuator uses http basic auth
49+
http
50+
.authorizeRequests()
51+
.antMatchers(HttpMethod.GET, "/actuator/info", "/actuator/health", "/actuator/prometheus")
52+
.permitAll()
53+
.and()
54+
.antMatcher("/actuator/**")
55+
.authorizeRequests()
56+
.anyRequest()
57+
.hasRole("ADMIN")
58+
.and()
59+
.httpBasic();
60+
}
61+
62+
}

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/configuration/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.beans.factory.annotation.Autowired;
3535
import org.springframework.context.annotation.Bean;
3636
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.core.annotation.Order;
3738
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
3839
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
3940
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -50,6 +51,7 @@
5051
*/
5152
@Configuration
5253
@EnableWebSecurity
54+
@Order(1001)
5355
public class SecurityConfig extends WebSecurityConfigurerAdapter {
5456
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
5557

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/configuration/WebConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.beans.factory.annotation.Autowired;
3232
import org.springframework.context.annotation.Configuration;
3333
import org.springframework.http.converter.HttpMessageConverter;
34+
import org.springframework.http.converter.StringHttpMessageConverter;
3435
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3536
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
3637
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -84,6 +85,9 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
8485
.modulesToInstall(new ProtobufModule())
8586
.serializerByType(GenericData.Record.class, new SimpleAvroDataSerializer(appProperties.isAvroIncludeSchema()))
8687
.build();
88+
8789
converters.add(new MappingJackson2HttpMessageConverter(mapper));
90+
converters.add(new StringHttpMessageConverter());
8891
}
92+
8993
}

kafka-webview-ui/src/main/resources/config/base.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ server:
33
tomcat:
44
remote_ip_header: x-forwarded-for
55
protocol_header: x-forwarded-proto
6+
mbeanregistry:
7+
enabled: true
68
servlet:
79
session:
810
## User sessions should not be persistent across service restarts by default.
@@ -43,12 +45,30 @@ spring:
4345
show-sql: false
4446
open-in-view: true
4547

46-
## Disable LDAP Management by default
48+
# Spring Actuator - global
4749
management:
50+
server:
51+
port: 9090
52+
endpoints:
53+
web:
54+
exposure:
55+
include: "*"
56+
endpoint:
57+
health:
58+
show-details: when_authorized
59+
metrics:
60+
tags:
61+
application: ${spring.application.name}
62+
## Disable LDAP by default
4863
health:
4964
ldap:
5065
enabled: false
5166

67+
# Spring Actuator - Info endpoint
68+
info:
69+
app:
70+
name: ${spring.application.name}
71+
5272
## Various App Configs
5373
app:
5474
name: Kafka Web View

kafka-webview-ui/src/main/resources/config/dev.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ server:
44
persistent: true
55

66
spring:
7+
jpa:
8+
show-sql: true
79
# H2 Datbase
810
h2:
911
console:
1012
## Disable for release
1113
enabled: true
1214
path: /h2
1315

14-
jpa:
15-
show-sql: true
16-
1716
app:
1817
requireSsl: false
1918
user:

0 commit comments

Comments
 (0)