Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Gave up and just made health monitor paths configurable, under the se…

…rvice.
  • Loading branch information...
commit d63247fabec487050d3d4179a27f14b5fd91cdda 1 parent 71b5bb7
@nuttycom nuttycom authored
View
3  core/src/main/scala/blueeyes/core/service/HttpServices.scala
@@ -91,7 +91,7 @@ object DelegatingService {
class HttpHandlerService[A, B, C](h: HttpServiceHandler[B, C], f: A => B) extends CustomHttpService[A, C] {
val service = (r: HttpRequest[A]) => h(r.map(f)).success
- val metadata = DescriptionMetadata("(opaque HTTP handler)")
+ val metadata = NoMetadata
}
class FailureService[A, B](onFailure: HttpRequest[A] => (HttpFailure, String)) extends CustomHttpService[A, B] {
@@ -116,7 +116,6 @@ class DebugService[A, B](logger: Logger, val delegate: HttpService[A, B]) extend
class HealthMonitorService[A, B](context: ServiceContext, monitor: HealthMonitor, startTime: Long)(implicit jv2b: JValue => B) extends CustomHttpService[A, Future[HttpResponse[B]]] {
val service = (req: HttpRequest[A]) => Success {
import scalaz.syntax.show._
- println("Serviced request " + req.show)
for (requests <- monitor.toJValue) yield {
val version = context.serviceVersion
val responseContent = JObject(
View
23 core/src/main/scala/blueeyes/core/service/ServiceDescriptorFactoryCombinators.scala
@@ -50,9 +50,13 @@ trait ServiceDescriptorFactoryCombinators extends HttpRequestHandlerCombinators
* }}}
*/
def healthMonitor[T, S](f: HealthMonitor => ServiceDescriptorFactory[T, S])
- (implicit jv2t: JValue => T, executor: ExecutionContext): ServiceDescriptorFactory[T, S] = healthMonitor(defaultShutdownTimeout)(f)
+ (implicit jv2t: JValue => T, executor: ExecutionContext): ServiceDescriptorFactory[T, S] = healthMonitor("/health", defaultShutdownTimeout)(f)
- def healthMonitor[T, S](shutdownTimeout: Timeout, config: Seq[IntervalConfig] = defaultHealthMonitorConfig)
+ def healthMonitor[T, S](pathPrefix: RestPathPattern)
+ (f: HealthMonitor => ServiceDescriptorFactory[T, S])
+ (implicit jv2t: JValue => T, executor: ExecutionContext): ServiceDescriptorFactory[T, S] = healthMonitor(pathPrefix, defaultShutdownTimeout)(f)
+
+ def healthMonitor[T, S](pathPrefix: RestPathPattern, shutdownTimeout: Timeout, config: Seq[IntervalConfig] = defaultHealthMonitorConfig)
(f: HealthMonitor => ServiceDescriptorFactory[T, S])
(implicit jv2t: JValue => T, executor: ExecutionContext): ServiceDescriptorFactory[T, S] = {
(context: ServiceContext) => {
@@ -71,14 +75,11 @@ trait ServiceDescriptorFactoryCombinators extends HttpRequestHandlerCombinators
val monitoredService = new MonitorHttpRequestService(service, monitor)
- val monitorService = path("/blueeyes/services/" + context.serviceName + "/v" + context.serviceVersion.majorVersion + "/health") {
- debug(logger) { get { new HealthMonitorService[T, T](context, monitor, startTime) } }
+ val monitorService = path(pathPrefix) {
+ get { new HealthMonitorService[T, T](context, monitor, startTime) }
}
- val resultService = monitoredService ~ monitorService
-
- println("Metadata: " + Metadata.serviceMetadata(resultService))
- (resultService, monitorStoppable)
+ (monitorService ~ monitoredService, monitorStoppable)
}
)
}
@@ -94,7 +95,9 @@ trait ServiceDescriptorFactoryCombinators extends HttpRequestHandlerCombinators
* }
* }}}
*/
- def help[T, S](f: => ServiceDescriptorFactory[T, S])(implicit s2t: String => T, executor: ExecutionContext): ServiceDescriptorFactory[T, S] = {
+ def help[T, S](f: => ServiceDescriptorFactory[T, S])(implicit s2t: String => T, executor: ExecutionContext): ServiceDescriptorFactory[T, S] = help("/docs/api")(f)
+
+ def help[T, S](pathPrefix: RestPathPattern)(f: => ServiceDescriptorFactory[T, S])(implicit s2t: String => T, executor: ExecutionContext): ServiceDescriptorFactory[T, S] = {
(context: ServiceContext) => {
val underlying = f(context)
underlying.copy(
@@ -102,7 +105,7 @@ trait ServiceDescriptorFactoryCombinators extends HttpRequestHandlerCombinators
val (service, stoppable) = underlying.runningState(state)
val helpService = {
service ~
- path("/blueeyes/services/" + context.serviceName + "/v" + context.serviceVersion.majorVersion + "/docs/api") {
+ path(pathPrefix) {
get {
produce(text/html){
new HttpHandlerService(
View
4 core/src/test/scala/blueeyes/core/service/HttpServiceDescriptorFactoryCombinatorsSpec.scala
@@ -95,7 +95,7 @@ class HttpServiceDescriptorFactoryCombinatorsSpec extends BlueEyesServiceSpecifi
"support health monitor statistics" in {
import blueeyes.json.JParser.parse
- monitorClient.get[JValue]("/blueeyes/services/email/v1/health") must succeedWithContent { (content: JValue) =>
+ monitorClient.get[JValue]("/health") must succeedWithContent { (content: JValue) =>
(content \ "requests" \ "GET" \ "count" \ "eternity" mustEqual(parse("[1]"))) and
(content \ "requests" \ "GET" \ "timing" mustNotEqual(JUndefined)) and
(content \ "requests" \ "GET" \ "timing" \ "perSecond" \ "eternity" mustNotEqual(JUndefined)) and
@@ -121,7 +121,7 @@ trait HealthMonitorTestService extends BlueEyesServiceBuilder with ServiceDescri
val emailService = service ("email", "1.2.3") {
requestLogging(Timeout(60000)) {
logging { log =>
- healthMonitor(Timeout(60000), List(eternity)) { monitor =>
+ healthMonitor("/health", Timeout(60000), List(eternity)) { monitor =>
serviceLocator { locator: ServiceLocator[ByteChunk] =>
context => {
request {
View
6 core/src/test/scala/blueeyes/health/IntervalHealthMonitorSpec.scala
@@ -70,9 +70,11 @@ with FutureMatchers {
monitor.error("foo")(new NullPointerException())
Thread.sleep(900)
- val monitorJson = JParser.parse("""{"foo":{"errorDistribution":{"java.lang.NullPointerException":{"1s x 3":[1,0,0]}},"count":{"1s x 3":[1,0,0]}}}""")
+ val monitorJson = JParser.parseUnsafe("""{"foo":{"errorDistribution":{"java.lang.NullPointerException":{"1s x 3":[1,0,0]}},"count":{"1s x 3":[1,0,0]}}}""")
val jValue = monitor.toJValue
- jValue.map(_.renderCanonical) must whenDelivered (be_==(monitorJson.renderCanonical))
+ jValue must whenDelivered {
+ be_==(monitorJson)
+ }
}
"composes into JValue" in{
Please sign in to comment.
Something went wrong with that request. Please try again.