-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Http4s Client with configuration appropriate for common-streams apps
Common-streams apps require an http4s Client for: - Iglu resolver - Webhook monitoring alerts - Telemetry This commit provides a Client which is configured appropriately for these common use cases.
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
snowplow.defaults: { | ||
http: { | ||
client: { | ||
maxConnectionsPerServer: 4 | ||
} | ||
} | ||
|
||
statsd: { | ||
port: 8125 | ||
tags: {} | ||
|
41 changes: 41 additions & 0 deletions
41
...les/runtime-common/src/main/scala/com/snowplowanalytics/snowplow/runtime/HttpClient.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,41 @@ | ||
/* | ||
* Copyright (c) 2023-present Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Snowplow Community License Version 1.0, | ||
* and you may not use this file except in compliance with the Snowplow Community License Version 1.0. | ||
* You may obtain a copy of the Snowplow Community License Version 1.0 at https://docs.snowplow.io/community-license-1.0 | ||
*/ | ||
package com.snowplowanalytics.snowplow.runtime | ||
|
||
import cats.effect.{Async, Resource} | ||
import org.http4s.blaze.client.BlazeClientBuilder | ||
import org.http4s.client.Client | ||
import io.circe._ | ||
import io.circe.generic.semiauto._ | ||
|
||
object HttpClient { | ||
case class Config( | ||
maxConnectionsPerServer: Int | ||
) | ||
|
||
object Config { | ||
implicit def telemetryConfigDecoder: Decoder[Config] = deriveDecoder | ||
} | ||
|
||
/** | ||
* Provides a http4s Client configured appropriately for a snowplow common-streams app | ||
* | ||
* Blaze option `maxConnectionsPerRequestKey` is set to something small. This is required so we | ||
* can traverse over many schemas in parallel without overwhelming any single Iglu server. | ||
* | ||
* Blaze options `maxTotalConnections` and `maxWaitQueueLimit` are unlimited. This is appropriate | ||
* because common-streams apps are already naturally rate limited by the flow of events. We do not | ||
* want exceptions for exceeding number of requests allowed in a queue. | ||
*/ | ||
def resource[F[_]: Async](config: Config): Resource[F, Client[F]] = | ||
BlazeClientBuilder[F] | ||
.withMaxConnectionsPerRequestKey(Function.const(config.maxConnectionsPerServer)) | ||
.withMaxTotalConnections(Int.MaxValue) | ||
.withMaxWaitQueueLimit(Int.MaxValue) | ||
.resource | ||
} |
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