Skip to content

Commit e67e7a6

Browse files
committed
Fix everything
1 parent 99ad846 commit e67e7a6

File tree

35 files changed

+145
-113
lines changed

35 files changed

+145
-113
lines changed

modules/cloudutils/aws/src/main/scala/com/snowplowanalytics/snowplow/enrich/aws/S3Client.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object S3Client {
3131

3232
def mk[F[_]: Async]: Resource[F, Client[F]] =
3333
for {
34-
s3Client <- Resource.fromAutoCloseable(Sync[F].delay(S3AsyncClient.builder().region(getRegion).build()))
34+
s3Client <- Resource.fromAutoCloseable(Sync[F].delay(S3AsyncClient.builder().region(getRegion()).build()))
3535
store <- Resource.eval(S3Store.builder[F](s3Client).build.toEither.leftMap(_.head).pure[F].rethrow)
3636
} yield new Client[F] {
3737
def canDownload(uri: URI): Boolean =

modules/common-fs2/src/it/scala/com/snowplowanalytics/snowplow/enrich/common/fs2/test/CollectorPayloadGen.scala

+52-22
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.apache.thrift.TSerializer
2727

2828
import java.util.Base64
2929

30-
import com.snowplowanalytics.iglu.core.{ SelfDescribingData, SchemaKey, SchemaVer }
30+
import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer, SelfDescribingData}
3131
import com.snowplowanalytics.iglu.core.circe.CirceIgluCodecs._
3232

3333
import com.snowplowanalytics.snowplow.enrich.common.loaders.CollectorPayload
@@ -40,7 +40,9 @@ object CollectorPayloadGen {
4040
generateRaw(nbGoodEvents, nbBadRows).map(_.toThrift).map(new TSerializer().serialize)
4141

4242
def generateRaw[F[_]: Sync](nbGoodEvents: Long, nbBadRows: Long): Stream[F, CollectorPayload] =
43-
Stream.repeatEval(runGen(collectorPayloadGen(true))).take(nbGoodEvents) ++ Stream.repeatEval(runGen(collectorPayloadGen(false))).take(nbBadRows)
43+
Stream.repeatEval(runGen(collectorPayloadGen(true))).take(nbGoodEvents) ++ Stream
44+
.repeatEval(runGen(collectorPayloadGen(false)))
45+
.take(nbBadRows)
4446

4547
private def collectorPayloadGen(valid: Boolean): Gen[CollectorPayload] =
4648
for {
@@ -74,46 +76,74 @@ object CollectorPayloadGen {
7476
aid <- Gen.const("enrich-kinesis-integration-tests").withKey("aid")
7577
e <- Gen.const("ue").withKey("e")
7678
tv <- Gen.oneOf("scala-tracker_1.0.0", "js_2.0.0", "go_1.2.3").withKey("tv")
77-
uePx <-
78-
if(valid)
79-
ueGen.map(_.toString).map(str => base64Encoder.encodeToString(str.getBytes)).withKey("ue_px")
80-
else
81-
Gen.const("foo").withKey("ue_px")
79+
uePx <- if (valid)
80+
ueGen.map(_.toString).map(str => base64Encoder.encodeToString(str.getBytes)).withKey("ue_px")
81+
else
82+
Gen.const("foo").withKey("ue_px")
8283
} yield SelfDescribingData(
83-
SchemaKey("com.snowplowanalytics.snowplow", "payload_data", "jsonschema", SchemaVer.Full(1,0,4)),
84-
List(asObject(List(p, aid, e, uePx, tv))).asJson
84+
SchemaKey("com.snowplowanalytics.snowplow", "payload_data", "jsonschema", SchemaVer.Full(1, 0, 4)),
85+
List(asObject(List(p, aid, e, uePx, tv))).asJson
8586
).asJson.toString
8687

8788
private def ueGen =
8889
for {
8990
sdj <- Gen.oneOf(changeFormGen, clientSessionGen)
9091
} yield SelfDescribingData(
91-
SchemaKey("com.snowplowanalytics.snowplow", "unstruct_event", "jsonschema", SchemaVer.Full(1,0,0)),
92+
SchemaKey("com.snowplowanalytics.snowplow", "unstruct_event", "jsonschema", SchemaVer.Full(1, 0, 0)),
9293
sdj.asJson
9394
).asJson
9495

95-
9696
private def changeFormGen =
9797
for {
98-
formId <- strGen(32, Gen.alphaNumChar).withKey("formId")
98+
formId <- strGen(32, Gen.alphaNumChar).withKey("formId")
9999
elementId <- strGen(32, Gen.alphaNumChar).withKey("elementId")
100-
nodeName <- Gen.oneOf(List("INPUT", "TEXTAREA", "SELECT")).withKey("nodeName")
101-
`type` <- Gen.option(Gen.oneOf(List("button", "checkbox", "color", "date", "datetime", "datetime-local", "email", "file", "hidden", "image", "month", "number", "password", "radio", "range", "reset", "search", "submit", "tel", "text", "time", "url", "week"))).withKeyOpt("type")
102-
value <- Gen.option(strGen(16, Gen.alphaNumChar)).withKeyNull("value")
100+
nodeName <- Gen.oneOf(List("INPUT", "TEXTAREA", "SELECT")).withKey("nodeName")
101+
`type` <- Gen
102+
.option(
103+
Gen.oneOf(
104+
List(
105+
"button",
106+
"checkbox",
107+
"color",
108+
"date",
109+
"datetime",
110+
"datetime-local",
111+
"email",
112+
"file",
113+
"hidden",
114+
"image",
115+
"month",
116+
"number",
117+
"password",
118+
"radio",
119+
"range",
120+
"reset",
121+
"search",
122+
"submit",
123+
"tel",
124+
"text",
125+
"time",
126+
"url",
127+
"week"
128+
)
129+
)
130+
)
131+
.withKeyOpt("type")
132+
value <- Gen.option(strGen(16, Gen.alphaNumChar)).withKeyNull("value")
103133
} yield SelfDescribingData(
104-
SchemaKey("com.snowplowanalytics.snowplow", "change_form", "jsonschema", SchemaVer.Full(1,0,0)),
134+
SchemaKey("com.snowplowanalytics.snowplow", "change_form", "jsonschema", SchemaVer.Full(1, 0, 0)),
105135
asObject(List(formId, elementId, nodeName, `type`, value))
106136
)
107137

108138
private def clientSessionGen =
109139
for {
110-
userId <- Gen.uuid.withKey("userId")
111-
sessionId <- Gen.uuid.withKey("sessionId")
112-
sessionIndex <- Gen.choose(0, 2147483647).withKey("sessionIndex")
140+
userId <- Gen.uuid.withKey("userId")
141+
sessionId <- Gen.uuid.withKey("sessionId")
142+
sessionIndex <- Gen.choose(0, 2147483647).withKey("sessionIndex")
113143
previousSessionId <- Gen.option(Gen.uuid).withKeyNull("previousSessionId")
114-
storageMechanism <- Gen.oneOf(List("SQLITE", "COOKIE_1", "COOKIE_3", "LOCAL_STORAGE", "FLASH_LSO")).withKey("storageMechanism")
144+
storageMechanism <- Gen.oneOf(List("SQLITE", "COOKIE_1", "COOKIE_3", "LOCAL_STORAGE", "FLASH_LSO")).withKey("storageMechanism")
115145
} yield SelfDescribingData(
116-
SchemaKey("com.snowplowanalytics.snowplow", "client_session", "jsonschema", SchemaVer.Full(1,0,1)),
146+
SchemaKey("com.snowplowanalytics.snowplow", "client_session", "jsonschema", SchemaVer.Full(1, 0, 1)),
117147
asObject(List(userId, sessionId, sessionIndex, previousSessionId, storageMechanism))
118148
)
119149

@@ -159,7 +189,7 @@ object CollectorPayloadGen {
159189

160190
implicit class GenOps[A](gen: Gen[A]) {
161191
def withKey[B](name: String)(implicit enc: Encoder[A]): Gen[Option[(String, Json)]] =
162-
gen.map { a => Some((name -> a.asJson)) }
192+
gen.map(a => Some((name -> a.asJson)))
163193
}
164194

165195
implicit class GenOptOps[A](gen: Gen[Option[A]]) {

modules/common-fs2/src/main/scala/com/snowplowanalytics/snowplow/enrich/common/fs2/Assets.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import java.net.URI
1414

1515
import scala.concurrent.ExecutionContext
1616
import scala.concurrent.duration._
17-
import scala.util.control.NonFatal
1817

1918
import cats.Applicative
2019
import cats.implicits._
@@ -259,8 +258,7 @@ object Assets {
259258
def worthRetrying[F[_]: Applicative](e: Throwable): F[Boolean] =
260259
e match {
261260
case _: Clients.RetryableFailure => Applicative[F].pure(true)
262-
case _: IllegalArgumentException => Applicative[F].pure(false)
263-
case NonFatal(_) => Applicative[F].pure(false)
261+
case _ => Applicative[F].pure(false)
264262
}
265263

266264
def onError[F[_]: Sync](error: Throwable, details: RetryDetails): F[Unit] =

modules/common-fs2/src/main/scala/com/snowplowanalytics/snowplow/enrich/common/fs2/Enrich.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ object Enrich {
152152
payload.fold(_.asJson.noSpaces, _.map(_.toBadRowPayload.asJson.noSpaces).getOrElse("None"))
153153

154154
/** Log an error, turn the problematic `CollectorPayload` into `BadRow` and notify Sentry if configured */
155-
def sendToSentry[F[_]: Sync: Clock](
155+
def sendToSentry[F[_]: Sync](
156156
original: Array[Byte],
157157
sentry: Option[SentryClient],
158158
processor: Processor,

modules/common-fs2/src/main/scala/com/snowplowanalytics/snowplow/enrich/common/fs2/Run.scala

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import cats.implicits._
1818

1919
import fs2.Stream
2020

21-
import scala.concurrent.ExecutionContext
22-
2321
import cats.effect.kernel.{Async, Resource, Sync}
2422
import cats.effect.ExitCode
2523

modules/common-fs2/src/main/scala/com/snowplowanalytics/snowplow/enrich/common/fs2/io/FileSystem.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package com.snowplowanalytics.snowplow.enrich.common.fs2.io
1212

1313
import java.nio.file.{Files, Path}
1414

15-
import scala.collection.JavaConverters._
15+
import scala.jdk.CollectionConverters._
1616
import scala.io.{Source => SSource}
1717

1818
import cats.data.EitherT

modules/common-fs2/src/test/scala/com/snowplowanalytics/snowplow/enrich/common/fs2/blackbox/BlackBoxTesting.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
package com.snowplowanalytics.snowplow.enrich.common.fs2.blackbox
1212

13-
import scala.collection.JavaConverters._
13+
import scala.jdk.CollectionConverters._
1414

1515
import org.specs2.mutable.Specification
1616

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/adapters/registry/Adapter.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ trait Adapter {
165165
formatter: FormatterFunc,
166166
platform: String
167167
): RawEventParameters = {
168-
val params = formatter(parameters - ("nuid", "aid", "cv", "p"))
168+
val params = formatter(parameters -- List("nuid", "aid", "cv", "p"))
169169
val json = toUnstructEvent(SelfDescribingData(schema, params)).noSpaces
170170
buildUnstructEventParams(tracker, platform, parameters, json)
171171
}
@@ -182,7 +182,7 @@ trait Adapter {
182182
"p" -> parameters.getOrElse("p", Option(platform)), // Required field
183183
"ue_pr" -> Option(json)
184184
) ++
185-
parameters.filterKeys(AcceptedQueryParameters)
185+
parameters.view.filterKeys(AcceptedQueryParameters).toMap
186186

187187
/**
188188
* Creates a Snowplow unstructured event by nesting the provided JValue in a self-describing
@@ -375,7 +375,7 @@ trait Adapter {
375375
*/
376376
private[registry] def camelCase(snakeOrDash: String) =
377377
snakeCaseOrDashTokenCapturingRegex.replaceAllIn(
378-
Character.toLowerCase(snakeOrDash.charAt(0)) + snakeOrDash.substring(1),
378+
Character.toString(Character.toLowerCase(snakeOrDash.charAt(0))) + snakeOrDash.substring(1),
379379
m => m.group(1).capitalize
380380
)
381381

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/adapters/registry/GoogleAnalyticsAdapter.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package com.snowplowanalytics.snowplow.enrich.common.adapters.registry
1212

1313
import scala.annotation.tailrec
1414

15-
import cats.{Applicative, Functor, Monad}
15+
import cats.{Applicative, Monad}
1616
import cats.data.{NonEmptyList, ValidatedNel}
1717
import cats.implicits._
1818

@@ -531,7 +531,7 @@ case class GoogleAnalyticsAdapter(schemas: GoogleAnalyticsSchemas) extends Adapt
531531
)
532532
schemaVal = lookupSchema(
533533
hitType.some,
534-
unstructEventData.mapValues(_.schemaKey)
534+
unstructEventData.view.mapValues(_.schemaKey).toMap
535535
).toValidatedNel
536536
simpleContexts = buildContexts(params, contextData, fieldToSchemaMap)
537537
compositeContexts = buildCompositeContexts(
@@ -675,7 +675,9 @@ case class GoogleAnalyticsAdapter(schemas: GoogleAnalyticsSchemas) extends Adapt
675675
// composite params have digits in their key
676676
composite <- originalParams
677677
.collect { case (k, Some(v)) => (k, v) }
678+
.view
678679
.filterKeys(k => k.exists(_.isDigit))
680+
.toMap
679681
.asRight
680682
brokenDown <- composite.toList.sorted.map {
681683
case (k, v) => breakDownCompField(k, v, indicator)
@@ -684,7 +686,9 @@ case class GoogleAnalyticsAdapter(schemas: GoogleAnalyticsSchemas) extends Adapt
684686
// we additionally make sure we have a rectangular dataset
685687
grouped = (partitioned._2 ++ removeConsecutiveDuplicates(partitioned._1)).flatten
686688
.groupBy(_._1)
689+
.view
687690
.mapValues(_.map(_._2))
691+
.toMap
688692
translated <- {
689693
val m = grouped
690694
.foldLeft(
@@ -821,7 +825,7 @@ case class GoogleAnalyticsAdapter(schemas: GoogleAnalyticsSchemas) extends Adapt
821825
case head => head :: transpose(l.collect { case _ :: tail => tail })
822826
}
823827

824-
private def traverseMap[G[_]: Functor: Applicative, K, V](m: Map[K, G[V]]): G[Map[K, V]] =
828+
private def traverseMap[G[_]: Applicative, K, V](m: Map[K, G[V]]): G[Map[K, V]] =
825829
m.toList
826830
.traverse {
827831
case (name, vnel) =>

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/adapters/registry/OlarkAdapter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ package com.snowplowanalytics.snowplow.enrich.common.adapters.registry
1313
import java.net.URI
1414
import java.nio.charset.StandardCharsets.UTF_8
1515

16-
import scala.collection.JavaConverters._
16+
import scala.jdk.CollectionConverters._
1717
import scala.util.{Try, Success => TS, Failure => TF}
1818

1919
import cats.Monad

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/adapters/registry/StatusGatorAdapter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ package com.snowplowanalytics.snowplow.enrich.common.adapters.registry
1313
import java.net.URI
1414
import java.nio.charset.StandardCharsets.UTF_8
1515

16-
import scala.collection.JavaConverters._
16+
import scala.jdk.CollectionConverters._
1717
import scala.util.{Try, Success => TS, Failure => TF}
1818

1919
import cats.Monad

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/adapters/registry/UnbounceAdapter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ package com.snowplowanalytics.snowplow.enrich.common.adapters.registry
1313
import java.net.URI
1414
import java.nio.charset.StandardCharsets.UTF_8
1515

16-
import scala.collection.JavaConverters._
16+
import scala.jdk.CollectionConverters._
1717
import scala.util.{Try, Success => TS, Failure => TF}
1818

1919
import cats.Monad

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/adapters/registry/snowplow/RedirectAdapter.scala

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ object RedirectAdapter extends Adapter {
9898
case (None, Some(Some(co))) if co == "" => newCo.asRight
9999
case (None, Some(Some(co))) => addToExistingCo(json, co).map(str => Map("co" -> str))
100100
case (Some(Some(cx)), _) => addToExistingCx(json, cx).map(str => Map("cx" -> str))
101+
case other => throw new IllegalStateException(s"Illegal state: $other")
101102
}
102103
} else
103104
// Add URI redirect as an unstructured event

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/EnrichmentManager.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ object EnrichmentManager {
287287
def setCollectorTstamp(event: EnrichedEvent, timestamp: Option[DateTime]): Either[FailureDetails.EnrichmentFailure, Unit] =
288288
EE.formatCollectorTstamp(timestamp).map { t =>
289289
event.collector_tstamp = t
290-
().asRight
290+
()
291291
}
292292

293293
def setUseragent(

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/AnonIpEnrichment.scala

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ final case class AnonIpEnrichment(ipv4Octets: AnonIPv4Octets.AnonIPv4Octets, ipv
150150
.map {
151151
case _: Inet4Address => anonymizeIpV4(ip)
152152
case ipv6: Inet6Address => anonymizeIpV6(ipv6.getHostAddress)
153+
case _ => throw new IllegalStateException(s"Illegal state")
153154
}
154155
.getOrElse(tryAnonymizingInvalidIp(ip))
155156
}.orNull

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/YauaaEnrichment.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
package com.snowplowanalytics.snowplow.enrich.common.enrichments.registry
1212

13-
import scala.collection.JavaConverters._
13+
import scala.jdk.CollectionConverters._
1414

1515
import cats.data.ValidatedNel
1616
import cats.syntax.either._
@@ -64,7 +64,7 @@ object YauaaEnrichment extends ParseableEnrichment {
6464
s match {
6565
case _ if s.isEmpty => s
6666
case _ if s.length == 1 => s.toLowerCase
67-
case _ => s.charAt(0).toLower + s.substring(1)
67+
case _ => Character.toString(s.charAt(0).toLower) + s.substring(1)
6868
}
6969
}
7070

@@ -112,7 +112,9 @@ final case class YauaaEnrichment(cacheSize: Option[Int]) extends Enrichment {
112112
parsedUA.getAvailableFieldNamesSorted.asScala
113113
.map(field => decapitalize(field) -> parsedUA.getValue(field))
114114
.toMap
115+
.view
115116
.filterKeys(validFields)
117+
.toMap
116118
}
117119

118120
/** Yauaa 7.x added many new fields which are not in the 1-0-4 schema */

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/apirequest/ApiRequestEnrichment.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ object ApiRequestEnrichment extends ParseableEnrichment {
9393
UUID.nameUUIDFromBytes(contentKey.getBytes).toString
9494
}
9595

96-
def create[F[_]: Async: Clock](
96+
def create[F[_]: Async](
9797
schemaKey: SchemaKey,
9898
inputs: List[Input],
9999
api: HttpApi,

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/pii/PiiPseudonymizerEnrichment.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111
package com.snowplowanalytics.snowplow.enrich.common.enrichments.registry.pii
1212

13-
import scala.collection.JavaConverters._
14-
import scala.collection.mutable.MutableList
13+
import scala.jdk.CollectionConverters._
14+
import scala.collection.mutable.ListBuffer
1515

1616
import cats.data.ValidatedNel
1717
import cats.implicits._
@@ -216,7 +216,7 @@ final case class PiiJson(
216216
val jObjectMap = obj.toMap
217217
val contextMapped = jObjectMap.map(mapContextTopFields(_, strategy))
218218
(
219-
Json.obj(contextMapped.mapValues(_._1).toList: _*),
219+
Json.obj(contextMapped.view.mapValues(_._1).toList: _*),
220220
contextMapped.values.flatMap(_._2)
221221
)
222222
}
@@ -282,7 +282,7 @@ final case class PiiJson(
282282
): (Json, List[JsonModifiedField]) = {
283283
val objectNode = io.circe.jackson.mapper.valueToTree[ObjectNode](json)
284284
val documentContext = JJsonPath.using(JsonPathConf).parse(objectNode)
285-
val modifiedFields = MutableList[JsonModifiedField]()
285+
val modifiedFields = ListBuffer[JsonModifiedField]()
286286
Option(documentContext.read[AnyRef](jsonPath)) match { // check that json object not null
287287
case None => (jacksonToCirce(documentContext.json[JsonNode]()), modifiedFields.toList)
288288
case _ =>
@@ -297,7 +297,7 @@ final case class PiiJson(
297297

298298
private final case class ScrambleMapFunction(
299299
strategy: PiiStrategy,
300-
modifiedFields: MutableList[JsonModifiedField],
300+
modifiedFields: ListBuffer[JsonModifiedField],
301301
fieldName: String,
302302
jsonPath: String,
303303
schema: String

modules/common/src/main/scala/com.snowplowanalytics.snowplow.enrich/common/enrichments/registry/sqlquery/DbExecutor.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,6 @@ object DbExecutor {
193193
if (intMap.keys.size == placeholderCount) true else false
194194
}
195195

196-
def getConnection[F[_]: Monad: DbExecutor](dataSource: DataSource): Resource[F, Connection] =
196+
def getConnection[F[_]: DbExecutor](dataSource: DataSource): Resource[F, Connection] =
197197
DbExecutor[F].getConnection(dataSource)
198198
}

0 commit comments

Comments
 (0)