Skip to content

Commit 666f53f

Browse files
smsteeless047890
andauthored
Enhancement to add EnablePrometheusRSocketProxyServer annotation (#36)
Co-authored-by: ss047890 <[email protected]>
1 parent 187b713 commit 666f53f

File tree

14 files changed

+174
-40
lines changed

14 files changed

+174
-40
lines changed

proxy-server/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
id 'java-library'
3+
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencyManagement {
11+
imports {
12+
mavenBom 'org.springframework.boot:spring-boot-dependencies:2.3.3.RELEASE'
13+
}
14+
}
15+
16+
dependencies {
17+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
18+
implementation 'org.springframework.boot:spring-boot-starter-webflux'
19+
implementation 'io.micrometer:micrometer-registry-prometheus'
20+
21+
implementation 'io.rsocket:rsocket-micrometer:1.0.2'
22+
implementation 'io.rsocket:rsocket-transport-netty:1.0.2'
23+
24+
implementation 'org.xerial.snappy:snappy-java:latest.release'
25+
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
26+
27+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
28+
testImplementation 'io.projectreactor:reactor-test'
29+
}

proxy/src/main/java/io/micrometer/prometheus/rsocket/PrometheusController.java renamed to proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* @author Christian Tzolov
5959
*/
6060
@RestController
61-
class PrometheusController {
61+
public class PrometheusController {
6262
private final PrometheusMeterRegistry meterRegistry;
6363
private final Timer scrapeTimerSuccess;
6464
private final Timer scrapeTimerClosed;
@@ -67,12 +67,11 @@ class PrometheusController {
6767
private final PrometheusControllerProperties properties;
6868
private final Map<RSocket, ConnectionState> scrapableApps = new ConcurrentHashMap<>();
6969

70-
PrometheusController(PrometheusMeterRegistry meterRegistry, PrometheusControllerProperties properties) {
70+
public PrometheusController(PrometheusMeterRegistry meterRegistry, PrometheusControllerProperties properties) {
7171
this.meterRegistry = meterRegistry;
7272
this.metricsInterceptor = new MicrometerRSocketInterceptor(meterRegistry);
7373
this.properties = properties;
7474
meterRegistry.gaugeMapSize("prometheus.proxy.scrape.active.connections", Tags.empty(), scrapableApps);
75-
7675
this.scrapeTimerSuccess = Timer.builder("prometheus.proxy.scrape")
7776
.tag("outcome", "success")
7877
.tag("exception", "none")

proxy/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
implementation 'org.springframework.boot:spring-boot-starter-actuator'
2626
implementation 'org.springframework.boot:spring-boot-starter-webflux'
2727
implementation 'io.micrometer:micrometer-registry-prometheus'
28+
implementation project(':prometheus-rsocket-spring')
2829

2930
implementation 'io.rsocket:rsocket-micrometer:1.0.2'
3031
implementation 'io.rsocket:rsocket-transport-netty:1.0.2'

proxy/src/main/java/io/micrometer/prometheus/rsocket/PrometheusRSocketProxyMain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616
package io.micrometer.prometheus.rsocket;
1717

18+
import io.micrometer.prometheus.rsocket.autoconfigure.EnablePrometheusRSocketProxyServer;
1819
import org.springframework.boot.SpringApplication;
1920
import org.springframework.boot.autoconfigure.SpringBootApplication;
20-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2121

2222
@SpringBootApplication
23-
@EnableConfigurationProperties(PrometheusControllerProperties.class)
23+
@EnablePrometheusRSocketProxyServer
2424
public class PrometheusRSocketProxyMain {
2525
public static void main(String[] args) {
2626
SpringApplication.run(PrometheusRSocketProxyMain.class, args);

settings.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ project(':prometheus-rsocket-proxy').projectDir = new File(rootProject.projectDi
2121
include 'prometheus-rsocket-client'
2222
project(':prometheus-rsocket-client').projectDir = new File(rootProject.projectDir, 'client')
2323

24+
include 'prometheus-rsocket-proxy-server'
25+
project(':prometheus-rsocket-proxy-server').projectDir = new File(rootProject.projectDir, 'proxy-server')
26+
2427
include 'prometheus-rsocket-spring'
25-
project(':prometheus-rsocket-spring').projectDir = new File(rootProject.projectDir, 'starter-spring')
28+
project(':prometheus-rsocket-spring').projectDir = new File(rootProject.projectDir, 'starter-spring')
29+

starter-spring/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
implementation 'org.springframework.boot:spring-boot-actuator-autoconfigure'
2020
implementation 'org.springframework.boot:spring-boot-autoconfigure'
2121
implementation project(':prometheus-rsocket-client')
22+
implementation project(':prometheus-rsocket-proxy-server')
2223

2324
implementation 'io.rsocket:rsocket-transport-netty:1.0.2'
2425

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2020 Pivotal Software, Inc.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micrometer.prometheus.rsocket.autoconfigure;
17+
18+
import io.micrometer.prometheus.rsocket.PrometheusController;
19+
import org.springframework.context.annotation.Import;
20+
21+
import java.lang.annotation.*;
22+
23+
/**
24+
* Annotation to activate Prometheus RSocket Proxy Server related configuration.
25+
* {@link PrometheusController}
26+
*
27+
* @author Scott Steele
28+
* @author Doug Saus
29+
*/
30+
@Target(ElementType.TYPE)
31+
@Retention(RetentionPolicy.RUNTIME)
32+
@Documented
33+
@Import(PrometheusRSocketProxyServerMarkerConfiguration.class)
34+
public @interface EnablePrometheusRSocketProxyServer {
35+
36+
}
Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616

1717
package io.micrometer.prometheus.rsocket.autoconfigure;
1818

19-
import io.micrometer.core.instrument.Clock;
20-
import io.micrometer.prometheus.PrometheusConfig;
2119
import io.micrometer.prometheus.PrometheusMeterRegistry;
2220
import io.micrometer.prometheus.rsocket.PrometheusRSocketClient;
23-
import io.prometheus.client.CollectorRegistry;
2421
import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration;
2522
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2623
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -35,36 +32,12 @@
3532
@AutoConfigureAfter(PrometheusMetricsExportAutoConfiguration.class)
3633
@ConditionalOnClass(PrometheusMeterRegistry.class)
3734
@ConditionalOnProperty(prefix = "management.metrics.export.prometheus.rsocket", name = "enabled", havingValue = "true", matchIfMissing = true)
38-
@EnableConfigurationProperties(PrometheusRSocketProperties.class)
39-
public class PrometheusRSocketAutoConfiguration {
40-
41-
@ConditionalOnMissingBean
42-
@Bean
43-
Clock micrometerClock() {
44-
return Clock.SYSTEM;
45-
}
46-
47-
@ConditionalOnMissingBean
48-
@Bean
49-
PrometheusConfig prometheusConfig() {
50-
return PrometheusConfig.DEFAULT;
51-
}
52-
53-
@ConditionalOnMissingBean
54-
@Bean
55-
CollectorRegistry prometheusCollectorRegistry() {
56-
return new CollectorRegistry(true);
57-
}
58-
59-
@ConditionalOnMissingBean
60-
@Bean
61-
PrometheusMeterRegistry prometheusMeterRegistry(PrometheusConfig config, CollectorRegistry collectorRegistry, Clock clock) {
62-
return new PrometheusMeterRegistry(config, collectorRegistry, clock);
63-
}
35+
@EnableConfigurationProperties(PrometheusRSocketClientProperties.class)
36+
public class PrometheusRSocketClientAutoConfiguration {
6437

6538
@ConditionalOnMissingBean
6639
@Bean(destroyMethod = "pushAndClose")
67-
PrometheusRSocketClient prometheusRSocketClient(PrometheusMeterRegistry meterRegistry, PrometheusRSocketProperties properties) {
40+
PrometheusRSocketClient prometheusRSocketClient(PrometheusMeterRegistry meterRegistry, PrometheusRSocketClientProperties properties) {
6841
return PrometheusRSocketClient.build(meterRegistry, properties.createClientTransport())
6942
.retry(Retry.backoff(properties.getMaxRetries(), properties.getFirstBackoff())
7043
.maxBackoff(properties.getMaxBackoff()))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.time.Duration;
2727

2828
@ConfigurationProperties("management.metrics.export.prometheus.rsocket")
29-
public class PrometheusRSocketProperties {
29+
public class PrometheusRSocketClientProperties {
3030

3131
/**
3232
* The host name of the proxy to connect to.

0 commit comments

Comments
 (0)