-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
144 additions
and
89 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
19 changes: 19 additions & 0 deletions
19
...s/src/main/scala/com.snowplowanalytics.snowplow.collectors.scalastream/CollectorApp.scala
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,19 @@ | ||
package com.snowplowanalytics.snowplow.collectors.scalastream | ||
|
||
import cats.effect.{ExitCode, IO} | ||
import com.comcast.ip4s.IpLiteralSyntax | ||
import org.http4s.ember.server.EmberServerBuilder | ||
|
||
object CollectorApp { | ||
|
||
def run(): IO[ExitCode] = | ||
buildHttpServer().use(_ => IO.never).as(ExitCode.Success) | ||
|
||
private def buildHttpServer() = | ||
EmberServerBuilder | ||
.default[IO] | ||
.withHost(ipv4"0.0.0.0") | ||
.withPort(port"8080") | ||
.withHttpApp(new CollectorRoutes[IO].value) | ||
.build | ||
} |
15 changes: 15 additions & 0 deletions
15
...rc/main/scala/com.snowplowanalytics.snowplow.collectors.scalastream/CollectorRoutes.scala
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,15 @@ | ||
package com.snowplowanalytics.snowplow.collectors.scalastream | ||
|
||
import cats.effect.Sync | ||
import org.http4s.{HttpApp, HttpRoutes} | ||
import org.http4s.dsl.Http4sDsl | ||
|
||
class CollectorRoutes[F[_]: Sync]() extends Http4sDsl[F] { | ||
|
||
lazy val value: HttpApp[F] = HttpRoutes | ||
.of[F] { | ||
case GET -> Root / "health" => | ||
Ok("OK") | ||
} | ||
.orNotFound | ||
} |
21 changes: 21 additions & 0 deletions
21
...est/scala/com.snowplowanalytics.snowplow.collectors.scalastream/CollectorRoutesSpec.scala
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,21 @@ | ||
package com.snowplowanalytics.snowplow.collectors.scalastream | ||
|
||
import cats.effect.IO | ||
import cats.effect.unsafe.implicits.global | ||
import org.http4s.implicits.http4sLiteralsSyntax | ||
import org.http4s.{Method, Request, Status} | ||
import org.specs2.mutable.Specification | ||
|
||
class CollectorRoutesSpec extends Specification { | ||
|
||
"Health endpoint" should { | ||
"return OK always because collector always works" in { | ||
val request = Request[IO](method = Method.GET, uri = uri"/health") | ||
val response = new CollectorRoutes[IO].value.run(request).unsafeRunSync() | ||
|
||
response.status must beEqualTo(Status.Ok) | ||
response.as[String].unsafeRunSync() must beEqualTo("OK") | ||
} | ||
} | ||
|
||
} |
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
80 changes: 40 additions & 40 deletions
80
...c/main/scala/com.snowplowanalytics.snowplow.collectors.scalastream/sinks/StdoutSink.scala
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,40 +1,40 @@ | ||
/* | ||
* Copyright (c) 2013-2022 Snowplow Analytics Ltd. | ||
* All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache | ||
* License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed | ||
* on an "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. | ||
*/ | ||
package com.snowplowanalytics.snowplow.collectors.scalastream | ||
package sinks | ||
|
||
import org.apache.commons.codec.binary.Base64 | ||
|
||
class StdoutSink(val maxBytes: Int, streamName: String) extends Sink { | ||
|
||
// Print a Base64-encoded event. | ||
override def storeRawEvents(events: List[Array[Byte]], key: String): Unit = | ||
streamName match { | ||
case "out" => | ||
events.foreach { e => | ||
println(Base64.encodeBase64String(e)) | ||
} | ||
case "err" => | ||
events.foreach { e => | ||
Console.err.println(Base64.encodeBase64String(e)) | ||
} | ||
} | ||
|
||
override def shutdown(): Unit = () | ||
} | ||
///* | ||
// * Copyright (c) 2013-2022 Snowplow Analytics Ltd. | ||
// * All rights reserved. | ||
// * | ||
// * This program is licensed to you under the Apache License Version 2.0, | ||
// * and you may not use this file except in compliance with the Apache | ||
// * License Version 2.0. | ||
// * You may obtain a copy of the Apache License Version 2.0 at | ||
// * http://www.apache.org/licenses/LICENSE-2.0. | ||
// * | ||
// * Unless required by applicable law or agreed to in writing, | ||
// * software distributed under the Apache License Version 2.0 is distributed | ||
// * on an "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. | ||
// */ | ||
//package com.snowplowanalytics.snowplow.collectors.scalastream | ||
//package sinks | ||
// | ||
//import org.apache.commons.codec.binary.Base64 | ||
// | ||
//class StdoutSink(val maxBytes: Int, streamName: String) extends Sink { | ||
// | ||
// // Print a Base64-encoded event. | ||
// override def storeRawEvents(events: List[Array[Byte]], key: String): Unit = | ||
// streamName match { | ||
// case "out" => | ||
// events.foreach { e => | ||
// println(Base64.encodeBase64String(e)) | ||
// } | ||
// case "err" => | ||
// events.foreach { e => | ||
// Console.err.println(Base64.encodeBase64String(e)) | ||
// } | ||
// } | ||
// | ||
// override def shutdown(): Unit = () | ||
//} |
50 changes: 25 additions & 25 deletions
50
...c/test/scala/com.snowplowanalytics.snowplow.collectors.scalastream/StdoutConfigSpec.scala
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,25 +1,25 @@ | ||
/** | ||
* Copyright (c) 2014-2022 Snowplow Analytics Ltd. | ||
* All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache | ||
* License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed | ||
* on an "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. | ||
*/ | ||
package com.snowplowanalytics.snowplow.collectors.scalastream | ||
|
||
import com.snowplowanalytics.snowplow.collectors.scalastream.config.ConfigSpec | ||
|
||
class StdoutConfigSpec extends ConfigSpec { | ||
makeConfigTest("stdout", "", "") | ||
} | ||
///** | ||
// * Copyright (c) 2014-2022 Snowplow Analytics Ltd. | ||
// * All rights reserved. | ||
// * | ||
// * This program is licensed to you under the Apache License Version 2.0, | ||
// * and you may not use this file except in compliance with the Apache | ||
// * License Version 2.0. | ||
// * You may obtain a copy of the Apache License Version 2.0 at | ||
// * http://www.apache.org/licenses/LICENSE-2.0. | ||
// * | ||
// * Unless required by applicable law or agreed to in writing, | ||
// * software distributed under the Apache License Version 2.0 is distributed | ||
// * on an "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. | ||
// */ | ||
//package com.snowplowanalytics.snowplow.collectors.scalastream | ||
// | ||
//import com.snowplowanalytics.snowplow.collectors.scalastream.config.ConfigSpec | ||
// | ||
//class StdoutConfigSpec extends ConfigSpec { | ||
// makeConfigTest("stdout", "", "") | ||
//} |