Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
f4c4b1d3
Commit
f4c4b1d3
authored
Mar 29, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Permit use of https for configuring Prometheus push gateway"
Closes gh-16084
parent
eed4e9ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
7 deletions
+39
-7
PrometheusMetricsExportAutoConfiguration.java
.../prometheus/PrometheusMetricsExportAutoConfiguration.java
+8
-0
PrometheusProperties.java
...igure/metrics/export/prometheus/PrometheusProperties.java
+2
-2
PrometheusMetricsExportAutoConfigurationTests.java
...etheus/PrometheusMetricsExportAutoConfigurationTests.java
+29
-5
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.java
View file @
f4c4b1d3
...
...
@@ -26,6 +26,8 @@ import io.micrometer.prometheus.PrometheusConfig;
import
io.micrometer.prometheus.PrometheusMeterRegistry
;
import
io.prometheus.client.CollectorRegistry
;
import
io.prometheus.client.exporter.PushGateway
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnExposedEndpoint
;
...
...
@@ -107,6 +109,9 @@ public class PrometheusMetricsExportAutoConfiguration {
@ConditionalOnProperty
(
prefix
=
"management.metrics.export.prometheus.pushgateway"
,
name
=
"enabled"
)
public
static
class
PrometheusPushGatewayConfiguration
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
PrometheusPushGatewayConfiguration
.
class
);
/**
* The fallback job name. We use 'spring' since there's a history of Prometheus
* spring integration defaulting to that name from when Prometheus integration
...
...
@@ -135,6 +140,9 @@ public class PrometheusMetricsExportAutoConfiguration {
return
new
PushGateway
(
new
URL
(
url
));
}
catch
(
MalformedURLException
ex
)
{
logger
.
warn
(
String
.
format
(
"Invalid PushGateway base url '%s': update your configuration to a valid URL"
,
url
));
return
new
PushGateway
(
url
);
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusProperties.java
View file @
f4c4b1d3
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -83,7 +83,7 @@ public class PrometheusProperties {
/**
* Base URL for the Pushgateway.
*/
private
String
baseUrl
=
"localhost:9091"
;
private
String
baseUrl
=
"
http://
localhost:9091"
;
/**
* Frequency with which to push metrics.
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java
View file @
f4c4b1d3
...
...
@@ -20,6 +20,7 @@ import io.micrometer.core.instrument.Clock;
import
io.micrometer.prometheus.PrometheusConfig
;
import
io.micrometer.prometheus.PrometheusMeterRegistry
;
import
io.prometheus.client.CollectorRegistry
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration
;
...
...
@@ -28,6 +29,7 @@ import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusScra
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.rule.OutputCapture
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -42,6 +44,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public
class
PrometheusMetricsExportAutoConfigurationTests
{
@Rule
public
final
OutputCapture
output
=
new
OutputCapture
();
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
PrometheusMetricsExportAutoConfiguration
.
class
));
...
...
@@ -152,9 +157,28 @@ public class PrometheusMetricsExportAutoConfigurationTests {
AutoConfigurations
.
of
(
ManagementContextAutoConfiguration
.
class
))
.
withPropertyValues
(
"management.metrics.export.prometheus.pushgateway.enabled=true"
)
.
withUserConfiguration
(
BaseConfiguration
.
class
)
.
run
((
context
)
->
hasGatewayURL
(
context
,
"http://localhost:9091/metrics/job/"
));
.
withUserConfiguration
(
BaseConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
this
.
output
.
toString
())
.
doesNotContain
(
"Invalid PushGateway base url"
);
hasGatewayURL
(
context
,
"http://localhost:9091/metrics/job/"
);
});
}
@Test
@Deprecated
public
void
withCustomLegacyPushGatewayURL
()
{
this
.
contextRunner
.
withConfiguration
(
AutoConfigurations
.
of
(
ManagementContextAutoConfiguration
.
class
))
.
withPropertyValues
(
"management.metrics.export.prometheus.pushgateway.enabled=true"
,
"management.metrics.export.prometheus.pushgateway.base-url=localhost:9090"
)
.
withUserConfiguration
(
BaseConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
this
.
output
.
toString
())
.
contains
(
"Invalid PushGateway base url"
)
.
contains
(
"localhost:9090"
);
hasGatewayURL
(
context
,
"http://localhost:9090/metrics/job/"
);
});
}
@Test
...
...
@@ -164,10 +188,10 @@ public class PrometheusMetricsExportAutoConfigurationTests {
AutoConfigurations
.
of
(
ManagementContextAutoConfiguration
.
class
))
.
withPropertyValues
(
"management.metrics.export.prometheus.pushgateway.enabled=true"
,
"management.metrics.export.prometheus.pushgateway.base-url=https://
localhost:8080/push
"
)
"management.metrics.export.prometheus.pushgateway.base-url=https://
example.com:8080
"
)
.
withUserConfiguration
(
BaseConfiguration
.
class
)
.
run
((
context
)
->
hasGatewayURL
(
context
,
"https://
localhost:8080/push
/metrics/job/"
));
"https://
example.com:8080
/metrics/job/"
));
}
private
void
hasGatewayURL
(
AssertableApplicationContext
context
,
String
url
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment