diff options
author | Marco Manzo <mmanzo@myfitnesspal.com> | 2015-04-01 10:19:23 -0700 |
---|---|---|
committer | Marco Manzo <mmanzo@myfitnesspal.com> | 2015-04-01 10:19:23 -0700 |
commit | 09d18e7d24e9c7148cccdbec8ae7a55f29ab27af (patch) | |
tree | f0e6a1d6a8ec30eeea8adc5065f54c62581ebc72 /kamon-statsd/src | |
parent | ef43abf9b54ba70783eb645f020b87c18bb58cb4 (diff) | |
download | Kamon-09d18e7d24e9c7148cccdbec8ae7a55f29ab27af.tar.gz Kamon-09d18e7d24e9c7148cccdbec8ae7a55f29ab27af.tar.bz2 Kamon-09d18e7d24e9c7148cccdbec8ae7a55f29ab27af.zip |
= statsd: creation of InetSocketAddress instances against the provided UDP host/port are not deferred until it's required for sending a metric payload.
Diffstat (limited to 'kamon-statsd/src')
3 files changed, 9 insertions, 7 deletions
diff --git a/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala b/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala index d406faf6..91d05510 100644 --- a/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala +++ b/kamon-statsd/src/main/scala/kamon/statsd/StatsD.scala @@ -43,7 +43,6 @@ class StatsDExtension(system: ExtendedActorSystem) extends Kamon.Extension { val metricsExtension = Kamon.metrics val tickInterval = metricsExtension.settings.tickInterval - val statsDHost = new InetSocketAddress(statsDConfig.getString("hostname"), statsDConfig.getInt("port")) val flushInterval = statsDConfig.getFiniteDuration("flush-interval") val maxPacketSizeInBytes = statsDConfig.getBytes("max-packet-size") val keyGeneratorFQCN = statsDConfig.getString("metric-key-generator") @@ -62,7 +61,8 @@ class StatsDExtension(system: ExtendedActorSystem) extends Kamon.Extension { val keyGenerator = system.dynamicAccess.createInstanceFor[MetricKeyGenerator](keyGeneratorFQCN, (classOf[Config], config) :: Nil).get val metricsSender = system.actorOf(StatsDMetricsSender.props( - statsDHost, + statsDConfig.getString("hostname"), + statsDConfig.getInt("port"), maxPacketSizeInBytes, keyGenerator), "statsd-metrics-sender") diff --git a/kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala b/kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala index 3241e1f3..70ff1b45 100644 --- a/kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala +++ b/kamon-statsd/src/main/scala/kamon/statsd/StatsDMetricsSender.scala @@ -26,7 +26,7 @@ import java.util.Locale import kamon.metric.instrument.{ Counter, Histogram } -class StatsDMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long, metricKeyGenerator: MetricKeyGenerator) +class StatsDMetricsSender(statsDHost: String, statsDPort: Int, maxPacketSizeInBytes: Long, metricKeyGenerator: MetricKeyGenerator) extends Actor with UdpExtensionProvider { import context.system @@ -38,6 +38,8 @@ class StatsDMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long, udpExtension ! Udp.SimpleSender + def newSocketAddress = new InetSocketAddress(statsDHost, statsDPort) + def receive = { case Udp.SimpleSenderReady ⇒ context.become(ready(sender)) @@ -48,7 +50,7 @@ class StatsDMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long, } def writeMetricsToRemote(tick: TickMetricSnapshot, udpSender: ActorRef): Unit = { - val packetBuilder = new MetricDataPacketBuilder(maxPacketSizeInBytes, udpSender, remote) + val packetBuilder = new MetricDataPacketBuilder(maxPacketSizeInBytes, udpSender, newSocketAddress) for ( (entity, snapshot) ← tick.metrics; @@ -80,8 +82,8 @@ class StatsDMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long, } object StatsDMetricsSender { - def props(remote: InetSocketAddress, maxPacketSize: Long, metricKeyGenerator: MetricKeyGenerator): Props = - Props(new StatsDMetricsSender(remote, maxPacketSize, metricKeyGenerator)) + def props(statsDHost: String, statsDPort: Int, maxPacketSize: Long, metricKeyGenerator: MetricKeyGenerator): Props = + Props(new StatsDMetricsSender(statsDHost, statsDPort, maxPacketSize, metricKeyGenerator)) } trait UdpExtensionProvider { diff --git a/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala b/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala index 1e53f48f..51e7cf19 100644 --- a/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala +++ b/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala @@ -138,7 +138,7 @@ class StatsDMetricSenderSpec extends BaseKamonSpec("statsd-metric-sender-spec") def setup(metrics: Map[Entity, EntitySnapshot]): TestProbe = { val udp = TestProbe() - val metricsSender = system.actorOf(Props(new StatsDMetricsSender(new InetSocketAddress("127.0.0.1", 0), testMaxPacketSize, metricKeyGenerator) { + val metricsSender = system.actorOf(Props(new StatsDMetricsSender("127.0.0.1", 0, testMaxPacketSize, metricKeyGenerator) { override def udpExtension(implicit system: ActorSystem): ActorRef = udp.ref })) |