-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from StreetContxt/add-stats
Added Stats
- Loading branch information
Showing
6 changed files
with
110 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
organization in ThisBuild := "com.contxt" | ||
scalaVersion in ThisBuild := "2.11.8" | ||
version in ThisBuild := "1.0.0-SNAPSHOT" | ||
|
||
val slf4j = "org.slf4j" % "slf4j-api" % "1.7.21" | ||
val amazonKinesisProducer = "com.amazonaws" % "amazon-kinesis-producer" % "0.12.8" | ||
val typesafeConfig = "com.typesafe" % "config" % "1.3.1" | ||
|
||
libraryDependencies ++= Seq( | ||
slf4j, | ||
amazonKinesisProducer | ||
amazonKinesisProducer, | ||
typesafeConfig | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
com.contxt.kinesis { | ||
producer { | ||
stats-class-name = "com.contxt.kinesis.NoopProducerStats" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.contxt.kinesis | ||
|
||
import com.amazonaws.services.kinesis.producer.UserRecordResult | ||
import com.typesafe.config.{ Config, ConfigFactory } | ||
import org.slf4j.LoggerFactory | ||
import scala.concurrent.Future | ||
import scala.util.control.NonFatal | ||
|
||
trait ProducerStats { | ||
def trackSend(streamId: StreamId, size: Int)(closure: => Future[UserRecordResult]): Future[UserRecordResult] | ||
def reportShutdown(streamId: StreamId): Unit | ||
} | ||
|
||
object ProducerStats { | ||
private val log = LoggerFactory.getLogger(classOf[ProducerStats]) | ||
|
||
def getInstance(config: Config): ProducerStats = { | ||
try { | ||
val className = config.getString("com.contxt.kinesis.producer.stats-class-name") | ||
Class.forName(className).newInstance().asInstanceOf[ProducerStats] | ||
} | ||
catch { | ||
case NonFatal(e) => | ||
log.error("Could not load a `ProducerStats` instance, falling back to `NoopProducerStats`.", e) | ||
new NoopProducerStats | ||
} | ||
} | ||
} | ||
|
||
class NoopProducerStats extends ProducerStats { | ||
def trackSend(streamId: StreamId, size: Int)(closure: => Future[UserRecordResult]): Future[UserRecordResult] = closure | ||
def reportShutdown(streamId: StreamId): Unit = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.contxt.kinesis | ||
|
||
case class StreamId( | ||
/** AWS region name. */ | ||
regionName: String, | ||
|
||
/** Stream name. */ | ||
streamName: String | ||
) |