Skip to content

Commit

Permalink
Use trusting ssl context in client
Browse files Browse the repository at this point in the history
This is a temporary change to see whether warmup can actually help us with
startup.
The approach is naive and should be replaced with a proper truststore mounts.
  • Loading branch information
peel committed Jul 4, 2024
1 parent 6150942 commit 6e134ad
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import io.circe.Decoder
import com.snowplowanalytics.snowplow.scalatracker.Tracking

import com.snowplowanalytics.snowplow.collector.core.model.Sinks
import java.security.SecureRandom
import java.security.cert.X509Certificate
import javax.net.ssl.{SSLContext, X509TrustManager}

object Run {

Expand Down Expand Up @@ -112,24 +115,34 @@ object Run {
config.monitoring.metrics,
config.debug.http
)
_ <- withGracefulShutdown(config.preTerminationPeriod)(httpServer)
httpClient <- BlazeClientBuilder[F].resource
_ <- withGracefulShutdown(config.preTerminationPeriod)(httpServer)
trustingCtx: SSLContext = {
val trustManager = new X509TrustManager {
def getAcceptedIssuers(): Array[X509Certificate] = Array.empty
def checkClientTrusted(certs: Array[X509Certificate], authType: String): Unit = {}
def checkServerTrusted(certs: Array[X509Certificate], authType: String): Unit = {}
}
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, Array(trustManager), new SecureRandom)
sslContext
}
httpClient <- BlazeClientBuilder[F].withSslContext(trustingCtx).withCheckEndpointAuthentication(false).resource
} yield httpClient

resources.use { httpClient =>
val appId = java.util.UUID.randomUUID.toString
val warmup = if (config.experimental.warmup.enable) {
Stream
.emits(1 to config.experimental.warmup.numRequests)
.evalMap(_ =>
.evalMap { _ =>
httpClient
.expect[String](
s"""${if (config.ssl.enable) "https" else "http"}://${config.interface}:${if (config.ssl.enable)
config.ssl.port
else config.port}/health"""
)
.recover { case _ => "error" }
)
}
.fold((0, 0))((acc, cur) => if (cur == "error") (acc._1 + 1, acc._2) else (acc._1, acc._2 + 1))
.evalTap(status =>
Logger[F].info(s"Warmup pass complete. Successful requests: ${status._2}, failures: ${status._1}")
Expand Down

0 comments on commit 6e134ad

Please sign in to comment.