TwitterServer — TwitterServer 24.2.0 documentation (original) (raw)
TwitterServer defines a template from which servers at Twitter are built. It provides common application components such as an administrative HTTP server, tracing, stats, etc. These features are wired in correctly for use in production at Twitter.
Getting Started¶
TwitterServer is published to Maven central:
com.twitter twitter-server_2.12 24.2.0or, with sbt:
libraryDependencies += "com.twitter" %% "twitter-server" % "24.2.0"
First we’ll need to import a few things into our namespace.
import com.twitter.finagle.{Http, Service} import com.twitter.finagle.http.{Request, Response, Status} import com.twitter.server.TwitterServer import com.twitter.util.{Await, Future}
TwitterServer defines its own version of the standard main. To use it, create an object extended with com.twitter.server.TwitterServer, and define the main() method (no arguments).
In this example, we use Finagle to start an HTTP server on port 8888. The service bound to this port is a simple hello service.
object BasicServer extends TwitterServer { val service = new Service[Request, Response] { def apply(request: Request) = { val response = Response(request.version, Status.Ok) response.contentString = "hello" Future.value(response) } }
def main(): Unit = { val server = Http.serve(":8888", service) onExit { server.close() } Await.ready(server) } }
onExit is used to register code to be run when the process shutdown is requested.
After compiling, we can start the server like any other java or scala process.
$ java -jar target/myserver-1.0.0-SNAPSHOT.jar & [1] 74159 I 1210 21:32:39.326 THREAD1: /admin => com.twitter.server.handler.SummaryHandler ... I 1210 21:32:39.332 THREAD1: /favicon.ico => com.twitter.server.handler.ResourceHandler I 1210 21:32:39.340 THREAD1: Serving admin http on 0.0.0.0/0.0.0.0:9990 I 1210 21:32:39.361 THREAD1: Finagle version 6.31.0 (rev=50d3bb0eea5ad3ed332111d707184c80fed6a506) built at 20151203-164135 I 1210 21:32:39.910 THREAD1: Tracer: com.twitter.finagle.zipkin.thrift.SamplingTracer
$ curl localhost:8888 hello
This server is fully configured to run in Twitter’s production environment. See features for more details.
User’s guide¶
- Features
- HTTP Admin interface
- Process Info
* /admin/lint
* /admin/threads
* /admin/registry.json
* /admin/balancers.json
* /admin/server_info
* /admin/announcer - Utilities
* /admin/tracing
* /admin/logging
* /admin/toggles
* /admin/tunables - Metrics
* /admin/metrics
* /admin/metrics.json
* /admin/histograms
* /admin/histograms.json
* /admin/metric_metadata.json
* Top-level/instance-wide Fields:
* Metadata Object Fields:
* Source Object Fields:
* /admin/metric/expressions.json
* Top-level/instance-wide Fields:
* Expression Object Fields:
* Labels Entries:
* Bounds Object Fields: - Profiling
* /admin/pprof/contention
* /admin/contention
* /admin/pprof/profile
* /admin/pprof/heap - Downstream Clients
* /admin/clients - Listening Servers
* /admin/servers
* /admin/servers/connections
- Process Info
- Using TwitterServer from Java
- Migration from Ostrich
- FAQ
- Changelog
- Unreleased
- 24.2.0
- 23.11.0
- 22.12.0
* Runtime Behavior Changes - 22.7.0
- 22.4.0
- 22.3.0
* Runtime Behavior Changes - 22.2.0
- 22.1.0
* Runtime Behavior Changes - 21.12.0
- 21.11.0
- 21.10.0
- 21.9.0
* Runtime Behavior Changes - 21.8.0 (No 21.7.0 Release)
* Admin Endpoint Versions
* Runtime Behavior Changes - 21.6.0
* Runtime Behavior Changes - 21.5.0
- 21.4.0
- 21.3.0
* Breaking API Changes
* Runtime Behavior Changes - 21.2.0
- 21.1.0
- 20.12.0
- 20.10.0
- 20.9.0
* Breaking API Changes - 20.8.1
- 20.8.0 (DO NOT USE)
- 20.7.0
* Breaking API Changes - 20.6.0
- 20.5.0
* Runtime Behavior Changes - 20.4.1
- 20.4.0 (DO NOT USE)
- 20.3.0
- 20.2.1
- 20.1.0
* Changed - 19.12.0
- 19.11.0
- 19.10.0
- 19.9.0
- 19.8.0
* Changes - 19.7.0
* Changes - 19.6.0
* Changes
* New Features - 19.5.1
- 19.5.0
* Changes - 19.4.0
* Changes - 19.3.0
- 19.2.0
- 19.1.0
- 18.12.0
- 18.11.0
- 18.10.0
* Changes
* Runtime Behavior Changes - 18.9.1
- 18.9.0
* Runtime Behavior Changes - 18.8.0
* New Features - 18.7.0
- 18.6.0
* New Features - 18.5.0
* Runtime Behavior Changes - 18.4.0
- 18.3.0
- 18.2.0
* Dependencies - 18.1.0
- 17.12.0
* Bug Fixes - 17.11.0
* Breaking API Changes - 17.10.0
* Release Version Format
* Runtime Behavior Changes
* Breaking API Changes - 1.32.0
* Breaking API Changes - 1.31.0
- 1.30.0
* Runtime Behavior Changes
* Breaking API Changes - 1.29.0
- 1.28.0
* Dependencies - 1.27.0
* New Features - 1.26.0
* Bug Fixes - 1.25.0
* New Features
* Runtime Behavior Changes - 1.24.0
- 1.23.0
- 1.22.0
* New Features
* Runtime Behavior Changes - 1.21.0
* Bug Fixes
* New Features
* Breaking API Changes - 1.20.0
* Runtime Behavior Changes
* New Features - 1.19.0
* New Features - 1.18.0
* New Features - 1.17.0
- 1.16.0
- 1.15.0
* New Features
* Runtime Behavior Changes - 1.14.0
* Dependencies - 1.13.0
- 1.12.0
- 1.11.0
* New Features - 1.10.0
* New Features
* Dependencies - 1.9.0
* New Features
* Dependencies - 1.8.0
* New Features
* Runtime Behavior Changes
* Breaking API Changes - 1.7.6
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.3
- 1.0.2
- 1.0.1