Skip to content

Commit

Permalink
1.29.0 (#40)
Browse files Browse the repository at this point in the history
* Change favicon.ico
* Upgrade to kotlin 1.7.0
  • Loading branch information
pambrose authored Jun 12, 2022
1 parent 9eb2903 commit 8de3369
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ depends:
./gradlew dependencies

upgrade-wrapper:
./gradlew wrapper --gradle-version=7.4.2 --distribution-type=bin
./gradlew wrapper --gradle-version=7.5-rc-2 --distribution-type=bin
64 changes: 33 additions & 31 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ buildscript {
plugins {
id 'java'
id 'application'
id 'org.jetbrains.kotlin.jvm' version '1.7.0-RC' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.0-RC' apply false
id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.0' apply false
id 'org.jmailen.kotlinter' version "3.10.0" apply false
id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false
id "com.github.ben-manes.versions" version '0.42.0' apply false
id "org.flywaydb.flyway" version "8.5.11"
id "org.flywaydb.flyway" version "8.5.12"
}

ext {
Expand All @@ -33,43 +33,45 @@ ext {

prometheus_proxy : "com.github.pambrose:prometheus-proxy:$proxy_version",

simple_client : "io.prometheus:simpleclient:$prometheus_version",
simple_client : "io.prometheus:simpleclient:$prometheus_version",

script_engine : "ch.obermuhlner:java-scriptengine:$java_script_version",
script_engine : "ch.obermuhlner:java-scriptengine:$java_script_version",

css : "org.jetbrains.kotlin-wrappers:kotlin-css:$css_version",
css : "org.jetbrains.kotlin-wrappers:kotlin-css:$css_version",

ktor_client_core : "io.ktor:ktor-client:$ktor_version",
ktor_client_cio : "io.ktor:ktor-client-cio:$ktor_version",
ktor_client_core: "io.ktor:ktor-client:$ktor_version",
ktor_client_cio : "io.ktor:ktor-client-cio:$ktor_version",

ktor_server_core : "io.ktor:ktor-server:$ktor_version",
ktor_server_cio : "io.ktor:ktor-server-cio:$ktor_version",
ktor_sessions : "io.ktor:ktor-server-sessions:$ktor_version",
ktor_html : "io.ktor:ktor-server-html-builder:$ktor_version",
ktor_locations : "io.ktor:ktor-server-locations:$ktor_version",
ktor_metrics : "io.ktor:ktor-server-metrics:$ktor_version",
ktor_websockets : "io.ktor:ktor-server-websockets:$ktor_version",
ktor_compression : "io.ktor:ktor-server-compression:$ktor_version",
ktor_calllogging : "io.ktor:ktor-server-call-logging:$ktor_version",
ktor_server_core: "io.ktor:ktor-server:$ktor_version",
ktor_server_cio : "io.ktor:ktor-server-cio:$ktor_version",
ktor_sessions : "io.ktor:ktor-server-sessions:$ktor_version",
ktor_html : "io.ktor:ktor-server-html-builder:$ktor_version",
ktor_locations : "io.ktor:ktor-server-locations:$ktor_version",
ktor_metrics : "io.ktor:ktor-server-metrics:$ktor_version",
ktor_websockets : "io.ktor:ktor-server-websockets:$ktor_version",
ktor_compression: "io.ktor:ktor-server-compression:$ktor_version",
ktor_calllogging: "io.ktor:ktor-server-call-logging:$ktor_version",

jedis : "redis.clients:jedis:$redis_version",
khealth : "dev.hayden:khealth:$khealth_version",

hikari : "com.zaxxer:HikariCP:$hikari_version",
exposed_core : "org.jetbrains.exposed:exposed-core:$exposed_version",
exposed_jdbc : "org.jetbrains.exposed:exposed-jdbc:$exposed_version",
exposed_jodatime : "org.jetbrains.exposed:exposed-jodatime:$exposed_version",
pgjdbc : "com.impossibl.pgjdbc-ng:pgjdbc-ng-all:$pgjdbc_version",
postgres : "org.postgresql:postgresql:$postgres_version",
socket : "com.google.cloud.sql:postgres-socket-factory:$cloud_version",
jedis : "redis.clients:jedis:$redis_version",

gson : "com.google.code.gson:gson:$gson_version",
hikari : "com.zaxxer:HikariCP:$hikari_version",
exposed_core : "org.jetbrains.exposed:exposed-core:$exposed_version",
exposed_jdbc : "org.jetbrains.exposed:exposed-jdbc:$exposed_version",
exposed_jodatime: "org.jetbrains.exposed:exposed-jodatime:$exposed_version",
pgjdbc : "com.impossibl.pgjdbc-ng:pgjdbc-ng-all:$pgjdbc_version",
postgres : "org.postgresql:postgresql:$postgres_version",
socket : "com.google.cloud.sql:postgres-socket-factory:$cloud_version",

sendgrid : "com.sendgrid:sendgrid-java:$sendgrid_version",
gson : "com.google.code.gson:gson:$gson_version",

commons : "org.apache.commons:commons-text:$commons_version",
flexmark : "com.vladsch.flexmark:flexmark:$flexmark_version",
sendgrid : "com.sendgrid:sendgrid-java:$sendgrid_version",

github : "org.kohsuke:github-api:$github_api_version",
commons : "org.apache.commons:commons-text:$commons_version",
flexmark : "com.vladsch.flexmark:flexmark:$flexmark_version",

github : "org.kohsuke:github-api:$github_api_version",

ktor_server_tests : "io.ktor:ktor-server-tests:$ktor_version",
ktor_server_test_host : "io.ktor:ktor-server-test-host:$ktor_version",
Expand All @@ -83,7 +85,7 @@ ext {
allprojects {
description = 'ReadingBat Core'
group 'com.github.readingbat'
version '1.28.0'
version '1.29.0'

apply plugin: 'application'
apply plugin: 'java-library' // gradle 7
Expand Down
Binary file added docs/images/face.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 6 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@ org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.jvmargs=-Xmx8g -Dkotlin.daemon.jvm.options=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
cloud_version=1.6.0
cloud_version=1.6.1
commons_version=1.9
//coroutines_version=1.6.1
css_version=1.0.0-pre.340
css_version=1.0.0-pre.343
exposed_version=0.38.2
flexmark_version=0.64.0
github_api_version=1.306
gson_version=2.9.0
hikari_version=5.0.1
java_script_version=2.0.0
//khealth_version=1.0.0
khealth_version=2.1.0
kotest_version=5.3.0
kotest_ktor_version=4.4.3
kotlin_version=1.7.0-Beta
kotlin_version=1.7.0
ktor_version=2.0.2
logback_version=1.2.10
logging_version=2.1.23
pgjdbc_version=0.8.9
postgres_version=42.3.6
postgres_version=42.4.0
prometheus_version=0.15.0
proxy_version=1.13.0
redis_version=4.2.3
serialization_version=1.3.3
sendgrid_version=4.9.2
utils_version=1.26.0
utils_version=1.27.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-rc-2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 3 additions & 1 deletion readingbat-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ dependencies {
implementation libraries.ktor_compression
implementation libraries.ktor_calllogging

implementation libraries.khealth

implementation libraries.jedis

implementation libraries.hikari
Expand Down Expand Up @@ -84,7 +86,7 @@ dependencies {
buildConfig {
buildConfigField('String', 'CORE_NAME', "\"${project.name}\"")
buildConfigField('String', 'CORE_VERSION', "\"${project.version}\"")
buildConfigField('String', 'CORE_RELEASE_DATE', "\"05/31/2022\"")
buildConfigField('String', 'CORE_RELEASE_DATE', "\"06/11/2022\"")
}

// Include build uberjars in heroku deploy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class GitHubContent(
fileName = fileName
)

private const val GH_PREFIX = "https://raw.githubusercontent.com"

fun readingBatContent(block: ReadingBatContent.() -> Unit) =
ReadingBatContent().apply(block).apply { validate() }

Expand Down Expand Up @@ -93,7 +95,7 @@ private fun saveContentDslToRedis(source: String, dsl: String) {
if (isContentCachingEnabled()) {
redisPool?.withNonNullRedisPool(true) { redis ->
redis.set(contentDslKey(source), dsl)
logger.info { "Saved $source to redis" }
logger.info { "Saved ${source.removePrefix(GH_PREFIX)} to redis" }
}
}
}
Expand All @@ -105,15 +107,15 @@ internal fun readContentDsl(contentSource: ContentSource) =
} else {
var dslCode = fetchContentDslFromRedis(contentSource.source)
if (dslCode.isNotNull()) {
logger.info { "Fetched ${contentSource.source} from redis cache" }
logger.info { "Fetched ${contentSource.source.removePrefix(GH_PREFIX)} from redis cache" }
} else {
dslCode = contentSource.content
saveContentDslToRedis(contentSource.source, dslCode)
}
dslCode
}
}.let {
logger.info { "Read content for ${contentSource.source} in ${it.duration}" }
logger.info { "Read content for ${contentSource.source.removePrefix(GH_PREFIX)} in ${it.duration}" }
it.value
}

Expand All @@ -124,12 +126,12 @@ internal fun evalContentDsl(
) =
runBlocking {
measureTimedValue {
logger.info { "Starting eval for $source" }
logger.info { "Starting eval for ${source.removePrefix(GH_PREFIX)}" }
val withImports = addImports(code, variableName)
evalDsl(withImports, source)
}
}.let {
logger.info { "Evaluated $source in ${it.duration}" }
logger.info { "Evaluated ${source.removePrefix(GH_PREFIX)} in ${it.duration}" }
it.value
}

Expand Down Expand Up @@ -163,7 +165,7 @@ private suspend fun evalDsl(code: String, sourceName: String) =
try {
kotlinScriptPool.eval { eval(code) as ReadingBatContent }.apply { validate() }
} catch (e: Throwable) {
logger.info { "Error in $sourceName:\n$code" }
logger.info { "Error in ${sourceName.removePrefix(GH_PREFIX)}:\n$code" }
throw e
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ internal object PageUtils {
if (url.isNotEmpty()) {
div {
style = "font-size:120%; margin-left:$marginLeft"
p { a { href = url; rawHtml("← $text") } }
p { a { href = url; rawHtml(" $text") } }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.github.readingbat.server.ConfigureFormAuth.configureFormAuth
import com.github.readingbat.server.Email.Companion.UNKNOWN_EMAIL
import com.github.readingbat.server.ReadingBatServer.serverSessionId
import com.github.readingbat.server.ServerUtils.fetchEmailFromCache
import dev.hayden.KHealth
import io.ktor.http.*
import io.ktor.http.HttpHeaders.Location
import io.ktor.http.HttpStatusCode.Companion.Found
Expand Down Expand Up @@ -165,6 +166,16 @@ object Installs : KLogging() {
verify { it.isNotEmpty() }
}

install(KHealth) {
// readyChecks {
// check("check my database is up") { true }
// }
//
// healthChecks {
// check("another check") { true }
// }
}

/*
install(DropwizardMetrics) {
val reporter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ import com.github.readingbat.common.Constants.REDIS_IS_DOWN
import com.github.readingbat.common.Constants.UNKNOWN_USER_ID
import com.github.readingbat.common.Endpoints.STATIC_ROOT
import com.github.readingbat.common.EnvVar
import com.github.readingbat.common.EnvVar.CLOUD_SQL_CONNECTION_NAME
import com.github.readingbat.common.EnvVar.SCRIPT_CLASSPATH
import com.github.readingbat.common.Metrics
import com.github.readingbat.common.Property
import com.github.readingbat.common.Property.CONFIG_FILENAME
import com.github.readingbat.common.Property.Companion.assignProperties
import com.github.readingbat.common.Property.DBMS_MAX_LIFETIME_MINS
import com.github.readingbat.common.Property.DBMS_MAX_POOL_SIZE
import com.github.readingbat.common.Property.KOTLIN_SCRIPT_CLASSPATH
import com.github.readingbat.common.User.Companion.createUnknownUser
import com.github.readingbat.common.User.Companion.userExists
import com.github.readingbat.dsl.ReadingBatContent
Expand Down Expand Up @@ -84,16 +90,16 @@ import kotlin.time.measureTime

@Version(version = BuildConfig.CORE_VERSION, date = BuildConfig.CORE_RELEASE_DATE)
object ReadingBatServer : KLogging() {
private const val CALLER_VERSION = "callerVersion"
private val startTime = TimeSource.Monotonic.markNow()
internal val serverSessionId = randomId(10)
internal val timeStamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("M/d/y H:m:ss"))
internal var callerVersion = ""
internal val content = AtomicReference(ReadingBatContent())
internal val adminUsers = mutableListOf<String>()
internal val contentReadCount = AtomicInteger(0)
val metrics by lazy { Metrics() }
internal var redisPool: JedisPool? = null
private const val CALLER_VERSION = "callerVersion"
internal var callerVersion = ""
val metrics by lazy { Metrics() }
internal val dbms by lazy {
Database.connect(
HikariDataSource(
Expand All @@ -104,19 +110,18 @@ object ReadingBatServer : KLogging() {
username = EnvVar.DBMS_USERNAME.getEnv(Property.DBMS_USERNAME.getRequiredProperty())
password = EnvVar.DBMS_PASSWORD.getEnv(Property.DBMS_PASSWORD.getRequiredProperty())

EnvVar.CLOUD_SQL_CONNECTION_NAME.getEnv("")
CLOUD_SQL_CONNECTION_NAME.getEnv("")
.also {
if (it.isNotBlank()) {
addDataSourceProperty("cloudSqlInstance", it)
addDataSourceProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory")
}
}

maximumPoolSize = Property.DBMS_MAX_POOL_SIZE.getRequiredProperty().toInt()
maximumPoolSize = DBMS_MAX_POOL_SIZE.getRequiredProperty().toInt()
isAutoCommit = false
transactionIsolation = "TRANSACTION_REPEATABLE_READ"
maxLifetime =
Property.DBMS_MAX_LIFETIME_MINS.getRequiredProperty().toInt().minutes.inWholeMilliseconds
maxLifetime = DBMS_MAX_LIFETIME_MINS.getRequiredProperty().toInt().minutes.inWholeMilliseconds
validate()
})
)
Expand All @@ -127,15 +132,15 @@ object ReadingBatServer : KLogging() {
fun assignKotlinScriptProperty() {
// If kotlin.script.classpath property is missing, set it based on env var SCRIPT_CLASSPATH
// This has to take place before reading DSL
val scriptClasspathProp = Property.KOTLIN_SCRIPT_CLASSPATH.getPropertyOrNull()
val scriptClasspathProp = KOTLIN_SCRIPT_CLASSPATH.getPropertyOrNull()
if (scriptClasspathProp.isNull()) {
val scriptClasspathEnvVar = EnvVar.SCRIPT_CLASSPATH.getEnvOrNull()
val scriptClasspathEnvVar = SCRIPT_CLASSPATH.getEnvOrNull()
if (scriptClasspathEnvVar.isNotNull())
Property.KOTLIN_SCRIPT_CLASSPATH.setProperty(scriptClasspathEnvVar)
KOTLIN_SCRIPT_CLASSPATH.setProperty(scriptClasspathEnvVar)
else
logger.warn { "Missing ${Property.KOTLIN_SCRIPT_CLASSPATH.propertyValue} and ${EnvVar.SCRIPT_CLASSPATH} values" }
logger.warn { "Missing ${KOTLIN_SCRIPT_CLASSPATH.propertyValue} and $SCRIPT_CLASSPATH values" }
} else {
logger.info { "${Property.KOTLIN_SCRIPT_CLASSPATH.propertyValue}: $scriptClasspathProp" }
logger.info { "${KOTLIN_SCRIPT_CLASSPATH.propertyValue}: $scriptClasspathProp" }
}
}

Expand All @@ -161,7 +166,7 @@ object ReadingBatServer : KLogging() {
?: Property.AGENT_CONFIG.getPropertyOrNull(false)
?: "src/main/resources/application.conf"

Property.CONFIG_FILENAME.setProperty(configFilename)
CONFIG_FILENAME.setProperty(configFilename)

return if (args.any { it.startsWith("-config=") })
args
Expand Down Expand Up @@ -245,7 +250,7 @@ fun Application.module() {

if (isAgentEnabled()) {
if (Property.PROXY_HOSTNAME.getRequiredProperty().isNotEmpty()) {
val configFilename = Property.CONFIG_FILENAME.getRequiredProperty()
val configFilename = CONFIG_FILENAME.getRequiredProperty()
val agentInfo = startAsyncAgent(configFilename, true)
Property.AGENT_LAUNCH_ID.setProperty(agentInfo.launchId)
} else {
Expand Down Expand Up @@ -296,5 +301,10 @@ fun Application.module() {
}

static(STATIC_ROOT) { resources("static") }

static("/") {
staticBasePackage = "public"
resources(".")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal object PubSubCommandsWs : KLogging() {
} ?: throw RedisUnavailableException("pubsubWs subscriber")
} catch (e: Throwable) {
logger.error(e) { "Exception in pubsubWs subscriber ${e.simpleClassName} ${e.message}" }
Thread.sleep(1.seconds.inWholeMilliseconds)
Thread.sleep(10.seconds.inWholeMilliseconds)
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit 8de3369

Please sign in to comment.