Skip to content

Commit

Permalink
Improve responsetime by using coroutines (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur93 authored Sep 11, 2023
1 parent 90577dc commit 8702a16
Show file tree
Hide file tree
Showing 28 changed files with 744 additions and 446 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deploy_feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- '**'
- '!main'

env:
GITHUB_USERNAME: x-access-token
Expand All @@ -27,7 +28,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -Dmaven.test.skip=true -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -Dmaven.test.skip=true -DskipOwasp=true -B -e --settings .m2/maven-settings.xml clean install
- uses: nais/docker-build-push@v0
id: docker-push
with:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Deploy to dev
on:
pull_request:
types: [ ready_for_review, opened, synchronize ]
push:
branches:
- 'main'

env:
GITHUB_USERNAME: x-access-token
Expand All @@ -29,7 +26,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -Dmaven.test.skip=true -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -Dmaven.test.skip=true -DskipOwasp=true -B -e --settings .m2/maven-settings.xml clean install
- uses: nais/docker-build-push@v0
id: docker-push
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -Dmaven.test.skip=true -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -Dmaven.test.skip=true -DskipOwasp=true -B -e --settings .m2/maven-settings.xml clean install
- uses: nais/docker-build-push@v0
id: docker-push
with:
Expand Down
2 changes: 1 addition & 1 deletion .nais/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ env:
BIDRAG_DOKUMENT_ARKIV_CLIENT_ID: dev-fss.bidrag.bidrag-dokument-arkiv-feature
BIDRAG_DOKUMENT_FORSENDELSE_CLIENT_ID: dev-gcp.bidrag.bidrag-dokument-forsendelse-feature
STS_ISSUER_URL: https://security-token-service.dev.adeo.no
JAVA_OPTS: -Xmx1500m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:MaxRAMPercentage=80.0 -XX:+UseContainerSupport
JAVA_OPTS: -Xms1500m -Xmx1500m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:MaxRAMPercentage=80.0 -XX:+UseContainerSupport
path: dev
2 changes: 1 addition & 1 deletion .nais/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ env:
BIDRAG_DOKUMENT_ARKIV_CLIENT_ID: dev-fss.bidrag.bidrag-dokument-arkiv
BIDRAG_DOKUMENT_FORSENDELSE_CLIENT_ID: dev-gcp.bidrag.bidrag-dokument-forsendelse
STS_ISSUER_URL: https://security-token-service.dev.adeo.no
JAVA_OPTS: -Xmx1500m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:MaxRAMPercentage=80.0 -XX:+UseContainerSupport
JAVA_OPTS: -Xms1500m -Xmx1500m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:MaxRAMPercentage=80.0 -XX:+UseContainerSupport
path: dev
2 changes: 1 addition & 1 deletion .nais/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ env:
BIDRAG_DOKUMENT_ARKIV_CLIENT_ID: prod-fss.bidrag.bidrag-dokument-arkiv
BIDRAG_DOKUMENT_FORSENDELSE_CLIENT_ID: prod-gcp.bidrag.bidrag-dokument-forsendelse
STS_ISSUER_URL: https://security-token-service.nais.adeo.no
JAVA_OPTS: -Xmx1500m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:MaxRAMPercentage=80.0
JAVA_OPTS: -Xms1500m -Xmx1500m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:MaxRAMPercentage=80.0
path: prod
48 changes: 40 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<version>3.1.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>

<!-- language -->
<java.version>17</java.version>
<kotlin.version>1.8.10</kotlin.version>
<kotlin.version>1.9.10</kotlin.version>

<!-- dependent versions other than from spring-boot -->
<bidrag-commons.version>20230427084654_4121ef0</bidrag-commons.version>
Expand All @@ -34,7 +34,7 @@
<token-support.version>3.0.10</token-support.version>
<squareup.version>4.11.0</squareup.version>
<mockk.version>4.0.2</mockk.version>
<kotest.version>5.6.1</kotest.version>
<kotest.version>5.7.0</kotest.version>
<kotlin-logging-jvm.version>3.0.5</kotlin-logging-jvm.version>

<!-- build -->
Expand All @@ -43,6 +43,7 @@
<maven.surefire.version>2.22.0</maven.surefire.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<skipOwasp>false</skipOwasp>

</properties>

Expand All @@ -59,12 +60,23 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
<version>2.2</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-reactor</artifactId>
<version>1.7.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
Expand Down Expand Up @@ -156,13 +168,17 @@
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.28</version>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-io</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>32.1.2-jre</version>
</dependency>

<!-- ws -->
Expand Down Expand Up @@ -389,11 +405,27 @@
<dependency>
<groupId>com.pinterest</groupId>
<artifactId>ktlint</artifactId>
<version>0.47.1</version>
<version>0.50.0</version>
</dependency>
<!-- additional 3rd party ruleset(s) can be specified here -->
</dependencies>
</plugin>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>8.4.0</version>
<configuration>
<failBuildOnCVSS>7</failBuildOnCVSS>
<skip>${skipOwasp}</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
48 changes: 33 additions & 15 deletions src/main/java/no/nav/bidrag/dokument/BidragDokumentConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,82 +36,100 @@ private val log = KotlinLogging.logger {}
@Configuration
@OpenAPIDefinition(
info = Info(title = "bidrag-dokument", version = "v1"),
security = [SecurityRequirement(name = "bearer-key")]
security = [SecurityRequirement(name = "bearer-key")],
)
@SecurityScheme(
bearerFormat = "JWT",
name = "bearer-key",
scheme = "bearer",
type = SecuritySchemeType.HTTP
type = SecuritySchemeType.HTTP,
)
@EnableAspectJAutoProxy
@EnableSecurityConfiguration
@Import(
EnhetFilter::class,
DefaultCorsFilter::class,
UserMdcFilter::class,
CorrelationIdFilter::class
CorrelationIdFilter::class,
)
class BidragDokumentConfig {
@Bean
@Qualifier(MIDL_BREVLAGER_QUALIFIER)
fun bidragJournalpostConsumer(
@Value("\${JOURNALPOST_URL}") journalpostBaseUrl: String,
securityTokenService: SecurityTokenService
securityTokenService: SecurityTokenService,
meterRegistry: MeterRegistry,
): BidragDokumentConsumer {
val restTemplate = createRestTemplate(
journalpostBaseUrl,
securityTokenService,
KLIENTNAVN_BIDRAG_DOKUMENT_JOURNALPOST
KLIENTNAVN_BIDRAG_DOKUMENT_JOURNALPOST,
)
return BidragDokumentConsumer(
KLIENTNAVN_BIDRAG_DOKUMENT_JOURNALPOST,
restTemplate,
journalpostBaseUrl,
meterRegistry,
)
return BidragDokumentConsumer(restTemplate, journalpostBaseUrl)
}

@Bean
@Qualifier(ARKIV_QUALIFIER)
fun bidragArkivConsumer(
@Value("\${BIDRAG_ARKIV_URL}") bidragArkivBaseUrl: String,
securityTokenService: SecurityTokenService
securityTokenService: SecurityTokenService,
meterRegistry: MeterRegistry,
): BidragDokumentConsumer {
val restTemplate = createRestTemplate(
bidragArkivBaseUrl,
securityTokenService,
KLIENTNAVN_BIDRAG_DOKUMENT_ARKIV
KLIENTNAVN_BIDRAG_DOKUMENT_ARKIV,
)
return BidragDokumentConsumer(
KLIENTNAVN_BIDRAG_DOKUMENT_ARKIV,
restTemplate,
bidragArkivBaseUrl,
meterRegistry,
)
return BidragDokumentConsumer(restTemplate, bidragArkivBaseUrl)
}

@Bean
@Qualifier(FORSENDELSE_QUALIFIER)
fun bidragForsendelseConsumer(
@Value("\${BIDRAG_FORSENDELSE_URL}") bidragForsendelseUrl: String,
securityTokenService: SecurityTokenService
securityTokenService: SecurityTokenService,
meterRegistry: MeterRegistry,
): BidragDokumentConsumer {
val restTemplate = createRestTemplate(
bidragForsendelseUrl,
securityTokenService,
KLIENTNAVN_BIDRAG_DOKUMENT_FORSENDELSE
KLIENTNAVN_BIDRAG_DOKUMENT_FORSENDELSE,
)
return BidragDokumentConsumer(
KLIENTNAVN_BIDRAG_DOKUMENT_FORSENDELSE,
restTemplate,
bidragForsendelseUrl,
meterRegistry,
)
return BidragDokumentConsumer(restTemplate, bidragForsendelseUrl)
}

@Bean
fun dokumentConsumer(
@Value("\${JOURNALPOST_URL}") journalpostBaseUrl: String,
securityTokenService: SecurityTokenService
securityTokenService: SecurityTokenService,
): DokumentTilgangConsumer {
val restTemplate = createRestTemplate(
journalpostBaseUrl,
securityTokenService,
KLIENTNAVN_BIDRAG_DOKUMENT_JOURNALPOST
KLIENTNAVN_BIDRAG_DOKUMENT_JOURNALPOST,
)
return DokumentTilgangConsumer(restTemplate)
}

private fun createRestTemplate(
baseUrl: String,
securityTokenService: SecurityTokenService,
clientId: String
clientId: String,
): RestTemplate {
val httpHeaderRestTemplate = HttpHeaderRestTemplate()
val sc = SocketConfig.custom().setSoTimeout(Timeout.ofMinutes(5)).build()
Expand Down
Loading

0 comments on commit 8702a16

Please sign in to comment.