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
8375e3b4
Commit
8375e3b4
authored
Mar 07, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapt to changes in commons that put onus on user with @LoadBalanced
parent
790ac76a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
116 additions
and
27 deletions
+116
-27
ServoEnvironmentPostProcessor.java
.../cloud/netflix/metrics/ServoEnvironmentPostProcessor.java
+63
-0
AtlasConfiguration.java
...ework/cloud/netflix/metrics/atlas/AtlasConfiguration.java
+1
-1
EnableAtlas.java
...ingframework/cloud/netflix/metrics/atlas/EnableAtlas.java
+1
-1
spring.factories
...netflix-core/src/main/resources/META-INF/spring.factories
+4
-0
AtlasExporterTests.java
...ework/cloud/netflix/metrics/atlas/AtlasExporterTests.java
+13
-3
RibbonClientHttpRequestFactoryTests.java
...d/netflix/ribbon/RibbonClientHttpRequestFactoryTests.java
+34
-22
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/ServoEnvironmentPostProcessor.java
0 → 100644
View file @
8375e3b4
/*
* Copyright 2013-2015 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
cloud
.
netflix
.
metrics
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.env.EnvironmentPostProcessor
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.util.ClassUtils
;
/**
* @author Dave Syer
*/
public
class
ServoEnvironmentPostProcessor
implements
EnvironmentPostProcessor
{
@Override
public
void
postProcessEnvironment
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
if
(
ClassUtils
.
isPresent
(
"com.netflix.servo.monitor.Monitors"
,
null
))
{
// Make spring AOP default to target class so RestTemplates can be customized
addDefaultProperty
(
environment
,
"spring.aop.proxyTargetClass"
,
"true"
);
}
}
private
void
addDefaultProperty
(
ConfigurableEnvironment
environment
,
String
name
,
String
value
)
{
MutablePropertySources
sources
=
environment
.
getPropertySources
();
Map
<
String
,
Object
>
map
=
null
;
if
(
sources
.
contains
(
"defaultProperties"
))
{
PropertySource
<?>
source
=
sources
.
get
(
"defaultProperties"
);
if
(
source
instanceof
MapPropertySource
)
{
map
=
((
MapPropertySource
)
source
).
getSource
();
}
}
else
{
map
=
new
LinkedHashMap
<>();
sources
.
addLast
(
new
MapPropertySource
(
"defaultProperties"
,
map
));
}
if
(
map
!=
null
)
{
map
.
put
(
name
,
value
);
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/atlas/Atlas
Auto
Configuration.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/atlas/AtlasConfiguration.java
View file @
8375e3b4
...
...
@@ -38,7 +38,7 @@ import com.netflix.servo.tag.BasicTagList;
@Configuration
@ConditionalOnClass
(
AtlasMetricObserver
.
class
)
@Import
(
ServoMetricsAutoConfiguration
.
class
)
public
class
Atlas
Auto
Configuration
{
public
class
AtlasConfiguration
{
@Autowired
(
required
=
false
)
private
Collection
<
AtlasTagProvider
>
tagProviders
;
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/metrics/atlas/EnableAtlas.java
View file @
8375e3b4
...
...
@@ -29,6 +29,6 @@ import org.springframework.context.annotation.Import;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
@Import
(
Atlas
Auto
Configuration
.
class
)
@Import
(
AtlasConfiguration
.
class
)
public
@interface
EnableAtlas
{
}
spring-cloud-netflix-core/src/main/resources/META-INF/spring.factories
View file @
8375e3b4
...
...
@@ -11,3 +11,6 @@ org.springframework.cloud.netflix.metrics.servo.ServoMetricsAutoConfiguration
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker=\
org.springframework.cloud.netflix.hystrix.HystrixCircuitBreakerConfiguration
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.cloud.netflix.metrics.ServoEnvironmentPostProcessor
\ No newline at end of file
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/metrics/atlas/AtlasExporterTests.java
View file @
8375e3b4
...
...
@@ -20,6 +20,7 @@ import org.junit.runner.RunWith;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
...
...
@@ -47,14 +48,16 @@ public class AtlasExporterTests {
@Test
public
void
exportMetricsAtPeriodicIntervals
()
{
MockRestServiceServer
mockServer
=
MockRestServiceServer
.
createServer
(
restTemplate
);
MockRestServiceServer
mockServer
=
MockRestServiceServer
.
createServer
(
this
.
restTemplate
);
mockServer
.
expect
(
MockRestRequestMatchers
.
requestTo
(
"atlas/api/v1/publish"
))
.
andExpect
(
MockRestRequestMatchers
.
method
(
HttpMethod
.
POST
))
.
andRespond
(
MockRestResponseCreators
.
withSuccess
(
"{\"status\" : \"OK\"}"
,
MediaType
.
APPLICATION_JSON
));
.
andRespond
(
MockRestResponseCreators
.
withSuccess
(
"{\"status\" : \"OK\"}"
,
MediaType
.
APPLICATION_JSON
));
DynamicCounter
.
increment
(
"counterThatWillBeSentToAtlas"
);
atlasExporter
.
export
();
this
.
atlasExporter
.
export
();
mockServer
.
verify
();
}
...
...
@@ -64,6 +67,13 @@ public class AtlasExporterTests {
@Configuration
@EnableAtlas
class
AtlasExporterConfiguration
{
@LoadBalanced
@Bean
public
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
}
@Bean
public
static
PropertySourcesPlaceholderConfigurer
properties
()
throws
Exception
{
final
PropertySourcesPlaceholderConfigurer
config
=
new
PropertySourcesPlaceholderConfigurer
();
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactoryTests.java
View file @
8375e3b4
...
...
@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -47,11 +48,11 @@ import org.springframework.web.client.RestTemplate;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
lombok.SneakyThrows
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
lombok.SneakyThrows
;
/**
* @author Spencer Gibb
*/
...
...
@@ -70,12 +71,13 @@ public class RibbonClientHttpRequestFactoryTests {
@Test
public
void
requestFactoryIsRibbon
()
{
assertTrue
(
"wrong RequestFactory type"
,
restTemplate
.
getRequestFactory
()
instanceof
RibbonClientHttpRequestFactory
);
assertTrue
(
"wrong RequestFactory type"
,
this
.
restTemplate
.
getRequestFactory
()
instanceof
RibbonClientHttpRequestFactory
);
}
@Test
public
void
vanillaRequestWorks
()
{
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
"http://simple/"
,
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
getForEntity
(
"http://simple/"
,
String
.
class
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello"
,
response
.
getBody
());
...
...
@@ -83,37 +85,41 @@ public class RibbonClientHttpRequestFactoryTests {
@Test
public
void
requestWithPathParamWorks
()
{
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
"http://simple/path/{param}"
,
String
.
class
,
"world"
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
getForEntity
(
"http://simple/path/{param}"
,
String
.
class
,
"world"
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello world"
,
response
.
getBody
());
}
@Test
public
void
requestWithEncodedPathParamWorks
()
{
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
"http://simple/path/{param}"
,
String
.
class
,
"world & everyone else"
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
getForEntity
(
"http://simple/path/{param}"
,
String
.
class
,
"world & everyone else"
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello world & everyone else"
,
response
.
getBody
());
assertEquals
(
"wrong response body"
,
"hello world & everyone else"
,
response
.
getBody
());
}
@Test
public
void
requestWithRequestParamWorks
()
{
ResponseEntity
<
String
>
response
=
restTemplate
.
getForEntity
(
"http://simple/request?param={param}"
,
String
.
class
,
"world"
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
getForEntity
(
"http://simple/request?param={param}"
,
String
.
class
,
"world"
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello world"
,
response
.
getBody
());
}
@Test
public
void
requestWithPostWorks
()
{
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
"http://simple/post"
,
"world"
,
String
.
class
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
postForEntity
(
"http://simple/post"
,
"world"
,
String
.
class
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello world"
,
response
.
getBody
());
}
@Test
public
void
requestWithEmptyPostWorks
()
{
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
"http://simple/emptypost"
,
""
,
String
.
class
);
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
postForEntity
(
"http://simple/emptypost"
,
""
,
String
.
class
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello empty"
,
response
.
getBody
());
}
...
...
@@ -122,18 +128,18 @@ public class RibbonClientHttpRequestFactoryTests {
@SneakyThrows
public
void
requestWithHeaderWorks
()
{
RequestEntity
<
Void
>
entity
=
RequestEntity
.
get
(
new
URI
(
"http://simple/header"
))
.
header
(
"X-Param"
,
"world"
)
.
build
();
ResponseEntity
<
String
>
response
=
restTemplate
.
exchange
(
entity
,
String
.
class
);
.
header
(
"X-Param"
,
"world"
)
.
build
();
ResponseEntity
<
String
>
response
=
this
.
restTemplate
.
exchange
(
entity
,
String
.
class
);
assertEquals
(
"wrong response code"
,
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
"wrong response body"
,
"hello world"
,
response
.
getBody
());
}
@Test
public
void
invalidHostNameError
()
{
exceptionRule
.
expect
(
ResourceAccessException
.
class
);
exceptionRule
.
expectMessage
(
"Invalid hostname"
);
restTemplate
.
getForEntity
(
"http://simple_bad"
,
String
.
class
);
this
.
exceptionRule
.
expect
(
ResourceAccessException
.
class
);
this
.
exceptionRule
.
expectMessage
(
"Invalid hostname"
);
this
.
restTemplate
.
getForEntity
(
"http://simple_bad"
,
String
.
class
);
}
@Configuration
...
...
@@ -142,6 +148,12 @@ public class RibbonClientHttpRequestFactoryTests {
@RibbonClient
(
value
=
"simple"
,
configuration
=
SimpleRibbonClientConfiguration
.
class
)
protected
static
class
App
{
@LoadBalanced
@Bean
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
}
@RequestMapping
(
"/"
)
public
String
hi
()
{
return
"hello"
;
...
...
@@ -149,17 +161,17 @@ public class RibbonClientHttpRequestFactoryTests {
@RequestMapping
(
"/path/{param}"
)
public
String
hiParam
(
@PathVariable
(
"param"
)
String
param
)
{
return
"hello "
+
param
;
return
"hello "
+
param
;
}
@RequestMapping
(
"/request"
)
public
String
hiRequest
(
@RequestParam
(
"param"
)
String
param
)
{
return
"hello "
+
param
;
return
"hello "
+
param
;
}
@RequestMapping
(
value
=
"/post"
,
method
=
RequestMethod
.
POST
)
public
String
hiPost
(
@RequestBody
String
param
)
{
return
"hello "
+
param
;
return
"hello "
+
param
;
}
@RequestMapping
(
value
=
"/emptypost"
,
method
=
RequestMethod
.
POST
)
...
...
@@ -169,7 +181,7 @@ public class RibbonClientHttpRequestFactoryTests {
@RequestMapping
(
"/header"
)
public
String
hiHeader
(
@RequestHeader
(
"X-Param"
)
String
param
)
{
return
"hello "
+
param
;
return
"hello "
+
param
;
}
}
}
...
...
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