diff --git a/src/it/docker/Dockerfile b/src/it/docker/Dockerfile index 53e12b2..7a850ec 100644 --- a/src/it/docker/Dockerfile +++ b/src/it/docker/Dockerfile @@ -1,10 +1,10 @@ -FROM java:8-alpine +FROM openjdk:8u342-slim-buster -RUN apk upgrade libssl1.0 --update-cache && \ - apk add wget ca-certificates bash +RUN apt-get update +RUN apt-get -y upgrade libssl1.0 && \ + apt-get -y install wget ca-certificates bash RUN wget -O /tmp/kairosdb.tar.gz \ -# https://github.com/kairosdb/kairosdb/releases/download/v1.1.3/kairosdb-1.1.3-1.tar.gz - https://github.com/kairosdb/kairosdb/releases/download/v1.2.0/kairosdb-1.2.0-1.tar.gz + https://github.com/kairosdb/kairosdb/releases/download/v1.3.0/kairosdb-1.3.0-1.tar.gz RUN mkdir -p /opt/ && \ cd /opt/ && \ diff --git a/src/it/docker/Makefile b/src/it/docker/Makefile index 6037960..a029361 100644 --- a/src/it/docker/Makefile +++ b/src/it/docker/Makefile @@ -2,8 +2,7 @@ # # build the KairosDB image -#VERSION=1.1.3-1 -VERSION=1.2.0-1 +VERSION=1.3.0-1 all: build diff --git a/src/it/resources/conf/auth/auth.props b/src/it/resources/conf/auth/auth.props new file mode 100644 index 0000000..b8d5038 --- /dev/null +++ b/src/it/resources/conf/auth/auth.props @@ -0,0 +1 @@ +test: test \ No newline at end of file diff --git a/src/it/resources/conf/auth/basicAuth.conf b/src/it/resources/conf/auth/basicAuth.conf new file mode 100644 index 0000000..440c79d --- /dev/null +++ b/src/it/resources/conf/auth/basicAuth.conf @@ -0,0 +1,6 @@ +basicAuth { + org.eclipse.jetty.jaas.spi.PropertyFileLoginModule required + debug="true" + //The line below should point to your .props file which lists your users and their passwords. + file="conf/auth/auth.props"; +}; \ No newline at end of file diff --git a/src/it/resources/conf/kairosdb.properties b/src/it/resources/conf/kairosdb.properties deleted file mode 100644 index f58f448..0000000 --- a/src/it/resources/conf/kairosdb.properties +++ /dev/null @@ -1,2 +0,0 @@ -kairosdb.jetty.basic_auth.user=test -kairosdb.jetty.basic_auth.password=test \ No newline at end of file diff --git a/src/it/scala/integration/AddAndQueryDataPointsIntegrationSpec.scala b/src/it/scala/integration/AddAndQueryDataPointsIntegrationSpec.scala index e838954..0d1d9af 100644 --- a/src/it/scala/integration/AddAndQueryDataPointsIntegrationSpec.scala +++ b/src/it/scala/integration/AddAndQueryDataPointsIntegrationSpec.scala @@ -123,8 +123,18 @@ class AddAndQueryDataPointsIntegrationSpec extends IntegrationSpec { (Instant.parse("1970-01-04T00:00:00Z"), KNumber(555) )) )))))) + case ("KairosDB 1.3.0-1.20210808220820", results) => + results must be(QueryResponse.Response(Seq(ResponseQuery(2, Seq( + Result("my.new.metric", Seq(GroupBy.GroupByType("number")), Seq(TagResult("aoeu", Seq("snth"))), Seq( + (Instant.parse("1970-01-01T00:00:00Z"), KNull), + (Instant.parse("1970-01-02T00:00:00Z"), KNumber(555)), + (Instant.parse("1970-01-03T00:00:00Z"), KNull), + (Instant.parse("1970-01-04T00:00:00Z"), KNumber(555)), + (Instant.parse("1970-01-05T00:00:00Z"), KNull) + ) + )))))) case other => - fail("Unknown kairos version") + fail(s"Unknown kairos version ${other._1}") } } } diff --git a/src/it/scala/integration/AuthSpec.scala b/src/it/scala/integration/AuthSpec.scala index 818a058..8c480bc 100644 --- a/src/it/scala/integration/AuthSpec.scala +++ b/src/it/scala/integration/AuthSpec.scala @@ -11,30 +11,25 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.collection.immutable.Seq class AuthSpec extends IntegrationSpec { - - // TODO enabling auth by providing env variables, when kairosdb 1.1.2 is released - // // same as KairosDB Main.java - // def toEnvVarName(propName: String) = { - // propName.toUpperCase().replace('.', '_') - // } - // - // override lazy val dockerEnv = Seq( - // toEnvVarName("kairosdb.jetty.basic_auth.user") + "=test", - // toEnvVarName("kairosdb.jetty.basic_auth.password") + "=test" - // ) - // enabling auth by providing a properties file override lazy val volumes = Seq( HostConfig.Bind - .from(Paths.get("src/it/resources/conf").toAbsolutePath.toString) - .to("/opt/kairosdb/conf") + .from(Paths.get("src/it/resources/conf/auth").toAbsolutePath.toString) + .to("/opt/kairosdb/conf/auth") .build() ) + override lazy val env: Seq[String] = Seq( + "JAVA_OPTS=-Djava.security.auth.login.config=/opt/kairosdb/conf/auth/basicAuth.conf -Dkairosdb.jetty.auth_module_name=basicAuth "+ + "-Dkairosdb.jetty.basic_auth.user=test " + + "-Dkairosdb.jetty.basic_auth.password=test" + ) + + "The health status" should { "fail without auth" in { val kairosDB = new KairosDB(wsClient, KairosDBConfig(port = kairosPort), global) - val res = kairosDB.healthStatus.failed.futureValue + val res = kairosDB.version.failed.futureValue res mustBe an[KairosDBResponseException] res must be(KairosDBResponseException(401, "Unauthorized", Seq.empty)) @@ -47,9 +42,9 @@ class AuthSpec extends IntegrationSpec { password = Some("test") ) val kairosDB = new KairosDB(wsClient, kairosConfig, global) - val res = kairosDB.healthStatus.futureValue + val res = kairosDB.version.futureValue - res must be(HealthStatusResults(Seq("JVM-Thread-Deadlock: OK", "Datastore-Query: OK"))) + res must startWith("KairosDB") } } } diff --git a/src/it/scala/integration/IntegrationSpec.scala b/src/it/scala/integration/IntegrationSpec.scala index 4f5a3ad..a9eae10 100644 --- a/src/it/scala/integration/IntegrationSpec.scala +++ b/src/it/scala/integration/IntegrationSpec.scala @@ -19,7 +19,7 @@ trait IntegrationSpec extends AnyWordSpec with Matchers with ScalaFutures with S lazy val env = Seq.empty[String] lazy val volumes = Seq.empty[HostConfig.Bind] - val kairosdbContainer = ContainerSpec("brunoballekens/kairosdb-scala-driver-it:1.2.0-1") + val kairosdbContainer = ContainerSpec("brunoballekens/kairosdb-scala-driver-it:1.3.0-1") .withEnv(env:_*) // broken with the spotify client .withVolumeBindings(volumes:_*) @@ -37,7 +37,7 @@ trait IntegrationSpec extends AnyWordSpec with Matchers with ScalaFutures with S .getOrElse(throw new IllegalStateException(s"Missing container mapped port for $DefaultKairosDbPort")) } - implicit val pc = PatienceConfig(Span(20, Seconds), Span(1, Second)) + implicit val pc = PatienceConfig(Span(2000, Seconds), Span(1, Second)) //override def dockerInitPatienceInterval = PatienceConfig(scaled(Span(30, Seconds)), scaled(Span(10, Millis))) override val managedContainers: ContainerGroup = ContainerGroup(Seq(kairosdbContainer.toContainer)) diff --git a/src/it/scala/integration/ListTagNamesIntegrationSpec.scala b/src/it/scala/integration/ListTagNamesIntegrationSpec.scala deleted file mode 100644 index ef2de67..0000000 --- a/src/it/scala/integration/ListTagNamesIntegrationSpec.scala +++ /dev/null @@ -1,27 +0,0 @@ -package integration - -import io.waylay.kairosdb.driver.KairosDB -import io.waylay.kairosdb.driver.models.KairosCompatibleType.KNumber -import io.waylay.kairosdb.driver.models.{DataPoint, KairosDBConfig, MetricName, Tag} - -import scala.concurrent.ExecutionContext.Implicits.global -import scala.collection.immutable.Seq - -class ListTagNamesIntegrationSpec extends IntegrationSpec { - - "Listing tag names" should { - - "only return tag of point that was just inserted" in { - - val kairosDB = new KairosDB(wsClient, KairosDBConfig(port = kairosPort), global) - val res = kairosDB.addDataPoint(DataPoint(MetricName("my.new.metric"), KNumber(555), tags = Seq(Tag("aoeu", "snth")))).flatMap { _ => - kairosDB.listTagNames - }.futureValue - - // these appear automatically after a while - val withSystemtagsRemoved = res.toSet -- Set("method", "host") - - withSystemtagsRemoved must be(Set("aoeu")) - } - } -} diff --git a/src/main/scala/io/waylay/kairosdb/driver/KairosDB.scala b/src/main/scala/io/waylay/kairosdb/driver/KairosDB.scala index bd17b52..152647c 100644 --- a/src/main/scala/io/waylay/kairosdb/driver/KairosDB.scala +++ b/src/main/scala/io/waylay/kairosdb/driver/KairosDB.scala @@ -51,26 +51,6 @@ class KairosDB(wsClient: StandaloneWSClient, config: KairosDBConfig, executionCo .map(_.map(MetricName)) } - def listTagNames: Future[Seq[String]] = { - wsClient - .url((url / "api" / "v1" / "tagnames").toString()) - .applyKairosDBAuth - .get() - .map { - wsRepsonseToResult(json => (json \ "results").validate[Seq[String]]) - } - } - - def listTagValues: Future[Seq[String]] = { - wsClient - .url((url / "api" / "v1" / "tagvalues").toString()) - .applyKairosDBAuth - .get() - .map( - wsRepsonseToResult(json => (json \ "results").validate[Seq[String]]) - ) - } - def healthStatus: Future[HealthStatusResults] = { wsClient .url((url / "api" / "v1" / "health" / "status").toString()) diff --git a/src/main/scala/io/waylay/kairosdb/driver/models/json/Formats.scala b/src/main/scala/io/waylay/kairosdb/driver/models/json/Formats.scala index e83e64a..188e1e1 100644 --- a/src/main/scala/io/waylay/kairosdb/driver/models/json/Formats.scala +++ b/src/main/scala/io/waylay/kairosdb/driver/models/json/Formats.scala @@ -266,7 +266,8 @@ object Formats { .getOrElse(Json.obj()) ++ rangeAgg.align .map { - case AlignStartTime => Json.obj("align_start_time" -> true) + // see https://github.com/kairosdb/kairosdb/issues/675 + case AlignStartTime => Json.obj("align_start_time" -> true, "align_sampling" -> false) case AlignSampling => Json.obj("align_sampling" -> true) } .getOrElse(Json.obj()) ++ @@ -288,7 +289,8 @@ object Formats { .getOrElse(Json.obj()) ++ percentileAgg.align .map { - case AlignStartTime => Json.obj("align_start_time" -> true) + // see https://github.com/kairosdb/kairosdb/issues/675 + case AlignStartTime => Json.obj("align_start_time" -> true, "align_sampling" -> false) case AlignSampling => Json.obj("align_sampling" -> true) } .getOrElse(Json.obj()) ++ diff --git a/src/test/scala/unit/AggregatorWritesSpec.scala b/src/test/scala/unit/AggregatorWritesSpec.scala index e732d7a..b4ccc95 100644 --- a/src/test/scala/unit/AggregatorWritesSpec.scala +++ b/src/test/scala/unit/AggregatorWritesSpec.scala @@ -59,6 +59,7 @@ class AggregatorWritesSpec extends Specification { Json.toJson(aggregator) should be equalTo Json.obj( "name" -> "avg", "align_start_time" -> true, + "align_sampling"->false, "sampling" -> Json.obj( "value" -> "1", "unit" -> "minutes" @@ -275,6 +276,7 @@ class AggregatorWritesSpec extends Specification { ), "start_time" -> 1469778777L, "align_start_time" -> true, + "align_sampling"->false, "time_zone" -> "Africa/Banjul" ) } diff --git a/src/test/scala/unit/ListTagNamesSpec.scala b/src/test/scala/unit/ListTagNamesSpec.scala deleted file mode 100644 index e42a02d..0000000 --- a/src/test/scala/unit/ListTagNamesSpec.scala +++ /dev/null @@ -1,34 +0,0 @@ -package unit - -import io.waylay.kairosdb.driver.KairosDB -import io.waylay.kairosdb.driver.models._ -import mockws.MockWS -import org.specs2.mutable.Specification -import play.api.libs.json.Json -import play.api.mvc.Results._ -import org.specs2.concurrent.ExecutionEnv -import org.specs2.matcher.{FutureMatchers, ResultMatchers} - -import scala.concurrent.duration._ - -class ListTagNamesSpec(implicit ee: ExecutionEnv) extends Specification with FutureMatchers with ResultMatchers with MockHelper { - - "KairosDB#listTagNames" should { - - "return the correct tag names" in { - val expected = Seq("mytag", "foo", "bar1") - - val mockWs = MockWS { - case ("GET", "http://localhost:8080/api/v1/tagnames") => Action { - Ok(Json.obj("results" -> expected)) - } - } - - val kairosDb = new KairosDB(StandaloneMockWs(mockWs), KairosDBConfig(), ee.ec) - - val r = kairosDb.listTagNames must be_==(expected).await(1, 3.seconds) - mockWs.close() - r - } - } -} diff --git a/src/test/scala/unit/ListTagValuesSpec.scala b/src/test/scala/unit/ListTagValuesSpec.scala deleted file mode 100644 index 653f170..0000000 --- a/src/test/scala/unit/ListTagValuesSpec.scala +++ /dev/null @@ -1,34 +0,0 @@ -package unit - -import io.waylay.kairosdb.driver.KairosDB -import io.waylay.kairosdb.driver.models._ -import mockws.MockWS -import org.specs2.mutable.Specification -import play.api.libs.json.Json -import play.api.mvc.Results._ -import org.specs2.concurrent.ExecutionEnv -import org.specs2.matcher.{FutureMatchers, ResultMatchers} - -import scala.concurrent.duration._ - -class ListTagValuesSpec(implicit ee: ExecutionEnv) extends Specification with FutureMatchers with ResultMatchers with MockHelper{ - - "KairosDB#listTagValues" should { - - "return the correct tag values" in { - val expected = Seq("mytag", "foo", "bar1") - - val mockWs = MockWS { - case ("GET", "http://localhost:8080/api/v1/tagvalues") => Action { - Ok(Json.obj("results" -> expected)) - } - } - - val kairosDb = new KairosDB(StandaloneMockWs(mockWs), KairosDBConfig(), ee.ec) - - val r = kairosDb.listTagValues must be_==(expected).await(1, 3.seconds) - mockWs.close() - r - } - } -} diff --git a/version.sbt b/version.sbt index 9f42197..e004bdd 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -ThisBuild / version := "5.0.1-SNAPSHOT" +ThisBuild / version := "6.0.0-SNAPSHOT"