Skip to content

Commit

Permalink
Expose server address as configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Franklin Hu committed Oct 22, 2012
1 parent 21e4316 commit 6e36739
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Expand Up @@ -116,8 +116,6 @@ trait ZipkinCollectorConfig extends ZipkinConfig[ZipkinCollector] {
def writeQueueConfig: WriteQueueConfig[T]
lazy val writeQueue: WriteQueue[T] = writeQueueConfig.apply(processor)

lazy val serverAddr = new InetSocketAddress(InetAddress.getLocalHost, serverPort)

val serverConfig: CollectorServerConfig

def apply(runtime: RuntimeEnvironment): ZipkinCollector = {
Expand Down
Expand Up @@ -23,6 +23,7 @@ import com.twitter.util.{FuturePool, Future}
import com.twitter.zipkin.config.ScribeZipkinCollectorConfig
import com.twitter.zipkin.gen
import org.apache.zookeeper.KeeperException
import java.net.InetSocketAddress

/**
* This class implements the log method from the Scribe Thrift interface.
Expand All @@ -40,15 +41,16 @@ class ScribeCollectorService(config: ScribeZipkinCollectorConfig, val writeQueue

override def start() {
/* Register a node in ZooKeeper for Scribe to pick up */
val serverAddress = new InetSocketAddress(config.serverAddress, config.serverPort)
val serverSet = new ServerSetImpl(config.zkClient, config.zkServerSetPath)
val cluster = new ZookeeperServerSetCluster(serverSet)
zkNodes = config.zkScribePaths.map {
path =>
new ResilientZKNode(path, config.serverAddr.getHostName + ":" + config.serverAddr.getPort,
new ResilientZKNode(path, serverAddress.getHostName + ":" + serverAddress.getPort,
config.zkClient, config.timer, config.statsReceiver)
}.toSeq
zkNodes foreach (_.register())
cluster.join(config.serverAddr)
cluster.join(serverAddress)

super.start()
}
Expand Down
Expand Up @@ -23,13 +23,16 @@ import com.twitter.zipkin.collector.ScribeCollectorService
import com.twitter.zipkin.gen
import org.apache.thrift.protocol.TBinaryProtocol
import com.twitter.zipkin.config.collector.CollectorServerConfig
import java.net.InetSocketAddress

class ScribeCollectorServerConfig(config: ScribeZipkinCollectorConfig) extends CollectorServerConfig {

val log = Logger.get(Logger.getClass)

def apply(): Server = {
log.info("Starting collector service on addr " + config.serverAddr)
val serverAddress = new InetSocketAddress(config.serverAddress, config.serverPort)

log.info("Starting collector service on addr " + serverAddress)

/* Start the service */
val service = new ScribeCollectorService(config, config.writeQueue, config.categories)
Expand All @@ -39,7 +42,7 @@ class ScribeCollectorServerConfig(config: ScribeZipkinCollectorConfig) extends C
/* Start the server */
ServerBuilder()
.codec(ThriftServerFramedCodec())
.bindTo(config.serverAddr)
.bindTo(serverAddress)
.name("ZipkinCollector")
.reportTo(config.statsReceiver)
.build(new gen.ZipkinCollector.FinagledService(service, new TBinaryProtocol.Factory()))
Expand Down
Expand Up @@ -23,9 +23,12 @@ import com.twitter.logging.{ConsoleHandler, LoggerFactory, Logger}
import com.twitter.util.{JavaTimer, Timer, Config}
import com.twitter.ostrich.admin._
import scala.util.matching.Regex
import java.net.{InetAddress, InetSocketAddress}

trait ZipkinConfig[T <: Service] extends Config[RuntimeEnvironment => T] {

var serverAddress: InetAddress = InetAddress.getLocalHost

/* The port on which the server runs */
var serverPort: Int

Expand Down
Expand Up @@ -17,16 +17,16 @@ package com.twitter.zipkin.query
*
*/
import com.twitter.logging.Logger
import org.apache.thrift.protocol.TBinaryProtocol
import com.twitter.zipkin.storage.{Aggregates, Index, Storage}
import com.twitter.zipkin.gen
import com.twitter.finagle.thrift.ThriftServerFramedCodec
import com.twitter.finagle.zookeeper.ZookeeperServerSetCluster
import com.twitter.finagle.builder.{ServerBuilder, Server}
import java.net.{InetAddress, InetSocketAddress}
import com.twitter.ostrich.admin.{ServiceTracker, Service}
import com.twitter.zipkin.config.ZipkinQueryConfig
import com.twitter.common.zookeeper.ServerSet
import java.net.InetSocketAddress
import org.apache.thrift.protocol.TBinaryProtocol

class ZipkinQuery(
config: ZipkinQueryConfig, serverSet: ServerSet, storage: Storage, index: Index, aggregates: Aggregates
Expand All @@ -35,7 +35,7 @@ class ZipkinQuery(
val log = Logger.get(getClass.getName)
var thriftServer: Server = null

val serverAddr = new InetSocketAddress(InetAddress.getLocalHost, config.serverPort)
val serverAddr = new InetSocketAddress(config.serverAddress, config.serverPort)

def start() {
log.info("Starting query thrift service on addr " + serverAddr)
Expand Down

0 comments on commit 6e36739

Please sign in to comment.