Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable admin #208

Closed
narcisobenigno opened this issue May 20, 2015 · 14 comments
Closed

Disable admin #208

narcisobenigno opened this issue May 20, 2015 · 14 comments

Comments

@narcisobenigno
Copy link

@narcisobenigno narcisobenigno commented May 20, 2015

Looks like I can not use admin on heroku... How can I disable it?

@cacoco
Copy link
Member

@cacoco cacoco commented May 20, 2015

@narcisobenigno can you explain a bit more what you mean when you say you can't use the admin? Can you also include any errors you're getting?

Thanks.

@schmitch
Copy link
Contributor

@schmitch schmitch commented May 26, 2015

Hi, I would like to disable the admin, too in some situations. However I don't have any problems with it yet, it's just dump when you need to configure multiple instances of finatra on a single server, ports clashing everywhere, so the less ports you need to configure, the better.

However I think it would still be great to have an admin module as a Guice Module, so we could just plug it in or plug it off easily.

Also it seems that httpAdminPort of the Ports trait has no function since the admin is configured in this way:

  def defaultHttpPort: Int = 9990
  val adminPort = flag("admin.port", new InetSocketAddress(defaultHttpPort), "Admin http server port")

I mean i could just overwrite defaultHttpPort, but still awefull. Looks like the whole trait has no effect..

EDIT:

  private def startHttpServer() {
    for (port <- parsePort(httpPortFlag)) {
      val serverBuilder = ServerBuilder()
        .codec(new RichHttp[Request](httpCodec))
        .bindTo(port)
        .name("http")

      configureHttpServer(serverBuilder)

      httpServer = serverBuilder.build(httpService)
      info("http server started on port: " + httpExternalPort.get)
    }
  }

Really strange code. the port comes from the httpPortFlag, which has a default of :8888 and then there is httpExternalPort inside the Ports trait which also defaults to :8888, but is only used for the info?!

wouldn't it be better to have something like if flag is not empty override httpExternalPort, so we could either overwrite httpExternalPort OR use the httpPortFlag?

@edma2
Copy link
Contributor

@edma2 edma2 commented May 26, 2015

The Ports trait is not meant for configuration. Its purpose is to expose the ports during integration tests so that HTTP clients can point at the correct destination.

https://github.com/twitter/finatra/blob/master/http/src/test/scala/com/twitter/finatra/http/test/EmbeddedHttpServer.scala#L39

@schmitch
Copy link
Contributor

@schmitch schmitch commented May 26, 2015

Oh however httpExternalPort is still used for the http server info message which is wrong.

OT: The next thing is there a way to set a flag inside the code?

@narcisobenigno
Copy link
Author

@narcisobenigno narcisobenigno commented May 26, 2015

Sorry by delay, and thanks by the feedback!

I don't know if is possible to configure in heroku to see de finatra admin dashboard. Then I wish to disable the dashboard (not startup it), just the server http port.

@cacoco
Copy link
Member

@cacoco cacoco commented May 28, 2015

@narcisobenigno it should be possible to just set the admin port twitter-server flag to 0, e.g.,

-admin.port=:0

I've tested this with a sample finatra application running on Heroku. Please let me know if that works for you. Thanks!

@narcisobenigno
Copy link
Author

@narcisobenigno narcisobenigno commented May 28, 2015

Okay, I will try.

Thanks

On Thu, May 28, 2015, 14:15 Christopher Coco notifications@github.com
wrote:

@narcisobenigno https://github.com/narcisobenigno it should be possible
to just set the admin port twitter-server flag to 0, e.g.,

-admin.port=:0

I've tested this with a sample finatra application running on Heroku.
Please let me know if that works for you. Thanks!


Reply to this email directly or view it on GitHub
#208 (comment).

@cacoco cacoco closed this Jun 13, 2015
@sergio91pt
Copy link

@sergio91pt sergio91pt commented Jun 25, 2015

@cacoco @narcisobenigno Setting the port to 0, assigns a random port bound to all interfaces. You can check with sudo netstat -plunt

@cacoco
Copy link
Member

@cacoco cacoco commented Jun 25, 2015

@sergio91pt yep -- unfortunately there's no way to get two assigned ports with Heroku currently so this is the workaround. You won't be able to access the admin as like you said it will be on some random port. Thanks!

@theyelllowdart
Copy link

@theyelllowdart theyelllowdart commented Mar 6, 2016

It's hacky but this works on Heroku.

Procfile
web: target/universal/stage/bin/hello-world -- -admin.port=:0 -http.port=:$PORT

Server/Module

class AdminClientModule(adminServer: => ListeningServer) extends HttpClientModule {
  override def dest: String = ":" + adminServer.boundAddress.asInstanceOf[InetSocketAddress].getPort
}

object HelloWorldMain extends HelloWorldServer

class HelloWorldServer extends HttpServer {

  override protected def modules: Seq[Module] = Vector(new AdminClientModule(adminHttpServer))
  ...
}

Controller

class AdminController @Inject()(httpClient: HttpClient) extends Controller {

  // NOTE(aaron): Use a wildcard in order to avoid being catalogued as an admin route in HttpRouter.partitionRoutesByType.
  get("/admi:*") { request: Request =>
    httpClient.execute(request)
  }
}
@aliakhtar
Copy link

@aliakhtar aliakhtar commented Feb 21, 2020

Bump - is there no way to disable the admin server?

@aliakhtar
Copy link

@aliakhtar aliakhtar commented Feb 21, 2020

@cacoco I did this but I still see the routes for admin server being created in the output when I start up the server:

2020-02-21 23:07:40,074  DEBUG main i.n.i.InMemoryDbServerMain$.updateMuxer - AdminHttpServer Muxer endpoints:
	/admin/ping => com.twitter.server.handler.ReplyHandler
	 => com.twitter.finagle.filter.OffloadFilter$Server.andThen(com.twitter.server.handler.AdminRedirectHandler)
	/admin => com.twitter.finagle.filter.OffloadFilter$Server.andThen(com.twitter.server.handler.SummaryHandler)
<snip>

I'm guessing this is because I'm not setting the value of admin.port to be the same as http.port. For http.port, I'm overriding the field in the class:

override val defaultHttpPort: String = ":8420"

but I can't find which field to override for admin.port?

@cacoco
Copy link
Member

@cacoco cacoco commented Feb 22, 2020

@aliakhtar as mentioned in the documentation, the admin is started and then shut down in the process of bringing up the server. You will see routes created but the listening server which accepts requests will not be started.

Also as linked to from the documentation the TwitterServer AdminHttpServer is what defines the admin.port flag and it's default which can be overridden in code:

https://github.com/twitter/twitter-server/blob/develop/server/src/main/scala/com/twitter/server/AdminHttpServer.scala#L117

Thus you would do:

override val defaultAdminPort: Int = 0

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants