Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderdean committed May 14, 2016
2 parents 2aa8ce3 + ad51853 commit fde976a
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 68 deletions.
25 changes: 19 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
language: scala
scala:
- 2.10.4
- 2.11.5
- 2.10.4
- 2.11.5
jdk:
- oraclejdk7
- openjdk6
- openjdk7
- oraclejdk7
- openjdk6
- openjdk7
script:
- sbt test
- sbt test
deploy:
skip_cleanup: true
provider: script
script: ./.travis/deploy.sh $TRAVIS_TAG
on:
condition: '"${TRAVIS_SCALA_VERSION}" == "2.11.5" && "${TRAVIS_JDK_VERSION}" == "oraclejdk7"'
tags: true
env:
global:
- secure: CMQoRlhW/ejJjiTIryucBgLXpbMOPx4tP9fzEKDpcltjQMZDIRyAezilraVXdI6Nap4BwbR+JuBXaG0wnfIR7hmEJe2EiWJoTWDXaHM2XnbPMsr44lXvDFPBm2H56jTf/yVTpp2HJO/iaeg+wMODPs9NqK974NY90WlwXuqIbZY=
- secure: WuGBdY3IXh9RP2q0ffVy/Q/qDGTv/DOxjW8dG1BK6F21Itz+9O3cnqHlQtNsoVMB2FmpU3Gb66sOyOYsbE4FDNB+RkFZ+bQ5qlYwNtqea6IgyODWFYMf/6+BxlyEKyFo45BHF33TIZet37vVWx9qdDPaN0tZ8fV5+gwtUa4BJ44=
- secure: "YTyO7algll9BM6I3RA5qMmfjgDTv7Al+oCZQ1SXewNV9jZQYy3DdQjwFDMvhSI2tqTlJs9rWb2pr0yE12YE/JRQDEJqf0XIZYRF6skkqSJy7BcOcbTqseRbY8DThaVtW9HqIHJq2WzoJMEU9KtYsU4ZX3MlthNgPH8hqoFLjKyg="
- secure: "hKu4UPezvg5GCUyOwtnQ0ZOUZA6bLLC1coodfnSKhTGZTvT4kS5ckbLqMtQTMpbW3+TZLbAuhzIemrxWbvPKJVbw6YEl9ScrsPuJ7ovyRBoIuFp66+BH4apQig7YQ8Lpt2f3Vhq74X0x4NLSfVTgnC2TzzE3wc5T8X/f03rbKzU="
24 changes: 24 additions & 0 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

tag_version=$1

mkdir ~/.bintray/
FILE=$HOME/.bintray/.credentials
cat <<EOF >$FILE
realm = Bintray API Realm
host = api.bintray.com
user = $BINTRAY_USER
password = $BINTRAY_API_KEY
EOF

cd $TRAVIS_BUILD_DIR
pwd

project_version=$(sbt version -Dsbt.log.noformat=true | perl -ne 'print $1 if /(\d+\.\d+[^\r\n]*)/')
if [ "${project_version}" == "${tag_version}" ]; then
sbt +publish
sbt +bintraySyncMavenCentral
else
echo "Tag version '${tag_version}' doesn't match version in scala project ('${project_version}'). Aborting!"
exit 1
fi
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Version 0.3.0 (2016-05-14)
--------------------------
Added support for true timestamp (#28)
Added HTTPS support to all emitters (#33)
Added missing setters for lang, page and useragent (#34)
Added trackSelfDescribingEvent method (#30)
Added Bintray credentials to .travis.yml (#41)
Fixed incorrect `instance_identity_document` jsonschema (#29)
Updated build configuration to publish to JCenter and Maven Central (#31)
Removed Snowplow Maven Repo and scala-util dependency (#42)

Version 0.2.0 (2015-10-14)
--------------------------
Added a custom context based on EC2 instance metadata (#2)
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ guest$ cd /vagrant
guest$ sbt test
```

## Publishing

```bash
host$ sbt publish-local
```

## Find out more

| Technical Docs | Setup Guide | Roadmap | Contributing |
Expand All @@ -35,7 +29,7 @@ guest$ sbt test

## Copyright and license

The Snowplow Scala Tracker is copyright 2015 Snowplow Analytics Ltd.
The Snowplow Scala Tracker is copyright 2015-2016 Snowplow Analytics Ltd.

Licensed under the **[Apache License, Version 2.0] [license]** (the "License");
you may not use this software except in compliance with the License.
Expand All @@ -52,7 +46,7 @@ limitations under the License.
[license-image]: http://img.shields.io/badge/license-Apache--2-blue.svg?style=flat
[license]: http://www.apache.org/licenses/LICENSE-2.0

[release-image]: http://img.shields.io/badge/release-0.2.0-blue.svg?style=flat
[release-image]: http://img.shields.io/badge/release-0.3.0-blue.svg?style=flat
[releases]: https://github.com/snowplow/snowplow-scala-tracker/releases

[snowplow]: http://snowplowanalytics.com
Expand Down
37 changes: 24 additions & 13 deletions project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
import bintray.BintrayPlugin._
import bintray.BintrayKeys._
import sbt._
import Keys._

Expand All @@ -18,7 +20,7 @@ object BuildSettings {
// Basic settings for our app
lazy val basicSettings = Seq[Setting[_]](
organization := "com.snowplowanalytics",
version := "0.2.0",
version := "0.3.0",
description := "Scala tracker for Snowplow",
scalaVersion := "2.10.6",
crossScalaVersions := Seq("2.10.6", "2.11.5"),
Expand All @@ -40,19 +42,28 @@ object BuildSettings {
Seq(file)
})

// Publish settings
// TODO: update with ivy credentials etc when we start using Nexus
lazy val publishSettings = Seq[Setting[_]](
// Enables publishing to maven repo
publishMavenStyle := true,
// Bintray publishing settings
lazy val publishSettings = bintraySettings ++ Seq[Setting[_]](
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.html")),
bintrayOrganization := Some("snowplow"),
bintrayRepository := "snowplow-maven"
)

publishTo <<= version { version =>
val basePath = "target/repo/%s".format {
if (version.trim.endsWith("SNAPSHOT")) "snapshots/" else "releases/"
}
Some(Resolver.file("Local Maven repository", file(basePath)) transactional())
}
// Maven Central publishing settings
lazy val mavenCentralExtras = Seq[Setting[_]](
pomIncludeRepository := { x => false },
homepage := Some(url("http://snowplowanalytics.com")),
scmInfo := Some(ScmInfo(url("https://github.com/snowplow/snowplow-scala-tracker"), "scm:[email protected]:snowplow/snowplow-scala-tracker.git")),
pomExtra := (
<developers>
<developer>
<name>Snowplow Analytics Ltd</name>
<email>support@snowplowanalytics.com</email>
<organization>Snowplow Analytics Ltd</organization>
<organizationUrl>http://snowplowanalytics.com</organizationUrl>
</developer>
</developers>)
)

lazy val buildSettings = basicSettings ++ scalifySettings ++ publishSettings
lazy val buildSettings = basicSettings ++ scalifySettings ++ publishSettings ++ mavenCentralExtras
}
6 changes: 1 addition & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import Keys._
object Dependencies {

val resolutionRepos = Seq(
// For scala-util
"Snowplow Analytics" at "http://maven.snplow.com/releases/",
// For Twitter's LRU cache
"Twitter Maven Repo" at "http://maven.twttr.com/",
"Sonatype" at "https://oss.sonatype.org/content/repositories/releases"
Expand All @@ -33,7 +31,6 @@ object Dependencies {
val jackson = "1.9.7"

// Scala
val scalaUtil = "0.1.0"
val json4s = "3.2.11"
val spray = "1.3.3"
val akka = "2.3.14"
Expand Down Expand Up @@ -64,7 +61,6 @@ object Dependencies {
val jackson = "org.codehaus.jackson" % "jackson-mapper-asl" % V.jackson

// Scala
val scalaUtil = "com.snowplowanalytics" % "scala-util" % V.scalaUtil
val sprayClient = "io.spray" %% "spray-client" % V.spray
val akka = "com.typesafe.akka" %% "akka-actor" % V.akka
val json4sJackson = "org.json4s" %% "json4s-jackson" % V.json4s
Expand Down Expand Up @@ -94,4 +90,4 @@ object Dependencies {
} else {
on211
}))
}
}
1 change: 0 additions & 1 deletion project/SnowplowTrackerBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ object SnowplowTrackerBuild extends Build {
Libraries.jodaConvert,
Libraries.jodaMoney,
Libraries.jackson,
Libraries.scalaUtil,
Libraries.json4sJackson,
Libraries.sprayClient,
Libraries.akka,
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.2
sbt.version=0.13.11
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object Ec2Metadata {
implicit val timeout = Timeout(shortTimeout)
val pipeline: HttpRequest => Future[HttpResponse] = sendReceive

val instanceIdentitySchema = "iglu:com.amazon.aws.ec2/instance_identity_document"
val instanceIdentitySchema = "iglu:com.amazon.aws.ec2/instance_identity_document/jsonschema/1-0-0"
val instanceIdentityUri = "http://169.254.169.254/latest/dynamic/instance-identity/document/"

private var contextSlot: Option[SelfDescribingJson] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class Subject {
this
}

def setLang(lang: String): Subject = {
standardNvPairs += ("lang" -> lang)
this
}

def setDomainUserId(domainUserId: String): Subject = {
standardNvPairs += ("duid" -> domainUserId)
this
Expand All @@ -61,6 +66,11 @@ class Subject {
this
}

def setUseragent(useragent: String): Subject = {
standardNvPairs += ("ua" -> useragent)
this
}

def setNetworkUserId(nuid: String): Subject = {
standardNvPairs += ("tnuid" -> nuid)
this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import java.util.UUID
// Scala
import scala.concurrent.Promise
import scala.concurrent.ExecutionContext.Implicits.global
import scala.language.implicitConversions
import scala.util.{ Failure, Success }

import emitters.TEmitter
Expand All @@ -31,6 +32,7 @@ import emitters.TEmitter
* @param encodeBase64 Whether to encode JSONs
*/
class Tracker(emitters: Seq[TEmitter], namespace: String, appId: String, encodeBase64: Boolean = true) {
import Tracker._

private val Version = s"scala-${generated.ProjectSettings.version}"

Expand Down Expand Up @@ -78,14 +80,15 @@ class Tracker(emitters: Seq[TEmitter], namespace: String, appId: String, encodeB
private def completePayload(
payload: Payload,
contexts: Seq[SelfDescribingJson],
timestamp: Option[Long]): Payload = {
timestamp: Option[Timestamp]): Payload = {

payload.add("eid", UUID.randomUUID().toString)

if (!payload.nvPairs.contains("dtm")) {
timestamp match {
case Some(dtm) => payload.add("dtm", dtm.toString)
case None => payload.add("dtm", System.currentTimeMillis().toString)
case Some(DeviceCreatedTimestamp(dtm)) => payload.add("dtm", dtm.toString)
case Some(TrueTimestamp(ttm)) => payload.add("ttm", ttm.toString)
case None => payload.add("dtm", System.currentTimeMillis().toString)
}
}

Expand Down Expand Up @@ -130,7 +133,7 @@ class Tracker(emitters: Seq[TEmitter], namespace: String, appId: String, encodeB
def trackUnstructEvent(
unstructEvent: SelfDescribingJson,
contexts: Seq[SelfDescribingJson] = Nil,
timestamp: Option[Long] = None): Tracker = {
timestamp: Option[Timestamp] = None): Tracker = {

val payload = new Payload()

Expand All @@ -147,6 +150,21 @@ class Tracker(emitters: Seq[TEmitter], namespace: String, appId: String, encodeB
this
}

/**
* Track a Snowplow unstructured event
* Alias for [[trackUnstructEvent]]
*
* @param unstructEvent self-describing JSON for the event
* @param contexts list of additional contexts
* @param timestamp optional user-provided timestamp (ms) for the event
* @return The tracker instance
*/
def trackSelfDescribingEvent(
unstructEvent: SelfDescribingJson,
contexts: Seq[SelfDescribingJson] = Nil,
timestamp: Option[Timestamp] = None): Tracker =
trackUnstructEvent(unstructEvent, contexts, timestamp)

/**
* Track a Snowplow structured event
*
Expand All @@ -166,7 +184,7 @@ class Tracker(emitters: Seq[TEmitter], namespace: String, appId: String, encodeB
property: Option[String] = None,
value: Option[Double] = None,
contexts: Seq[SelfDescribingJson] = Nil,
timestamp: Option[Long] = None): Tracker = {
timestamp: Option[Timestamp] = None): Tracker = {

val payload = new Payload()

Expand Down Expand Up @@ -197,7 +215,7 @@ class Tracker(emitters: Seq[TEmitter], namespace: String, appId: String, encodeB
pageTitle: Option[String] = None,
referrer: Option[String] = None,
contexts: Seq[SelfDescribingJson] = Nil,
timestamp: Option[Long] = None): Tracker = {
timestamp: Option[Timestamp] = None): Tracker = {

val payload = new Payload()

Expand Down Expand Up @@ -235,3 +253,19 @@ class Tracker(emitters: Seq[TEmitter], namespace: String, appId: String, encodeB
}
}

object Tracker {

/**
* Tag-type for timestamp, allowing to set ttm/dtm
*/
sealed trait Timestamp { val value: Long }
case class TrueTimestamp(value: Long) extends Timestamp
case class DeviceCreatedTimestamp(value: Long) extends Timestamp

/**
* Implicit conversion of Long values to [[DeviceCreatedTimestamp]] as default
*/
implicit def longToTimestamp(value: Long): Timestamp =
DeviceCreatedTimestamp(value)
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ object AsyncBatchEmitter {
* @param host collector host
* @param port collector port
* @param bufferSize quantity of events in batch request
* @param https should this use the https scheme
* @return emitter
*/
def createAndStart(host: String, port: Int = 80, bufferSize: Int = 50): AsyncBatchEmitter = {
val emitter = new AsyncBatchEmitter(host, port, bufferSize)
def createAndStart(host: String, port: Int = 80, bufferSize: Int = 50, https: Boolean = false): AsyncBatchEmitter = {
val emitter = new AsyncBatchEmitter(host, port, bufferSize, https = https)
emitter.startWorker()
emitter
}
Expand All @@ -43,8 +44,9 @@ object AsyncBatchEmitter {
* @param host collector host
* @param port collector port
* @param bufferSize quantity of events in a batch request
* @param https should this use the https scheme
*/
class AsyncBatchEmitter private(host: String, port: Int, bufferSize: Int) extends TEmitter {
class AsyncBatchEmitter private(host: String, port: Int, bufferSize: Int, https: Boolean = false) extends TEmitter {

val queue = new LinkedBlockingQueue[Seq[Map[String, String]]]()

Expand All @@ -58,7 +60,7 @@ class AsyncBatchEmitter private(host: String, port: Int, bufferSize: Int) extend
override def run {
while (true) {
val batch = queue.take()
RequestUtils.retryPostUntilSuccessful(host, batch, port, initialBackoffPeriod)
RequestUtils.retryPostUntilSuccessful(host, batch, port, initialBackoffPeriod, https = https)
}
}
}
Expand Down
Loading

0 comments on commit fde976a

Please sign in to comment.