diff options
author | Colin Smith <Colin.Smith@monitise.com> | 2015-10-09 14:31:20 +0100 |
---|---|---|
committer | Colin Smith <Colin.Smith@monitise.com> | 2015-10-09 14:31:20 +0100 |
commit | a4924ee0607f17bfe5ba61742e035af19c381785 (patch) | |
tree | 91f297a67952f91ffc492bb73ad660787862a174 /kamon-newrelic/src/main/scala/kamon/newrelic | |
parent | 91859be4df789c64ae30ef879b9c6c83503b99c2 (diff) | |
download | Kamon-a4924ee0607f17bfe5ba61742e035af19c381785.tar.gz Kamon-a4924ee0607f17bfe5ba61742e035af19c381785.tar.bz2 Kamon-a4924ee0607f17bfe5ba61742e035af19c381785.zip |
+ newrelic: add ssl support to agent
Use kamon.newrelic.ssl = true to send metrics over https
Diffstat (limited to 'kamon-newrelic/src/main/scala/kamon/newrelic')
3 files changed, 15 insertions, 11 deletions
diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/Agent.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/Agent.scala index 3e43da36..49a4993c 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/Agent.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/Agent.scala @@ -63,7 +63,7 @@ class Agent extends Actor with SprayJsonSupport with ActorLogging with MetricsSu def disconnected(attemptsLeft: Int): Receive = { case Connect ⇒ pipe(connectToCollector) to self - case Connected(collector, runID) ⇒ configureChildren(collector, runID) + case Connected(collector, runID, scheme) ⇒ configureChildren(collector, runID, scheme) case ConnectFailed(reason) if (attemptsLeft > 0) ⇒ scheduleReconnection(reason, attemptsLeft) case ConnectFailed(reason) ⇒ giveUpConnection() } @@ -85,8 +85,8 @@ class Agent extends Actor with SprayJsonSupport with ActorLogging with MetricsSu context stop self } - def configureChildren(collector: String, runID: Long): Unit = { - log.info("Configuring New Relic reporters to use runID: [{}] and collector: [{}]", runID, collector) + def configureChildren(collector: String, runID: Long, scheme: String): Unit = { + log.info("Configuring New Relic reporters to use runID: [{}] and collector: [{}] over: [{}]", runID, collector, scheme) context.children.foreach(_ ! Configure(collector, runID)) context become connected } @@ -105,8 +105,8 @@ class Agent extends Actor with SprayJsonSupport with ActorLogging with MetricsSu def connectToCollector: Future[ConnectResult] = { (for { collector ← selectCollector - runID ← connect(collector, agentSettings) - } yield Connected(collector, runID)) recover { case error ⇒ ConnectFailed(error) } + (runID, scheme) ← connect(collector, agentSettings) + } yield Connected(collector, runID, scheme)) recover { case error ⇒ ConnectFailed(error) } } def selectCollector: Future[String] = { @@ -116,10 +116,10 @@ class Agent extends Actor with SprayJsonSupport with ActorLogging with MetricsSu } } - def connect(collectorHost: String, connect: AgentSettings): Future[Long] = { + def connect(collectorHost: String, connect: AgentSettings): Future[(Long, String)] = { val apiClient = new ApiMethodClient(collectorHost, None, agentSettings, IO(Http)(context.system)) apiClient.invokeMethod(RawMethods.Connect, connect) map { json ⇒ - json.extract[Long]('return_value / 'agent_run_id) + (json.extract[Long]('return_value / 'agent_run_id), apiClient.scheme) } } } @@ -132,12 +132,12 @@ object Agent { case class Configure(collector: String, runID: Long) sealed trait ConnectResult - case class Connected(collector: String, runID: Long) extends ConnectResult + case class Connected(collector: String, runID: Long, scheme: String) extends ConnectResult case class ConnectFailed(reason: Throwable) extends ConnectResult } case class AgentSettings(licenseKey: String, appName: String, hostname: String, pid: Int, operationTimeout: Timeout, - maxConnectionRetries: Int, retryDelay: FiniteDuration, apdexT: Double) + maxConnectionRetries: Int, retryDelay: FiniteDuration, apdexT: Double, ssl: Boolean) object AgentSettings { @@ -147,6 +147,7 @@ object AgentSettings { val newRelicConfig = config.getConfig("kamon.newrelic") val licenseKey = newRelicConfig.getString("license-key") assert(licenseKey != "<put-your-key-here>", "You forgot to include your New Relic license key in the configuration settings!") + val ssl = newRelicConfig.getBoolean("ssl") AgentSettings( licenseKey, @@ -156,7 +157,8 @@ object AgentSettings { Timeout(newRelicConfig.getFiniteDuration("operation-timeout")), newRelicConfig.getInt("max-connect-retries"), newRelicConfig.getFiniteDuration("connect-retry-delay"), - newRelicConfig.getFiniteDuration("apdexT").toMillis / 1E3D) + newRelicConfig.getFiniteDuration("apdexT").toMillis / 1E3D, + ssl) } } diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/ApiMethodClient.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/ApiMethodClient.scala index 263faa63..0550f433 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/ApiMethodClient.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/ApiMethodClient.scala @@ -31,7 +31,8 @@ class ApiMethodClient(host: String, val runID: Option[Long], agentSettings: Agen } val httpClient = encode(Deflate) ~> sendReceive(httpTransport) ~> decode(Deflate) ~> unmarshal[JsValue] - val baseCollectorUri = Uri("/agent_listener/invoke_raw_method").withHost(host).withScheme("http") + val scheme = if (agentSettings.ssl) "https" else "http" + val baseCollectorUri = Uri("/agent_listener/invoke_raw_method").withHost(host).withScheme(scheme) def invokeMethod[T: Marshaller](method: String, payload: T): Future[JsValue] = { val methodQuery = ("method" -> method) +: baseQuery diff --git a/kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala b/kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala index 7f0d1383..8db24e46 100644 --- a/kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala +++ b/kamon-newrelic/src/main/scala/kamon/newrelic/JsonProtocol.scala @@ -30,6 +30,7 @@ object JsonProtocol extends DefaultJsonProtocol { "host" -> JsString(obj.hostname), "identifier" -> JsString(s"java:${appNames(0)}"), "language" -> JsString("java"), + "ssl" -> JsString(obj.ssl.toString), "pid" -> JsNumber(obj.pid))) } } |