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
61513287
Unverified
Commit
61513287
authored
Sep 28, 2017
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate /hystrix.stream to management context.
fixes gh-2309i
parent
8011b66e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
153 additions
and
170 deletions
+153
-170
ServletWrappingEndpoint.java
...ework/cloud/netflix/endpoint/ServletWrappingEndpoint.java
+0
-103
HystrixCircuitBreakerConfiguration.java
...d/netflix/hystrix/HystrixCircuitBreakerConfiguration.java
+5
-26
HystrixManagementContextConfiguration.java
...etflix/hystrix/HystrixManagementContextConfiguration.java
+71
-0
HystrixProperties.java
...ingframework/cloud/netflix/hystrix/HystrixProperties.java
+70
-0
HystrixStreamEndpoint.java
...ramework/cloud/netflix/hystrix/HystrixStreamEndpoint.java
+0
-33
spring.factories
...netflix-core/src/main/resources/META-INF/spring.factories
+3
-0
HystrixStreamEndpointTests.java
...ork/cloud/netflix/hystrix/HystrixStreamEndpointTests.java
+4
-8
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/endpoint/ServletWrappingEndpoint.java
deleted
100644 → 0
View file @
8011b66e
/*
* 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
.
endpoint
;
import
javax.servlet.Servlet
;
import
javax.servlet.ServletContext
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.InitializingBean
;
// import org.springframework.boot.actuate.endpoint.Endpoint;
// import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.context.ServletContextAware
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.mvc.ServletWrappingController
;
//FIXME 2.0.x
public
abstract
class
ServletWrappingEndpoint
implements
InitializingBean
,
ApplicationContextAware
,
ServletContextAware
/*, MvcEndpoint*/
{
// TODO: move to spring-boot?
private
String
path
;
private
boolean
sensitive
;
private
boolean
enabled
=
true
;
private
final
ServletWrappingController
controller
=
new
ServletWrappingController
();
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
this
.
controller
.
afterPropertiesSet
();
}
@Override
public
void
setServletContext
(
ServletContext
servletContext
)
{
this
.
controller
.
setServletContext
(
servletContext
);
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
controller
.
setApplicationContext
(
applicationContext
);
}
protected
ServletWrappingEndpoint
(
Class
<?
extends
Servlet
>
servletClass
,
String
servletName
,
String
path
,
boolean
sensitive
,
boolean
enabled
)
{
this
.
controller
.
setServletClass
(
servletClass
);
this
.
controller
.
setServletName
(
servletName
);
this
.
path
=
path
;
this
.
sensitive
=
sensitive
;
this
.
enabled
=
enabled
;
}
@RequestMapping
(
"**"
)
public
ModelAndView
handle
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
return
this
.
controller
.
handleRequest
(
request
,
response
);
}
public
boolean
isEnabled
()
{
return
this
.
enabled
;
}
public
ServletWrappingController
getController
()
{
return
this
.
controller
;
}
/*@Override
public String getPath() {
return this.path;
}
@Override
public boolean isSensitive() {
return this.sensitive;
}
@Override
public Class<? extends Endpoint<?>> getEndpointType() {
return null;
}*/
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerConfiguration.java
View file @
61513287
/*
* Copyright 2013-201
6
the original author or authors.
* Copyright 2013-201
7
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
* 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,
...
...
@@ -16,20 +16,16 @@
package
org
.
springframework
.
cloud
.
netflix
.
hystrix
;
import
com.netflix.hystrix.Hystrix
;
import
com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect
;
import
com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet
;
import
org.apache.catalina.core.ApplicationContext
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.client.actuator.NamedFeature
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.netflix.hystrix.Hystrix
;
import
com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect
;
/**
* @author Spencer Gibb
* @author Christian Dupuis
...
...
@@ -53,23 +49,6 @@ public class HystrixCircuitBreakerConfiguration {
return
HasFeatures
.
namedFeatures
(
new
NamedFeature
(
"Hystrix"
,
HystrixCommandAspect
.
class
));
}
@Configuration
@ConditionalOnProperty
(
value
=
"hystrix.stream.endpoint.enabled"
,
matchIfMissing
=
true
)
@ConditionalOnWebApplication
@ConditionalOnClass
({
Health
.
class
,
HystrixMetricsStreamServlet
.
class
})
protected
static
class
HystrixWebConfiguration
{
@Bean
public
HystrixStreamEndpoint
hystrixStreamEndpoint
()
{
return
new
HystrixStreamEndpoint
();
}
@Bean
public
HasFeatures
hystrixStreamFeature
()
{
return
HasFeatures
.
namedFeature
(
"Hystrix Stream Servlet"
,
HystrixStreamEndpoint
.
class
);
}
}
//FIXME: 2.0.0
/*@Configuration
@ConditionalOnProperty(value = "hystrix.metrics.enabled", matchIfMissing = true)
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixManagementContextConfiguration.java
0 → 100644
View file @
61513287
/*
* Copyright 2013-2017 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
.
hystrix
;
import
com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.servlet.ManagementServletContext
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.context.annotation.Bean
;
import
com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet
;
/**
* See original {@link org.springframework.boot.actuate.autoconfigure.jolokia.JolokiaManagementContextConfiguration}
*/
@ManagementContextConfiguration
@ConditionalOnProperty
(
value
=
"management.hystrix.enabled"
,
matchIfMissing
=
true
)
@ConditionalOnWebApplication
@ConditionalOnBean
(
HystrixCommandAspect
.
class
)
// only install the stream if enabled
@ConditionalOnClass
({
Health
.
class
,
HystrixMetricsStreamServlet
.
class
})
@EnableConfigurationProperties
(
HystrixProperties
.
class
)
class
HystrixManagementContextConfiguration
{
private
final
ManagementServletContext
managementServletContext
;
private
final
HystrixProperties
properties
;
public
HystrixManagementContextConfiguration
(
ManagementServletContext
managementServletContext
,
HystrixProperties
properties
)
{
this
.
managementServletContext
=
managementServletContext
;
this
.
properties
=
properties
;
}
@Bean
public
ServletRegistrationBean
<
HystrixMetricsStreamServlet
>
jolokiaServlet
()
{
String
path
=
this
.
managementServletContext
.
getContextPath
()
+
this
.
properties
.
getPath
();
String
urlMapping
=
(
path
.
endsWith
(
"/"
)
?
path
+
"*"
:
path
+
"/*"
);
ServletRegistrationBean
<
HystrixMetricsStreamServlet
>
registration
=
new
ServletRegistrationBean
<>(
new
HystrixMetricsStreamServlet
(),
urlMapping
);
registration
.
setInitParameters
(
this
.
properties
.
getConfig
());
return
registration
;
}
@Bean
public
HasFeatures
hystrixStreamFeature
()
{
return
HasFeatures
.
namedFeature
(
"Hystrix Stream Servlet"
,
HystrixMetricsStreamServlet
.
class
);
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixProperties.java
0 → 100644
View file @
61513287
/*
* Copyright 2013-2017 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
.
hystrix
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Configuration properties for Hystrix Servlet.
*
* @author Spencer Gibb
* @since 2.0.0
*/
@ConfigurationProperties
(
prefix
=
"management.hystrix"
)
public
class
HystrixProperties
{
/**
* Enable Hystrix Stream.
*/
private
boolean
enabled
;
/**
* Path at which Hystrix Stream will be available.
*/
private
String
path
=
"/hystrix.stream"
;
/**
* Hystrix settings. These are traditionally set using servlet parameters. Refer to
* the documentation of Hystrix for more details.
*/
private
final
Map
<
String
,
String
>
config
=
new
HashMap
<>();
public
boolean
isEnabled
()
{
return
this
.
enabled
;
}
public
void
setEnabled
(
boolean
enabled
)
{
this
.
enabled
=
enabled
;
}
public
String
getPath
()
{
return
this
.
path
;
}
public
void
setPath
(
String
path
)
{
this
.
path
=
path
;
}
public
Map
<
String
,
String
>
getConfig
()
{
return
this
.
config
;
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixStreamEndpoint.java
deleted
100644 → 0
View file @
8011b66e
/*
* Copyright 2013-2014 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
.
hystrix
;
import
org.springframework.cloud.netflix.endpoint.ServletWrappingEndpoint
;
import
com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet
;
/**
* @author Spencer Gibb
*/
public
class
HystrixStreamEndpoint
extends
ServletWrappingEndpoint
{
public
HystrixStreamEndpoint
()
{
super
(
HystrixMetricsStreamServlet
.
class
,
"hystrixStream"
,
"/hystrix.stream"
,
false
,
true
);
}
}
spring-cloud-netflix-core/src/main/resources/META-INF/spring.factories
View file @
61513287
...
...
@@ -13,3 +13,5 @@ org.springframework.cloud.netflix.zuul.ZuulProxyAutoConfiguration
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker=\
org.springframework.cloud.netflix.hystrix.HystrixCircuitBreakerConfiguration
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=\
org.springframework.cloud.netflix.hystrix.HystrixManagementContextConfiguration
\ No newline at end of file
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixStreamEndpointTests.java
View file @
61513287
...
...
@@ -5,14 +5,13 @@
* 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
* 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
.
hystrix
;
...
...
@@ -24,15 +23,14 @@ import java.util.List;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -65,14 +63,12 @@ public class HystrixStreamEndpointTests {
private
int
port
=
0
;
@Test
@Ignore
// FIXME: 2.0.x
public
void
pathStartsWithSlash
()
{
Hystrix
StreamEndpoint
endpoint
=
new
HystrixStreamEndpoint
();
// assertEquals("/hystrix.stream", endpoint
.getPath());
Hystrix
Properties
properties
=
new
HystrixProperties
();
assertEquals
(
"/hystrix.stream"
,
properties
.
getPath
());
}
@Test
@Ignore
// FIXME: 2.0.x
public
void
hystrixStreamWorks
()
throws
Exception
{
String
url
=
"http://localhost:"
+
port
;
// you have to hit a Hystrix circuit breaker before the stream sends anything
...
...
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