Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
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
openSource
spring-cloud-netflix
Commits
8af3ae8a
Unverified
Commit
8af3ae8a
authored
Jun 26, 2018
by
Ryan Baxter
Committed by
GitHub
Jun 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use management metadata in sidecar. Fixes 2859. (#3028)
parent
ab7b0fb3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
11 deletions
+95
-11
DefaultManagementMetadataProvider.java
...ix/eureka/metadata/DefaultManagementMetadataProvider.java
+1
-1
SidecarConfiguration.java
...framework/cloud/netflix/sidecar/SidecarConfiguration.java
+37
-10
SidecarApplication.java
...ngframework/cloud/netflix/sidecar/SidecarApplication.java
+26
-0
SidecarApplicationTests.java
...mework/cloud/netflix/sidecar/SidecarApplicationTests.java
+31
-0
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProvider.java
View file @
8af3ae8a
...
@@ -40,7 +40,7 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
...
@@ -40,7 +40,7 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
return
port
!=
null
&&
port
==
RANDOM_PORT
;
return
port
!=
null
&&
port
==
RANDOM_PORT
;
}
}
pr
ivate
String
getHealthCheckUrl
(
EurekaInstanceConfigBean
instance
,
int
serverPort
,
String
serverContextPath
,
pr
otected
String
getHealthCheckUrl
(
EurekaInstanceConfigBean
instance
,
int
serverPort
,
String
serverContextPath
,
String
managementContextPath
,
Integer
managementPort
,
boolean
isSecure
)
{
String
managementContextPath
,
Integer
managementPort
,
boolean
isSecure
)
{
String
healthCheckUrlPath
=
instance
.
getHealthCheckUrlPath
();
String
healthCheckUrlPath
=
instance
.
getHealthCheckUrlPath
();
String
healthCheckUrl
=
getUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
String
healthCheckUrl
=
getUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
...
...
spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/SidecarConfiguration.java
View file @
8af3ae8a
...
@@ -20,14 +20,17 @@ import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceI
...
@@ -20,14 +20,17 @@ import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceI
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.commons.util.InetUtils
;
import
org.springframework.cloud.commons.util.InetUtils
;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
org.springframework.cloud.netflix.eureka.metadata.DefaultManagementMetadataProvider
;
import
org.springframework.cloud.netflix.eureka.metadata.ManagementMetadata
;
import
org.springframework.cloud.netflix.eureka.metadata.ManagementMetadataProvider
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.ConfigurableEnvironment
;
...
@@ -36,8 +39,7 @@ import org.springframework.util.StringUtils;
...
@@ -36,8 +39,7 @@ import org.springframework.util.StringUtils;
import
com.netflix.appinfo.HealthCheckHandler
;
import
com.netflix.appinfo.HealthCheckHandler
;
import
com.netflix.discovery.EurekaClientConfig
;
import
com.netflix.discovery.EurekaClientConfig
;
import
java.net.InetAddress
;
import
java.util.Map
;
import
java.net.UnknownHostException
;
/**
/**
* Sidecar Configuration that setting up {@link com.netflix.appinfo.EurekaInstanceConfig}.
* Sidecar Configuration that setting up {@link com.netflix.appinfo.EurekaInstanceConfig}.
...
@@ -80,8 +82,17 @@ public class SidecarConfiguration {
...
@@ -80,8 +82,17 @@ public class SidecarConfiguration {
@Autowired
@Autowired
private
InetUtils
inetUtils
;
private
InetUtils
inetUtils
;
@Value
(
"${management.port:${MANAGEMENT_PORT:${server.port:${SERVER_PORT:${PORT:8080}}}}}"
)
@Value
(
value
=
"${management.port:${MANAGEMENT_PORT:#{null}}}"
)
private
int
managementPort
=
8080
;
private
Integer
managementPort
;
@Value
(
"${server.port:${SERVER_PORT:${PORT:8080}}}"
)
private
int
serverPort
=
8080
;
@Value
(
"${management.context-path:${MANAGEMENT_CONTEXT_PATH:#{null}}}"
)
private
String
managementContextPath
;
@Value
(
"${server.context-path:${SERVER_CONTEXT_PATH:/}}"
)
private
String
serverContextPath
=
"/"
;
@Value
(
"${eureka.instance.hostname:${EUREKA_INSTANCE_HOSTNAME:}}"
)
@Value
(
"${eureka.instance.hostname:${EUREKA_INSTANCE_HOSTNAME:}}"
)
private
String
hostname
;
private
String
hostname
;
...
@@ -90,7 +101,13 @@ public class SidecarConfiguration {
...
@@ -90,7 +101,13 @@ public class SidecarConfiguration {
private
ConfigurableEnvironment
env
;
private
ConfigurableEnvironment
env
;
@Bean
@Bean
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
()
{
@ConditionalOnMissingBean
public
ManagementMetadataProvider
serviceManagementMetadataProvider
()
{
return
new
DefaultManagementMetadataProvider
();
}
@Bean
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
(
ManagementMetadataProvider
managementMetadataProvider
)
{
EurekaInstanceConfigBean
config
=
new
EurekaInstanceConfigBean
(
inetUtils
);
EurekaInstanceConfigBean
config
=
new
EurekaInstanceConfigBean
(
inetUtils
);
RelaxedPropertyResolver
springPropertyResolver
=
new
RelaxedPropertyResolver
(
env
,
"spring.application."
);
RelaxedPropertyResolver
springPropertyResolver
=
new
RelaxedPropertyResolver
(
env
,
"spring.application."
);
String
springAppName
=
springPropertyResolver
.
getProperty
(
"name"
);
String
springAppName
=
springPropertyResolver
.
getProperty
(
"name"
);
...
@@ -114,10 +131,20 @@ public class SidecarConfiguration {
...
@@ -114,10 +131,20 @@ public class SidecarConfiguration {
config
.
setIpAddress
(
ipAddress
);
config
.
setIpAddress
(
ipAddress
);
}
}
String
scheme
=
config
.
getSecurePortEnabled
()
?
"https"
:
"http"
;
String
scheme
=
config
.
getSecurePortEnabled
()
?
"https"
:
"http"
;
config
.
setStatusPageUrl
(
scheme
+
"://"
+
config
.
getHostname
()
+
":"
ManagementMetadata
metadata
=
managementMetadataProvider
.
get
(
config
,
serverPort
,
+
this
.
managementPort
+
config
.
getStatusPageUrlPath
());
serverContextPath
,
managementContextPath
,
managementPort
);
config
.
setHealthCheckUrl
(
scheme
+
"://"
+
config
.
getHostname
()
+
":"
+
this
.
managementPort
+
config
.
getHealthCheckUrlPath
());
if
(
metadata
!=
null
)
{
config
.
setStatusPageUrl
(
metadata
.
getStatusPageUrl
());
config
.
setHealthCheckUrl
(
metadata
.
getHealthCheckUrl
());
if
(
config
.
isSecurePortEnabled
())
{
config
.
setSecureHealthCheckUrl
(
metadata
.
getSecureHealthCheckUrl
());
}
Map
<
String
,
String
>
metadataMap
=
config
.
getMetadataMap
();
if
(
metadataMap
.
get
(
"management.port"
)
==
null
)
{
metadataMap
.
put
(
"management.port"
,
String
.
valueOf
(
metadata
.
getManagementPort
()));
}
}
config
.
setHomePageUrl
(
scheme
+
"://"
+
config
.
getHostname
()
+
":"
+
port
config
.
setHomePageUrl
(
scheme
+
"://"
+
config
.
getHostname
()
+
":"
+
port
+
config
.
getHomePageUrlPath
());
+
config
.
getHomePageUrlPath
());
return
config
;
return
config
;
...
...
spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SidecarApplication.java
View file @
8af3ae8a
...
@@ -18,6 +18,11 @@ package org.springframework.cloud.netflix.sidecar;
...
@@ -18,6 +18,11 @@ package org.springframework.cloud.netflix.sidecar;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
org.springframework.cloud.netflix.eureka.metadata.DefaultManagementMetadataProvider
;
import
org.springframework.cloud.netflix.eureka.metadata.ManagementMetadata
;
import
org.springframework.cloud.netflix.eureka.metadata.ManagementMetadataProvider
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
@SpringBootApplication
@SpringBootApplication
...
@@ -29,4 +34,25 @@ public class SidecarApplication {
...
@@ -29,4 +34,25 @@ public class SidecarApplication {
SpringApplication
.
run
(
SidecarApplication
.
class
,
args
);
SpringApplication
.
run
(
SidecarApplication
.
class
,
args
);
}
}
@Bean
public
ManagementMetadataProvider
managementMetadataProvider
()
{
//The default management metadata provider checks for random ports, we dont care about this in tests
return
new
DefaultManagementMetadataProvider
()
{
@Override
public
ManagementMetadata
get
(
EurekaInstanceConfigBean
instance
,
int
serverPort
,
String
serverContextPath
,
String
managementContextPath
,
Integer
managementPort
)
{
String
healthCheckUrl
=
getHealthCheckUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
,
false
);
String
statusPageUrl
=
getStatusPageUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
);
ManagementMetadata
metadata
=
new
ManagementMetadata
(
healthCheckUrl
,
statusPageUrl
,
managementPort
==
null
?
serverPort
:
managementPort
);
if
(
instance
.
isSecurePortEnabled
())
{
metadata
.
setSecureHealthCheckUrl
(
getHealthCheckUrl
(
instance
,
serverPort
,
serverContextPath
,
managementContextPath
,
managementPort
,
true
));
}
return
metadata
;
}
};
}
}
}
spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SidecarApplicationTests.java
View file @
8af3ae8a
...
@@ -80,4 +80,35 @@ public class SidecarApplicationTests {
...
@@ -80,4 +80,35 @@ public class SidecarApplicationTests {
}
}
}
}
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
SidecarApplication
.
class
,
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
value
=
{
"spring.application.name=mytest"
,
"spring.cloud.client.hostname=mhhost"
,
"spring.application.instance_id=1"
,
"eureka.instance.hostname=mhhost1"
,
"sidecar.hostname=mhhost2"
,
"sidecar.port=7000"
,
"sidecar.ipAddress=127.0.0.1"
,
"management.context-path=/foo"
})
public
static
class
ManagementContextPathStatusAndHealthCheckUrls
{
@Autowired
EurekaInstanceConfigBean
config
;
@Test
public
void
testStatusAndHealthCheckUrls
()
{
assertThat
(
this
.
config
.
getStatusPageUrl
(),
equalTo
(
"http://mhhost2:0/foo/info"
));
assertThat
(
this
.
config
.
getHealthCheckUrl
(),
equalTo
(
"http://mhhost2:0/foo/health"
));
}
}
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
SidecarApplication
.
class
,
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
value
=
{
"spring.application.name=mytest"
,
"spring.cloud.client.hostname=mhhost"
,
"spring.application.instance_id=1"
,
"eureka.instance.hostname=mhhost1"
,
"sidecar.hostname=mhhost2"
,
"sidecar.port=7000"
,
"sidecar.ipAddress=127.0.0.1"
,
"server.context-path=/foo"
})
public
static
class
ServerContextPathStatusAndHealthCheckUrls
{
@Autowired
EurekaInstanceConfigBean
config
;
@Test
public
void
testStatusAndHealthCheckUrls
()
{
assertThat
(
this
.
config
.
getStatusPageUrl
(),
equalTo
(
"http://mhhost2:0/foo/info"
));
assertThat
(
this
.
config
.
getHealthCheckUrl
(),
equalTo
(
"http://mhhost2:0/foo/health"
));
}
}
}
}
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