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;
import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -58,17 +59,22 @@ public class HystrixConfiguration implements ImportAware {
public HystrixCommandAspect hystrixCommandAspect() {
return new HystrixCommandAspect();
}
@Bean
public HystrixShutdownHook hystrixShutdownHook() {
return new HystrixShutdownHook();
}
@Bean
@ConditionalOnExpression("${hystrix.stream.endpoint.enabled:true}")
// TODO: make it @ConditionalOnWebApp (need a nested class)
public HystrixStreamEndpoint hystrixStreamEndpoint() {
return new HystrixStreamEndpoint();
@Configuration
@ConditionalOnExpression("${hystrix.stream.endpoint.enabled:true}")
@ConditionalOnWebApplication
protected static class HystrixWebConfiguration {
@Bean
public HystrixStreamEndpoint hystrixStreamEndpoint() {
return new HystrixStreamEndpoint();
}
}
@Override
......@@ -88,7 +94,7 @@ public class HystrixConfiguration implements ImportAware {
private static Log logger = LogFactory
.getLog(HystrixMetricsPollerConfiguration.class);
@Autowired
@Autowired(required=false)
private GaugeService gauges;
private ObjectMapper mapper = new ObjectMapper();
......@@ -100,6 +106,9 @@ public class HystrixConfiguration implements ImportAware {
@Override
public void start() {
if (gauges==null) {
return;
}
MetricsAsJsonPollerListener listener = new MetricsAsJsonPollerListener() {
@Override
public void handleJsonMetric(String json) {
......@@ -157,7 +166,7 @@ public class HystrixConfiguration implements ImportAware {
@Override
public boolean isRunning() {
return poller!=null ? poller.isRunning() : false;
return poller != null ? poller.isRunning() : false;
}
@Override
......@@ -179,10 +188,10 @@ public class HystrixConfiguration implements ImportAware {
}
}
/**
* {@link DisposableBean} that makes sure that Hystrix internal state is cleared
* when {@link ApplicationContext} shuts down.
* {@link DisposableBean} that makes sure that Hystrix internal state is cleared when
* {@link ApplicationContext} shuts down.
*/
private class HystrixShutdownHook implements DisposableBean {
......@@ -191,6 +200,6 @@ public class HystrixConfiguration implements ImportAware {
// Just call Hystrix to reset thread pool etc.
Hystrix.reset();
}
}
}
......@@ -25,6 +25,6 @@ import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServl
public class HystrixStreamEndpoint extends ServletWrappingEndpoint {
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