From 503fbc4a9a6c02482daa4439a98009af9da1e2a1 Mon Sep 17 00:00:00 2001 From: Benjamin Benoist Date: Thu, 17 Aug 2023 17:33:24 +0200 Subject: [PATCH 1/2] Fix config loading --- .../ConfigParser.scala | 2 +- http4s/src/test/resources/test-config.hocon | 18 +++++++++ .../ConfigParserSpec.scala | 40 +++++++++++++++++++ .../TestUtils.scala | 2 +- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 http4s/src/test/resources/test-config.hocon create mode 100644 http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParserSpec.scala diff --git a/http4s/src/main/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParser.scala b/http4s/src/main/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParser.scala index c2960ba8d..2c12b7b09 100644 --- a/http4s/src/main/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParser.scala +++ b/http4s/src/main/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParser.scala @@ -67,7 +67,7 @@ object ConfigParser { } private def loadAll(config: TypesafeConfig): TypesafeConfig = - namespaced(ConfigFactory.load(namespaced(config.withFallback(namespaced(ConfigFactory.load()))))) + namespaced(config.withFallback(namespaced(ConfigFactory.load()))) private def namespaced(config: TypesafeConfig): TypesafeConfig = { val namespace = "collector" diff --git a/http4s/src/test/resources/test-config.hocon b/http4s/src/test/resources/test-config.hocon new file mode 100644 index 000000000..71202d62f --- /dev/null +++ b/http4s/src/test/resources/test-config.hocon @@ -0,0 +1,18 @@ +collector { + interface = "0.0.0.0" + port = 8080 + + streams { + good = "good" + bad = "bad" + + sink { + foo = "hello" + bar = "world" + } + } + + ssl { + enable = true + } +} diff --git a/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParserSpec.scala b/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParserSpec.scala new file mode 100644 index 000000000..8106ab345 --- /dev/null +++ b/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParserSpec.scala @@ -0,0 +1,40 @@ +package com.snowplowanalytics.snowplow.collector.core + +import java.nio.file.Paths + +import org.specs2.mutable.Specification + +import cats.effect.IO + +import cats.effect.testing.specs2.CatsEffect + +import io.circe.generic.semiauto._ + +class ConfigParserSpec extends Specification with CatsEffect { + + "Loading the configuration" should { + "use reference.conf and the hocon specified in the path" in { + case class SinkConfig(foo: String, bar: String) + implicit val decoder = deriveDecoder[SinkConfig] + + val path = Paths.get(getClass.getResource(("/test-config.hocon")).toURI()) + + val expectedStreams = Config.Streams[SinkConfig]( + "good", + "bad", + TestUtils.testConfig.streams.useIpAddressAsPartitionKey, + SinkConfig("hello", "world"), + TestUtils.testConfig.streams.buffer + ) + val expected = TestUtils + .testConfig + .copy[SinkConfig]( + paths = Map.empty[String, String], + streams = expectedStreams, + ssl = TestUtils.testConfig.ssl.copy(enable = true) + ) + + ConfigParser.fromPath[IO, SinkConfig](Some(path)).value.map(_ should beRight(expected)) + } + } +} diff --git a/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/TestUtils.scala b/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/TestUtils.scala index 334229b0c..3937b2580 100644 --- a/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/TestUtils.scala +++ b/http4s/src/test/scala/com.snowplowanalytics.snowplow.collector.core/TestUtils.scala @@ -102,6 +102,6 @@ object TestUtils { ), enableDefaultRedirect = false, redirectDomains = Set.empty[String], - preTerminationPeriod = 5.minutes + preTerminationPeriod = 10.seconds ) } From bf461b53e5bd5d20b4aad07164078c1097b146e8 Mon Sep 17 00:00:00 2001 From: Ian Streeter Date: Sun, 20 Aug 2023 20:25:56 +0100 Subject: [PATCH 2/2] Fix to fix config loading --- http4s/src/main/resources/reference.conf | 2 +- .../ConfigParser.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/http4s/src/main/resources/reference.conf b/http4s/src/main/resources/reference.conf index b4c83f3f9..e6acbc7ef 100644 --- a/http4s/src/main/resources/reference.conf +++ b/http4s/src/main/resources/reference.conf @@ -1,4 +1,4 @@ -collector { +{ paths {} p3p { diff --git a/http4s/src/main/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParser.scala b/http4s/src/main/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParser.scala index 2c12b7b09..c2960ba8d 100644 --- a/http4s/src/main/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParser.scala +++ b/http4s/src/main/scala/com.snowplowanalytics.snowplow.collector.core/ConfigParser.scala @@ -67,7 +67,7 @@ object ConfigParser { } private def loadAll(config: TypesafeConfig): TypesafeConfig = - namespaced(config.withFallback(namespaced(ConfigFactory.load()))) + namespaced(ConfigFactory.load(namespaced(config.withFallback(namespaced(ConfigFactory.load()))))) private def namespaced(config: TypesafeConfig): TypesafeConfig = { val namespace = "collector"