diff --git a/server/src/main/scala/com/twitter/server/Admin.scala b/server/src/main/scala/com/twitter/server/Admin.scala index 690315aa..fe070859 100644 --- a/server/src/main/scala/com/twitter/server/Admin.scala +++ b/server/src/main/scala/com/twitter/server/Admin.scala @@ -1,49 +1,23 @@ package com.twitter.server import com.twitter.app.App +import com.twitter.finagle.http.Method import com.twitter.finagle.stats.{ - WithHistogramDetails, + AggregateWithHistogramDetails, DelegatingStatsReceiver, - AggregateWithHistogramDetails + StatsReceiver, + WithHistogramDetails } -import com.twitter.finagle.http.Method +import com.twitter.server.AdminHttpServer.Route import com.twitter.server.handler._ import com.twitter.server.view._ object Admin { /** - * Common constants for [[AdminHttpServer.Route]]'s `group`. + * Defines many of the default `/admin/` HTTP routes. */ - object Grouping { - val ProcessInfo: String = "Process Info" - val PerfProfile: String = "Performance Profile" - val Utilities: String = "Utilities" - val Metrics: String = "Metrics" - } - - /** - * Constants for Admin endpoints. - */ - object Path { - val Root: String = "" - val Admin: String = "/admin" - val Clients: String = Admin + "/clients/" - val Servers: String = Admin + "/servers/" - val Files: String = Admin + "/files/" - } -} - -/** - * Defines many of the default `/admin/` HTTP routes. - */ -trait Admin { self: App with AdminHttpServer with Stats => - import Admin._ - import AdminHttpServer.Route - import Admin.Grouping - - override protected def routes: Seq[Route] = { - + def adminRoutes(statsReceiver: StatsReceiver, app: App): Seq[Route] = { // we handle ping in-band with the global default worker pool val colocatedRoutes = Seq( Route( @@ -82,7 +56,7 @@ trait Admin { self: App with AdminHttpServer with Stats => ), Route( path = "/admin/server_info", - handler = new TextBlockView().andThen(new ServerInfoHandler(self)), + handler = new TextBlockView().andThen(new ServerInfoHandler()), alias = "Build Properties", group = Some(Grouping.ProcessInfo), includeInIndex = true @@ -166,7 +140,7 @@ trait Admin { self: App with AdminHttpServer with Stats => ), Route( path = "/admin/shutdown", - handler = new ShutdownHandler(this), + handler = new ShutdownHandler(app), alias = "Shutdown", group = Some(Grouping.Utilities), includeInIndex = true, @@ -264,7 +238,7 @@ trait Admin { self: App with AdminHttpServer with Stats => group = Some(Grouping.Utilities), includeInIndex = true ) - ).map(Route.isolate) + ).map(AdminHttpServer.Route.isolate) // If histograms are available, add an additional endpoint val histos = DelegatingStatsReceiver @@ -306,4 +280,25 @@ trait Admin { self: App with AdminHttpServer with Stats => ) } } + + /** + * Common constants for [[AdminHttpServer.Route]]'s `group`. + */ + object Grouping { + val ProcessInfo: String = "Process Info" + val PerfProfile: String = "Performance Profile" + val Utilities: String = "Utilities" + val Metrics: String = "Metrics" + } + + /** + * Constants for Admin endpoints. + */ + object Path { + val Root: String = "" + val Admin: String = "/admin" + val Clients: String = Admin + "/clients/" + val Servers: String = Admin + "/servers/" + val Files: String = Admin + "/files/" + } } diff --git a/server/src/main/scala/com/twitter/server/AdminHttpServer.scala b/server/src/main/scala/com/twitter/server/AdminHttpServer.scala index af83d1d5..0540d1fe 100644 --- a/server/src/main/scala/com/twitter/server/AdminHttpServer.scala +++ b/server/src/main/scala/com/twitter/server/AdminHttpServer.scala @@ -129,7 +129,7 @@ object AdminHttpServer { } -trait AdminHttpServer { self: App => +trait AdminHttpServer { self: App with Stats => import AdminHttpServer._ // We use slf4-api directly b/c we're in a trait and want the trait class to be the Logger name @@ -159,7 +159,8 @@ trait AdminHttpServer { self: App => LoadService[AdminHttpMuxHandler]() .map(handler => Route.from(handler.route)) .map(Route.isolate) - private var allRoutes: Seq[Route] = loadServiceRoutes + + private[this] var allRoutes: Seq[Route] = loadServiceRoutes /** * The address to which the Admin HTTP server is bound. @@ -179,8 +180,7 @@ trait AdminHttpServer { self: App => addAdminRoutes(Seq(route)) } - @deprecated("Routes should be added via `AdminHttpServer#addAdminRoutes`", "2018-10-17") - protected def routes: Seq[Route] = Nil + def routes: Seq[Route] = allRoutes /** * Name used for registration in the [[com.twitter.util.registry.Library]] @@ -312,7 +312,7 @@ trait AdminHttpServer { self: App => } premain { - addAdminRoutes(routes) + addAdminRoutes(Admin.adminRoutes(statsReceiver, self)) startServer() } } diff --git a/server/src/main/scala/com/twitter/server/TwitterServer.scala b/server/src/main/scala/com/twitter/server/TwitterServer.scala index 8d284d63..6d248fad 100644 --- a/server/src/main/scala/com/twitter/server/TwitterServer.scala +++ b/server/src/main/scala/com/twitter/server/TwitterServer.scala @@ -36,13 +36,12 @@ trait TwitterServer extends App with Slf4jBridge with Logging + with Stats with Linters with DtabFlags with Hooks with AdminHttpServer - with Admin - with Lifecycle - with Stats { + with Lifecycle { /** Don't let applications opt-out */ final override val suppressGracefulShutdownErrors: Boolean = false diff --git a/server/src/main/scala/com/twitter/server/handler/ServerInfoHandler.scala b/server/src/main/scala/com/twitter/server/handler/ServerInfoHandler.scala index 3c37cdbe..bb3d82c9 100644 --- a/server/src/main/scala/com/twitter/server/handler/ServerInfoHandler.scala +++ b/server/src/main/scala/com/twitter/server/handler/ServerInfoHandler.scala @@ -17,7 +17,7 @@ import scala.collection.JavaConverters._ * A simple http service for serving up information pulled from a build.properties * file. */ -class ServerInfoHandler(obj: AnyRef) extends Service[Request, Response] { +class ServerInfoHandler() extends Service[Request, Response] { private[this] val mxRuntime = ManagementFactory.getRuntimeMXBean private[this] val registry = GlobalRegistry.get diff --git a/server/src/test/scala/com/twitter/server/handler/ServerInfoHandlerTest.scala b/server/src/test/scala/com/twitter/server/handler/ServerInfoHandlerTest.scala index bb348c8c..7123730c 100644 --- a/server/src/test/scala/com/twitter/server/handler/ServerInfoHandlerTest.scala +++ b/server/src/test/scala/com/twitter/server/handler/ServerInfoHandlerTest.scala @@ -14,7 +14,7 @@ class ServerInfoHandlerTest extends FunSuite { GlobalRegistry.get.exists(_.key.startsWith(key)) test("ServerInfo handler display server information") { - val handler = new ServerInfoHandler(this) + val handler = new ServerInfoHandler() val req = Request("/") val res = Await.result(handler(req)) @@ -31,7 +31,7 @@ class ServerInfoHandlerTest extends FunSuite { } test("ServerInfo handler returns the right content-type") { - val handler = new ServerInfoHandler(this) + val handler = new ServerInfoHandler() val req = Request("/") val res = Await.result(handler(req)) assert(res.contentType.contains("application/json;charset=UTF-8")) @@ -42,7 +42,7 @@ class ServerInfoHandlerTest extends FunSuite { test(s"ServerInfo handler adds ${key.mkString(" ")} to Global Registry on instantiation") { GlobalRegistry.withRegistry(new SimpleRegistry) { assert(!isRegistered(key)) - new ServerInfoHandler(this) + new ServerInfoHandler() assert(isRegistered(key)) } }