Skip to content

Commit

Permalink
Use collector 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Apr 8, 2024
1 parent 6745f37 commit 27c8e06
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- name: Publish collector locally
run: |
git clone --branch 3.1.0_cross_scala_2.12 --depth 1 https://github.com/snowplow/stream-collector.git
git clone --branch 3.2.0 --depth 1 https://github.com/snowplow/stream-collector.git
cd stream-collector
sbt +publishLocal
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- name: Publish collector locally
run: |
git clone --branch 3.1.0_cross_scala_2.12 --depth 1 https://github.com/snowplow/stream-collector.git
git clone --branch 3.2.0 --depth 1 https://github.com/snowplow/stream-collector.git
cd stream-collector
sbt +publishLocal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Assuming [Git][git] and [sbt][sbt]:
git clone git@github.com:snowplow-incubator/snowplow-micro.git
cd snowplow-micro
git clone --branch 2.8.1 --depth 1 git@github.com:snowplow/stream-collector.git
git clone --branch 3.2.0 --depth 1 git@github.com:snowplow/stream-collector.git
cd stream-collector
sbt publishLocal && cd ..
sbt +publishLocal && cd ..
sbt test
```
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Dependencies {

object V {
// Snowplow
val snowplowStreamCollector = "3.1.3-rc1"
val snowplowStreamCollector = "3.2.0"
val snowplowCommonEnrich = "4.1.0"
val http4sCirce = "0.23.23"

Expand Down
14 changes: 6 additions & 8 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
logLevel := Level.Warn

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.0.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.8.2")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.3")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.2")
addSbtPlugin("com.snowplowanalytics" % "sbt-snowplow-release" % "0.3.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.0.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import com.avast.datadog4s.api.Tag
import com.avast.datadog4s.extension.http4s.DatadogMetricsOps
import com.avast.datadog4s.{StatsDMetricFactory, StatsDMetricFactoryConfig}
import com.snowplowanalytics.snowplow.collector.core.{Config => CollectorConfig}
import com.snowplowanalytics.snowplow.micro.Configuration.MicroConfig
import com.snowplowanalytics.snowplow.micro.Configuration.{MicroConfig, SinkConfig}
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.headers.`Strict-Transport-Security`
import org.http4s.server.Server
import org.http4s.server.middleware.{HSTS, Metrics}
import org.http4s.server.middleware.{HSTS, Metrics, Timeout, Logger => LoggerMiddleware}
import org.http4s.{HttpApp, HttpRoutes}
import org.typelevel.ci.CIString
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger

Expand All @@ -44,23 +45,44 @@ object MicroHttpServer {
} yield ()

private def buildHTTPServer(routes: HttpRoutes[IO], config: MicroConfig): Resource[IO, Server] =
builder(routes, config)
builder(routes, config.collector)
.bindSocketAddress(new InetSocketAddress(config.collector.port))
.resource

private def buildHTTPSServer(routes: HttpRoutes[IO], config: MicroConfig, sslContext: SSLContext): Resource[IO, Server] =
builder(routes, config)
builder(routes, config.collector)
.bindSocketAddress(new InetSocketAddress(config.collector.ssl.port))
.withSslContext(sslContext)
.resource

private def builder(routes: HttpRoutes[IO], config: MicroConfig): BlazeServerBuilder[IO] = {
private def builder(routes: HttpRoutes[IO], config: CollectorConfig[SinkConfig]): BlazeServerBuilder[IO] = {
BlazeServerBuilder[IO]
.withHttpApp(hstsMiddleware(config.collector.hsts, routes.orNotFound))
.withIdleTimeout(config.collector.networking.idleTimeout)
.withMaxConnections(config.collector.networking.maxConnections)
.withHttpApp(
loggerMiddleware(timeoutMiddleware(hstsMiddleware(config.hsts, routes.orNotFound), config.networking), config.debug.http)
)
.withIdleTimeout(config.networking.idleTimeout)
.withMaxConnections(config.networking.maxConnections)
.withResponseHeaderTimeout(config.networking.responseHeaderTimeout)
.withLengthLimits(
maxRequestLineLen = config.networking.maxRequestLineLength,
maxHeadersLen = config.networking.maxHeadersLength
)
}

private def loggerMiddleware(routes: HttpApp[IO], config: CollectorConfig.Debug.Http): HttpApp[IO] =
if (config.enable) {
LoggerMiddleware.httpApp[IO](
logHeaders = config.logHeaders,
logBody = config.logBody,
redactHeadersWhen = config.redactHeaders.map(CIString(_)).contains(_),
logAction = Some((msg: String) => Logger[IO].debug(msg))
)(routes)
} else routes

private def timeoutMiddleware(routes: HttpApp[IO], networking: CollectorConfig.Networking): HttpApp[IO] =
Timeout.httpApp[IO](timeout = networking.responseHeaderTimeout)(routes)


private def createMetricsMiddleware(routes: HttpRoutes[IO],
metricsCollectorConfig: CollectorConfig.Metrics): Resource[IO, HttpRoutes[IO]] =
if (metricsCollectorConfig.statsd.enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ object Run {
config.collector.enableDefaultRedirect,
config.collector.rootResponse.enabled,
config.collector.crossDomain.enabled,
config.collector.networking.bodyReadTimeout,
collectorService
).value

Expand Down

0 comments on commit 27c8e06

Please sign in to comment.