Skip to content

Commit

Permalink
store constants in searchable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ehigham committed Nov 20, 2024
1 parent e121222 commit d21ad57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 6 additions & 1 deletion hail/src/main/scala/is/hail/services/oauth2.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package is.hail.services

import is.hail.services.oauth2.AzureCloudCredentials.AzureTokenRefreshMinutes
import is.hail.services.oauth2.AzureCloudCredentials.EnvVars.AzureApplicationCredentials
import is.hail.services.oauth2.GoogleCloudCredentials.EnvVars.GoogleApplicationCredentials
import is.hail.shadedazure.com.azure.core.credential.{
Expand Down Expand Up @@ -88,14 +89,18 @@ object oauth2 {
}

private[this] def isExpired: Boolean =
token == null || OffsetDateTime.now.plusMinutes(5).isBefore(token.getExpiresAt)
token == null || OffsetDateTime.now.plusMinutes(AzureTokenRefreshMinutes).isBefore(
token.getExpiresAt
)
}

object AzureCloudCredentials {
object EnvVars {
val AzureApplicationCredentials = "AZURE_APPLICATION_CREDENTIALS"
}

private[AzureCloudCredentials] val AzureTokenRefreshMinutes = 5

def apply(keyPath: Option[Path], scopes: IndexedSeq[String], env: Map[String, String] = sys.env)
: AzureCloudCredentials =
keyPath.orElse(env.get(AzureApplicationCredentials).map(Path.of(_))) match {
Expand Down
18 changes: 10 additions & 8 deletions hail/src/main/scala/is/hail/services/requests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,32 @@ object requests {
def patch(route: String): JValue
}

private[this] val TIMEOUT_MS = 5 * 1000
private[this] val TimeoutMs = 5 * 1000
private[this] val MaxNumConnectionPerRoute = 20
private[this] val MaxNumConnections = 100

def Requester(baseUrl: URL, cred: CloudCredentials): Requester = {

val httpClient: CloseableHttpClient = {
log.info("creating HttpClient")
val requestConfig = RequestConfig.custom()
.setConnectTimeout(TIMEOUT_MS)
.setConnectionRequestTimeout(TIMEOUT_MS)
.setSocketTimeout(TIMEOUT_MS)
.setConnectTimeout(TimeoutMs)
.setConnectionRequestTimeout(TimeoutMs)
.setSocketTimeout(TimeoutMs)
.build()
try {
HttpClients.custom()
.setSSLContext(tls.getSSLContext)
.setMaxConnPerRoute(20)
.setMaxConnTotal(100)
.setMaxConnPerRoute(MaxNumConnectionPerRoute)
.setMaxConnTotal(MaxNumConnections)
.setDefaultRequestConfig(requestConfig)
.build()
} catch {
case _: NoSSLConfigFound =>
log.info("creating HttpClient with no SSL Context")
HttpClients.custom()
.setMaxConnPerRoute(20)
.setMaxConnTotal(100)
.setMaxConnPerRoute(MaxNumConnectionPerRoute)
.setMaxConnTotal(MaxNumConnections)
.setDefaultRequestConfig(requestConfig)
.build()
}
Expand Down

0 comments on commit d21ad57

Please sign in to comment.