Commit 5ef304a4 by Dave Syer

Make sure /hystrix.stream has the correct path

Fixes gh-52
parent af1278a4
...@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.GaugeService; import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.SmartLifecycle; import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -58,17 +59,22 @@ public class HystrixConfiguration implements ImportAware { ...@@ -58,17 +59,22 @@ public class HystrixConfiguration implements ImportAware {
public HystrixCommandAspect hystrixCommandAspect() { public HystrixCommandAspect hystrixCommandAspect() {
return new HystrixCommandAspect(); return new HystrixCommandAspect();
} }
@Bean @Bean
public HystrixShutdownHook hystrixShutdownHook() { public HystrixShutdownHook hystrixShutdownHook() {
return new HystrixShutdownHook(); return new HystrixShutdownHook();
} }
@Bean @Configuration
@ConditionalOnExpression("${hystrix.stream.endpoint.enabled:true}") @ConditionalOnExpression("${hystrix.stream.endpoint.enabled:true}")
// TODO: make it @ConditionalOnWebApp (need a nested class) @ConditionalOnWebApplication
public HystrixStreamEndpoint hystrixStreamEndpoint() { protected static class HystrixWebConfiguration {
return new HystrixStreamEndpoint();
@Bean
public HystrixStreamEndpoint hystrixStreamEndpoint() {
return new HystrixStreamEndpoint();
}
} }
@Override @Override
...@@ -88,7 +94,7 @@ public class HystrixConfiguration implements ImportAware { ...@@ -88,7 +94,7 @@ public class HystrixConfiguration implements ImportAware {
private static Log logger = LogFactory private static Log logger = LogFactory
.getLog(HystrixMetricsPollerConfiguration.class); .getLog(HystrixMetricsPollerConfiguration.class);
@Autowired @Autowired(required=false)
private GaugeService gauges; private GaugeService gauges;
private ObjectMapper mapper = new ObjectMapper(); private ObjectMapper mapper = new ObjectMapper();
...@@ -100,6 +106,9 @@ public class HystrixConfiguration implements ImportAware { ...@@ -100,6 +106,9 @@ public class HystrixConfiguration implements ImportAware {
@Override @Override
public void start() { public void start() {
if (gauges==null) {
return;
}
MetricsAsJsonPollerListener listener = new MetricsAsJsonPollerListener() { MetricsAsJsonPollerListener listener = new MetricsAsJsonPollerListener() {
@Override @Override
public void handleJsonMetric(String json) { public void handleJsonMetric(String json) {
...@@ -157,7 +166,7 @@ public class HystrixConfiguration implements ImportAware { ...@@ -157,7 +166,7 @@ public class HystrixConfiguration implements ImportAware {
@Override @Override
public boolean isRunning() { public boolean isRunning() {
return poller!=null ? poller.isRunning() : false; return poller != null ? poller.isRunning() : false;
} }
@Override @Override
...@@ -179,10 +188,10 @@ public class HystrixConfiguration implements ImportAware { ...@@ -179,10 +188,10 @@ public class HystrixConfiguration implements ImportAware {
} }
} }
/** /**
* {@link DisposableBean} that makes sure that Hystrix internal state is cleared * {@link DisposableBean} that makes sure that Hystrix internal state is cleared when
* when {@link ApplicationContext} shuts down. * {@link ApplicationContext} shuts down.
*/ */
private class HystrixShutdownHook implements DisposableBean { private class HystrixShutdownHook implements DisposableBean {
...@@ -191,6 +200,6 @@ public class HystrixConfiguration implements ImportAware { ...@@ -191,6 +200,6 @@ public class HystrixConfiguration implements ImportAware {
// Just call Hystrix to reset thread pool etc. // Just call Hystrix to reset thread pool etc.
Hystrix.reset(); Hystrix.reset();
} }
} }
} }
...@@ -25,6 +25,6 @@ import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServl ...@@ -25,6 +25,6 @@ import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServl
public class HystrixStreamEndpoint extends ServletWrappingEndpoint { public class HystrixStreamEndpoint extends ServletWrappingEndpoint {
public HystrixStreamEndpoint() { public HystrixStreamEndpoint() {
super(HystrixMetricsStreamServlet.class, "hystrixStream", "hystrix.stream", false, true); super(HystrixMetricsStreamServlet.class, "hystrixStream", "/hystrix.stream", false, true);
} }
} }
/*
* 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.junit.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
/**
* @author Dave Syer
*
*/
public class HystrixConfigurationTests {
@Test
public void nonWebAppStartsUp() {
new SpringApplicationBuilder(HystrixConfiguration.class).web(false).run().close();
}
}
/*
* 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 static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* @author Dave Syer
*
*/
public class HystrixStreamEndpointTests {
@Test
public void pathStartsWithSlash() {
HystrixStreamEndpoint endpoint = new HystrixStreamEndpoint();
assertEquals("/hystrix.stream", endpoint.getPath());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment