Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bumped to ktor 3.0.0 #280

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ val caffeineVersion = "3.1.8"
val coroutinesVersion = "1.9.0"
val jacksonVersion = "2.18.0"
val kluentVersion = "1.73"
val ktorVersion = "2.3.12"
val ktorVersion = "3.0.1"
val logbackVersion = "1.5.8"
val logstashEncoderVersion = "8.0"
val prometheusVersion = "0.16.0"
Expand All @@ -26,7 +26,7 @@ plugins {
id("application")
kotlin("jvm") version "2.0.20"
id("com.diffplug.spotless") version "6.25.0"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.gradleup.shadow") version "8.3.3"
}

application {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
16 changes: 8 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/syfo/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fun harTilgang(credentials: JWTCredential, clientId: String): Boolean {
return credentials.payload.audience.contains(clientId)
}

fun unauthorized(credentials: JWTCredential): Principal? {
fun unauthorized(credentials: JWTCredential): Unit? {
logger.warn(
"Auth: Unexpected audience for jwt {}, {}",
StructuredArguments.keyValue("issuer", credentials.payload.issuer),
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/no/nav/syfo/metrics/MonitorHttpRequests.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package no.nav.syfo.metrics

import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.*
import io.ktor.server.request.path
import io.ktor.util.pipeline.PipelineContext
import io.ktor.util.pipeline.*

fun monitorHttpRequests(): suspend PipelineContext<Unit, ApplicationCall>.(Unit) -> Unit {
fun monitorHttpRequests(): PipelineInterceptor<Unit, PipelineCall> {
return {
val label = context.request.path()
val timer = HTTP_HISTOGRAM.labels(label).startTimer()
Expand Down
100 changes: 56 additions & 44 deletions src/test/kotlin/no/nav/syfo/application/api/SelftestSpek.kt
Original file line number Diff line number Diff line change
@@ -1,67 +1,79 @@
package no.nav.syfo.application.api
package no.nav.syfo

import io.kotest.core.spec.style.FunSpec
import io.ktor.http.HttpMethod
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.HttpStatusCode
import io.ktor.server.routing.routing
import io.ktor.server.testing.TestApplicationEngine
import io.ktor.server.testing.handleRequest
import no.nav.syfo.ApplicationState
import io.ktor.server.testing.*
import no.nav.syfo.nais.isalive.naisIsAliveRoute
import no.nav.syfo.nais.isready.naisIsReadyRoute
import org.amshove.kluent.shouldBeEqualTo

object SelftestSpek :
FunSpec({
context("Successfull liveness and readyness tests") {
with(TestApplicationEngine()) {
start()
val applicationState = ApplicationState()
applicationState.ready = true
applicationState.alive = true
application.routing {
naisIsAliveRoute(applicationState)
naisIsReadyRoute(applicationState)
}

class SelftestSpek :
FunSpec(
{
context("Successfull liveness and readyness tests") {
test("Returns ok on is_alive") {
with(handleRequest(HttpMethod.Get, "/internal/is_alive")) {
response.status() shouldBeEqualTo HttpStatusCode.OK
response.content shouldBeEqualTo "I'm alive! :)"
testApplication {
application {
val applicationState = ApplicationState()
applicationState.ready = true
applicationState.alive = true
routing { naisIsAliveRoute(applicationState) }
}

val response = client.get("/internal/is_alive")

response.status shouldBeEqualTo HttpStatusCode.OK
response.bodyAsText() shouldBeEqualTo "I'm alive! :)"
}
}
test("Returns ok in is_ready") {
with(handleRequest(HttpMethod.Get, "/internal/is_ready")) {
response.status() shouldBeEqualTo HttpStatusCode.OK
response.content shouldBeEqualTo "I'm ready! :)"
testApplication {
application {
val applicationState = ApplicationState()
applicationState.ready = true
applicationState.alive = true
routing { naisIsReadyRoute(applicationState) }
}

val response = client.get("/internal/is_ready")
response.status shouldBeEqualTo HttpStatusCode.OK
response.bodyAsText() shouldBeEqualTo "I'm ready! :)"
}
}
}
}
context("Unsuccessful liveness and readyness") {
with(TestApplicationEngine()) {
start()
val applicationState = ApplicationState()
applicationState.ready = false
applicationState.alive = false
application.routing {
naisIsAliveRoute(applicationState)
naisIsReadyRoute(applicationState)
}

context("Unsuccessful liveness and readyness") {
test("Returns internal server error when liveness check fails") {
with(handleRequest(HttpMethod.Get, "/internal/is_alive")) {
response.status() shouldBeEqualTo HttpStatusCode.InternalServerError
response.content shouldBeEqualTo "I'm dead x_x"
testApplication {
application {
val applicationState = ApplicationState()
applicationState.ready = false
applicationState.alive = false
routing { naisIsAliveRoute(applicationState) }
}
val response = client.get("/internal/is_alive")

response.status shouldBeEqualTo HttpStatusCode.InternalServerError
response.bodyAsText() shouldBeEqualTo "I'm dead x_x"
}
}

test("Returns internal server error when readyness check fails") {
with(handleRequest(HttpMethod.Get, "/internal/is_ready")) {
response.status() shouldBeEqualTo HttpStatusCode.InternalServerError
response.content shouldBeEqualTo "Please wait! I'm not ready :("
testApplication {
application {
val applicationState = ApplicationState()
applicationState.ready = false
applicationState.alive = false
routing { naisIsReadyRoute(applicationState) }
}
val response = client.get("/internal/is_ready")

response.status shouldBeEqualTo HttpStatusCode.InternalServerError
response.bodyAsText() shouldBeEqualTo "Please wait! I'm not ready :("
}
}
}
}
})
},
)
Loading