From 79dfb9d392c9a4b5e882cbf48cbf8190b3db9432 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 26 Sep 2024 13:58:15 +0200 Subject: [PATCH 01/10] Testing without OTEL. --- deploy/nais.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/nais.yaml b/deploy/nais.yaml index 434ca63..c71af8a 100644 --- a/deploy/nais.yaml +++ b/deploy/nais.yaml @@ -12,7 +12,7 @@ spec: image: {{image}} observability: autoInstrumentation: - enabled: true + enabled: false runtime: java gcp: sqlInstances: From c248d54fb3456fd50a012c92a3212fa812530651 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 26 Sep 2024 14:18:53 +0200 Subject: [PATCH 02/10] A bit more juice. --- deploy/nais.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy/nais.yaml b/deploy/nais.yaml index c71af8a..9e6c465 100644 --- a/deploy/nais.yaml +++ b/deploy/nais.yaml @@ -48,10 +48,10 @@ spec: timeout: 1 resources: limits: - memory: 1024Mi + memory: 2024Mi requests: - cpu: 40m - memory: 256Mi + cpu: 80m + memory: 1024Mi ingresses: {{#each ingresses as |ingress|}} - {{ingress}} From 79e5c1d940aca4b3b1d57b56aff8871a48e5e5ef Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 26 Sep 2024 14:35:20 +0200 Subject: [PATCH 03/10] OTEL on again. --- deploy/nais.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/nais.yaml b/deploy/nais.yaml index 9e6c465..94e1c2d 100644 --- a/deploy/nais.yaml +++ b/deploy/nais.yaml @@ -12,7 +12,7 @@ spec: image: {{image}} observability: autoInstrumentation: - enabled: false + enabled: true runtime: java gcp: sqlInstances: From 269be0583c59aa48b912578a90bf9018c5d7a07c Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 26 Sep 2024 15:41:06 +0200 Subject: [PATCH 04/10] Less replicas for now. --- deploy/nais.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/nais.yaml b/deploy/nais.yaml index 94e1c2d..6e22353 100644 --- a/deploy/nais.yaml +++ b/deploy/nais.yaml @@ -57,8 +57,8 @@ spec: - {{ingress}} {{/each}} replicas: - min: 2 - max: 4 + min: 1 + max: 3 cpuThresholdPercentage: 80 prometheus: enabled: true From bfbedb85a3c73049e750429127c8e34baaed2747 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 26 Sep 2024 21:44:41 +0200 Subject: [PATCH 05/10] Load less data when getting versions. Getting OOM otherwise. --- .../no/nav/klage/document/api/DocumentController.kt | 3 ++- .../no/nav/klage/document/domain/DocumentVersion.kt | 13 ++++++++++++- .../repositories/DocumentVersionRepository.kt | 12 ++++++++++++ .../nav/klage/document/service/DocumentService.kt | 5 +++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt b/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt index 1681dd0..599a5cf 100644 --- a/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt +++ b/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt @@ -7,6 +7,7 @@ import no.nav.klage.document.api.views.DocumentVersionView import no.nav.klage.document.api.views.DocumentView import no.nav.klage.document.config.SecurityConfiguration.Companion.ISSUER_AAD import no.nav.klage.document.domain.DocumentVersion +import no.nav.klage.document.domain.ShortDocumentVersion import no.nav.klage.document.service.DocumentService import no.nav.klage.document.util.TokenUtil import no.nav.klage.document.util.getLogger @@ -132,7 +133,7 @@ class DocumentController( modified = documentVersion.modified ) - private fun mapToDocumentVersionView(documentVersion: DocumentVersion): DocumentVersionView = + private fun mapToDocumentVersionView(documentVersion: ShortDocumentVersion): DocumentVersionView = DocumentVersionView( documentId = documentVersion.documentId, version = documentVersion.version, diff --git a/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt b/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt index 997ca57..45f4e8f 100644 --- a/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt +++ b/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt @@ -43,5 +43,16 @@ class DocumentVersion( return "DocumentVersion(documentId=$documentId, version=$version, json='$json', data=$data, created=$created, modified=$modified, authorNavIdent='$authorNavIdent')" } - } + +/** + * Using this when we don't need the full DocumentVersion object, just a subset of the fields. + * Otherwise, we would have to fetch the full object from the database and that's too much data. + */ +data class ShortDocumentVersion( + val documentId: UUID, + val version: Int, + val authorNavIdent: String, + val created: LocalDateTime, + val modified: LocalDateTime, +) diff --git a/src/main/kotlin/no/nav/klage/document/repositories/DocumentVersionRepository.kt b/src/main/kotlin/no/nav/klage/document/repositories/DocumentVersionRepository.kt index 9f423bc..8306064 100644 --- a/src/main/kotlin/no/nav/klage/document/repositories/DocumentVersionRepository.kt +++ b/src/main/kotlin/no/nav/klage/document/repositories/DocumentVersionRepository.kt @@ -2,12 +2,24 @@ package no.nav.klage.document.repositories import no.nav.klage.document.domain.DocumentVersion import no.nav.klage.document.domain.DocumentVersionId +import no.nav.klage.document.domain.ShortDocumentVersion import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query import java.util.* interface DocumentVersionRepository : JpaRepository { fun findByDocumentId(documentId: UUID): List + @Query( + """ + SELECT new no.nav.klage.document.domain.ShortDocumentVersion(documentId, version, authorNavIdent, created, modified) + FROM DocumentVersion + WHERE documentId = :documentId + ORDER BY version + """ + ) + fun findVersionsByDocumentId(documentId: UUID): List + fun deleteByDocumentId(documentId: UUID) } \ No newline at end of file diff --git a/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt b/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt index b599aa6..dab71d2 100644 --- a/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt +++ b/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt @@ -3,6 +3,7 @@ package no.nav.klage.document.service import no.nav.klage.document.domain.Document import no.nav.klage.document.domain.DocumentVersion import no.nav.klage.document.domain.DocumentVersionId +import no.nav.klage.document.domain.ShortDocumentVersion import no.nav.klage.document.repositories.CommentRepository import no.nav.klage.document.repositories.DocumentRepository import no.nav.klage.document.repositories.DocumentVersionRepository @@ -113,8 +114,8 @@ class DocumentService( documentRepository.deleteById(documentId) } - fun getDocumentVersions(documentId: UUID): List { - return documentVersionRepository.findByDocumentId(documentId = documentId).sortedBy { it.version } + fun getDocumentVersions(documentId: UUID): List { + return documentVersionRepository.findVersionsByDocumentId(documentId = documentId) } } \ No newline at end of file From fb4b3c54c796283a5897fcabb59e457bb71c3f66 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 26 Sep 2024 22:07:10 +0200 Subject: [PATCH 06/10] Removed Micrometer tracing. --- build.gradle.kts | 3 -- .../document/config/CustomTraceFilter.kt | 36 ------------------- src/main/resources/application.yml | 17 +-------- 3 files changed, 1 insertion(+), 55 deletions(-) delete mode 100644 src/main/kotlin/no/nav/klage/document/config/CustomTraceFilter.kt diff --git a/build.gradle.kts b/build.gradle.kts index 532d6aa..86583ce 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,9 +40,6 @@ dependencies { implementation("com.zaxxer:HikariCP") implementation("org.postgresql:postgresql") - implementation("io.micrometer:micrometer-registry-prometheus") - implementation("io.micrometer:micrometer-tracing-bridge-brave") - implementation("ch.qos.logback:logback-classic") implementation("net.logstash.logback:logstash-logback-encoder:$logstashVersion") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1") diff --git a/src/main/kotlin/no/nav/klage/document/config/CustomTraceFilter.kt b/src/main/kotlin/no/nav/klage/document/config/CustomTraceFilter.kt deleted file mode 100644 index 08ee1c2..0000000 --- a/src/main/kotlin/no/nav/klage/document/config/CustomTraceFilter.kt +++ /dev/null @@ -1,36 +0,0 @@ -package no.nav.klage.document.config - -import io.micrometer.tracing.Tracer -import jakarta.servlet.FilterChain -import jakarta.servlet.ServletRequest -import jakarta.servlet.ServletResponse -import org.springframework.beans.factory.annotation.Value -import org.springframework.context.annotation.Profile -import org.springframework.core.annotation.Order -import org.springframework.stereotype.Component -import org.springframework.web.filter.GenericFilterBean - -/** - * Adding some custom NAV-specific attributes to standard Spring Sleuth/Micrometer - */ -@Component -@Profile("!local") -@Order(-20) -class CustomTraceFilter( - private val tracer: Tracer, - @Value("\${navCallIdName}") private val navCallIdName: String, -) : GenericFilterBean() { - - override fun doFilter( - request: ServletRequest?, response: ServletResponse, - chain: FilterChain - ) { - //Create if not exists - tracer.createBaggageInScope(navCallIdName, tracer.currentTraceContext().context()!!.traceId()) - - //also add this, since some services require that version/spelling - tracer.createBaggageInScope("Nav-Call-Id", tracer.currentTraceContext().context()!!.traceId()) - - chain.doFilter(request, response) - } -} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2068f50..713215d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,14 +3,6 @@ spring: name: kabal-smart-editor-api main: banner-mode: OFF - sleuth: - baggage: - remote-fields: - - Nav-Callid - - Nav-Consumer-Id - correlation-fields: - - Nav-Callid - - Nav-Consumer-Id mvc: throw-exception-if-no-handler-found: true lifecycle: @@ -44,8 +36,6 @@ server: enabled: false shutdown: graceful -navCallIdName: Nav-Callid - management: endpoint: health: @@ -62,12 +52,7 @@ management: export: enabled: true tracing: - baggage: - remote-fields: - - ${navCallIdName} - correlation: - fields: - - ${navCallIdName} + enabled: false no.nav.security.jwt: issuer: From 7441ca9f0c1f33f7757450167e1165df72f837e3 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 26 Sep 2024 22:20:28 +0200 Subject: [PATCH 07/10] Reverting replicas, but making sure we can handle it in dev. --- deploy/nais.yaml | 4 ++-- src/main/resources/application-dev-gcp.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy/nais.yaml b/deploy/nais.yaml index 6e22353..94e1c2d 100644 --- a/deploy/nais.yaml +++ b/deploy/nais.yaml @@ -57,8 +57,8 @@ spec: - {{ingress}} {{/each}} replicas: - min: 1 - max: 3 + min: 2 + max: 4 cpuThresholdPercentage: 80 prometheus: enabled: true diff --git a/src/main/resources/application-dev-gcp.yml b/src/main/resources/application-dev-gcp.yml index 439d95b..5c376bf 100644 --- a/src/main/resources/application-dev-gcp.yml +++ b/src/main/resources/application-dev-gcp.yml @@ -1,4 +1,4 @@ spring: datasource: hikari: - maximum-pool-size: 5 \ No newline at end of file + maximum-pool-size: 4 \ No newline at end of file From f7ccee794844587ed37394edb4127f38f3925036 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Fri, 27 Sep 2024 10:09:03 +0200 Subject: [PATCH 08/10] Moving `data` to document instead of version. --- .../klage/document/api/DocumentController.kt | 59 +++--------- .../no/nav/klage/document/domain/Document.kt | 6 +- .../klage/document/domain/DocumentVersion.kt | 4 +- .../klage/document/service/DocumentService.kt | 92 +++++++++++++------ src/main/resources/application.yml | 10 +- .../resources/db/migration/V7__Move_data.sql | 7 ++ .../document/repositories/RepositoryTest.kt | 12 +-- 7 files changed, 97 insertions(+), 93 deletions(-) create mode 100644 src/main/resources/db/migration/V7__Move_data.sql diff --git a/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt b/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt index 599a5cf..c7a623c 100644 --- a/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt +++ b/src/main/kotlin/no/nav/klage/document/api/DocumentController.kt @@ -6,8 +6,6 @@ import no.nav.klage.document.api.views.DocumentUpdateInput import no.nav.klage.document.api.views.DocumentVersionView import no.nav.klage.document.api.views.DocumentView import no.nav.klage.document.config.SecurityConfiguration.Companion.ISSUER_AAD -import no.nav.klage.document.domain.DocumentVersion -import no.nav.klage.document.domain.ShortDocumentVersion import no.nav.klage.document.service.DocumentService import no.nav.klage.document.util.TokenUtil import no.nav.klage.document.util.getLogger @@ -41,7 +39,7 @@ class DocumentController( ): DocumentView { log("createDocument") secureLogger.debug("createDocument: received json: {}", input.json) - return mapToDocumentView(documentService.createDocument(json = input.json, data = input.data)) + return documentService.createDocument(json = input.json, data = input.data) } @Operation( @@ -62,24 +60,20 @@ class DocumentController( ) return try { - mapToDocumentView( - documentService.updateDocument( - documentId = documentId, - json = input.json, - data = input.data, - currentVersion = input.currentVersion, - ) + documentService.updateDocument( + documentId = documentId, + json = input.json, + data = input.data, + currentVersion = input.currentVersion, ) + } catch (e: Exception) { logger.warn("Failed to update document $documentId. Trying one more time.", e) - - mapToDocumentView( - documentService.updateDocument( - documentId = documentId, - json = input.json, - data = input.data, - currentVersion = input.currentVersion, - ) + documentService.updateDocument( + documentId = documentId, + json = input.json, + data = input.data, + currentVersion = input.currentVersion, ) } } @@ -94,7 +88,7 @@ class DocumentController( @PathVariable("version", required = false) version: Int?, ): DocumentView { log("getDocument called with id $documentId and version $version") - return mapToDocumentView(documentService.getDocument(documentId = documentId, version = version)) + return documentService.getDocument(documentId = documentId, version = version) } @Operation( @@ -114,34 +108,9 @@ class DocumentController( @GetMapping("/{documentId}/versions") fun getDocumentVersions(@PathVariable("documentId") documentId: UUID): List { log("getDocumentVersions called with id $documentId") - val documentVersions = documentService.getDocumentVersions(documentId = documentId) - - return documentVersions.map { - mapToDocumentVersionView(it) - } + return documentService.getDocumentVersions(documentId = documentId) } - private fun mapToDocumentView(documentVersion: DocumentVersion): DocumentView = - DocumentView( - id = documentVersion.documentId, - documentId = documentVersion.documentId, - version = documentVersion.version, - json = documentVersion.json, - data = documentVersion.data, - authorNavIdent = documentVersion.authorNavIdent, - created = documentVersion.created, - modified = documentVersion.modified - ) - - private fun mapToDocumentVersionView(documentVersion: ShortDocumentVersion): DocumentVersionView = - DocumentVersionView( - documentId = documentVersion.documentId, - version = documentVersion.version, - authorNavIdent = documentVersion.authorNavIdent, - created = documentVersion.created, - modified = documentVersion.modified - ) - private fun log(message: String) { logger.debug(message) secureLogger.debug("{}. On-behalf-of: {}", message, tokenUtil.getIdentNullable()) diff --git a/src/main/kotlin/no/nav/klage/document/domain/Document.kt b/src/main/kotlin/no/nav/klage/document/domain/Document.kt index 820ac8b..3b7b386 100644 --- a/src/main/kotlin/no/nav/klage/document/domain/Document.kt +++ b/src/main/kotlin/no/nav/klage/document/domain/Document.kt @@ -12,6 +12,8 @@ import java.util.* class Document( @Id val id: UUID = UUID.randomUUID(), + @Column(name = "data") + var data: String?, @Column(name = "created") val created: LocalDateTime, @Column(name = "modified") @@ -23,9 +25,7 @@ class Document( other as Document - if (id != other.id) return false - - return true + return id == other.id } override fun hashCode(): Int { diff --git a/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt b/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt index 45f4e8f..0a70805 100644 --- a/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt +++ b/src/main/kotlin/no/nav/klage/document/domain/DocumentVersion.kt @@ -14,8 +14,6 @@ class DocumentVersion( val version: Int, @Column(name = "json") var json: String, - @Column(name = "data") - var data: String?, @Column(name = "created") val created: LocalDateTime, @Column(name = "modified") @@ -40,7 +38,7 @@ class DocumentVersion( } override fun toString(): String { - return "DocumentVersion(documentId=$documentId, version=$version, json='$json', data=$data, created=$created, modified=$modified, authorNavIdent='$authorNavIdent')" + return "DocumentVersion(documentId=$documentId, version=$version, json='$json', created=$created, modified=$modified, authorNavIdent='$authorNavIdent')" } } diff --git a/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt b/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt index dab71d2..a25901e 100644 --- a/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt +++ b/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt @@ -1,5 +1,7 @@ package no.nav.klage.document.service +import no.nav.klage.document.api.views.DocumentVersionView +import no.nav.klage.document.api.views.DocumentView import no.nav.klage.document.domain.Document import no.nav.klage.document.domain.DocumentVersion import no.nav.klage.document.domain.DocumentVersionId @@ -32,30 +34,33 @@ class DocumentService( private val secureLogger = getSecureLogger() } - fun createDocument(json: String, data: String?): DocumentVersion { + fun createDocument(json: String, data: String?): DocumentView { val now = LocalDateTime.now() val document = documentRepository.save( Document( + data = data, created = now, modified = now, ) ) - return documentVersionRepository.save( - DocumentVersion( - documentId = document.id, - version = 1, - json = json, - data = data, - authorNavIdent = tokenUtil.getIdent(), - created = now, - modified = now, - ) + return mapToDocumentView( + documentVersionRepository.save( + DocumentVersion( + documentId = document.id, + version = 1, + json = json, + authorNavIdent = tokenUtil.getIdent(), + created = now, + modified = now, + ) + ), + document = document ) } - fun updateDocument(documentId: UUID, json: String, data: String?, currentVersion: Int?): DocumentVersion { + fun updateDocument(documentId: UUID, json: String, data: String?, currentVersion: Int?): DocumentView { val now = LocalDateTime.now() val latestVersionNumber = latestDocumentRepository.findById(documentId).get().currentVersion @@ -84,27 +89,32 @@ class DocumentService( version = latestVersionNumber ) ).get() - return documentVersionRepository.save( - DocumentVersion( - documentId = documentVersion.documentId, - version = latestVersionNumber + 1, - json = json, - data = data, - created = now, - modified = now, - authorNavIdent = tokenUtil.getIdent() - ) + return mapToDocumentView( + documentVersion = documentVersionRepository.save( + DocumentVersion( + documentId = documentVersion.documentId, + version = latestVersionNumber + 1, + json = json, + created = now, + modified = now, + authorNavIdent = tokenUtil.getIdent() + ) + ), + document = documentRepository.findById(documentId).get() ) } - fun getDocument(documentId: UUID, version: Int?): DocumentVersion { + fun getDocument(documentId: UUID, version: Int?): DocumentView { val versionToUse = version ?: latestDocumentRepository.findById(documentId).get().currentVersion - return documentVersionRepository.findById( - DocumentVersionId( - documentId = documentId, - version = versionToUse - ) - ).get() + return mapToDocumentView( + documentVersion = documentVersionRepository.findById( + DocumentVersionId( + documentId = documentId, + version = versionToUse + ) + ).get(), + document = documentRepository.findById(documentId).get() + ) } fun deleteDocument(documentId: UUID) { @@ -114,8 +124,30 @@ class DocumentService( documentRepository.deleteById(documentId) } - fun getDocumentVersions(documentId: UUID): List { + fun getDocumentVersions(documentId: UUID): List { return documentVersionRepository.findVersionsByDocumentId(documentId = documentId) + .map { mapToDocumentVersionView(it) } } + private fun mapToDocumentView(documentVersion: DocumentVersion, document: Document): DocumentView = + DocumentView( + id = documentVersion.documentId, + documentId = documentVersion.documentId, + version = documentVersion.version, + json = documentVersion.json, + data = document.data, + authorNavIdent = documentVersion.authorNavIdent, + created = documentVersion.created, + modified = documentVersion.modified + ) + + private fun mapToDocumentVersionView(documentVersion: ShortDocumentVersion): DocumentVersionView = + DocumentVersionView( + documentId = documentVersion.documentId, + version = documentVersion.version, + authorNavIdent = documentVersion.authorNavIdent, + created = documentVersion.created, + modified = documentVersion.modified + ) + } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 713215d..113072f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,12 +7,8 @@ spring: throw-exception-if-no-handler-found: true lifecycle: timeout-per-shutdown-phase: 20s - servlet: - multipart: - max-request-size: 8MB - max-file-size: 8MB codec: - max-in-memory-size: 16MB + max-in-memory-size: 32MB datasource: url: jdbc:postgresql://${NAIS_DATABASE_KABAL_SMART_EDITOR_API_KABAL_SMART_EDITOR_API_HOST}:${NAIS_DATABASE_KABAL_SMART_EDITOR_API_KABAL_SMART_EDITOR_API_PORT}/${NAIS_DATABASE_KABAL_SMART_EDITOR_API_KABAL_SMART_EDITOR_API_DATABASE} username: ${NAIS_DATABASE_KABAL_SMART_EDITOR_API_KABAL_SMART_EDITOR_API_USERNAME} @@ -20,7 +16,7 @@ spring: driver-class-name: org.postgresql.Driver flyway: enabled: true - clean-on-validation-error: true + clean-on-validation-error: false schemas: flyway_history_schema,klage sql: init: @@ -28,6 +24,8 @@ spring: web: resources: add-mappings: false + jpa: + open-in-view: false server: port: 7095 diff --git a/src/main/resources/db/migration/V7__Move_data.sql b/src/main/resources/db/migration/V7__Move_data.sql new file mode 100644 index 0000000..aef9a0f --- /dev/null +++ b/src/main/resources/db/migration/V7__Move_data.sql @@ -0,0 +1,7 @@ +ALTER TABLE klage.document_version + DROP COLUMN data +; + +ALTER TABLE klage.document + ADD COLUMN data TEXT +; \ No newline at end of file diff --git a/src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt b/src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt index daf1283..5fe12dd 100644 --- a/src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt +++ b/src/test/kotlin/no/nav/klage/document/repositories/RepositoryTest.kt @@ -47,6 +47,7 @@ class RepositoryTest { val document = testEntityManager.persistAndFlush( Document( + data = "{}", created = now, modified = now, ) @@ -58,7 +59,6 @@ class RepositoryTest { version = 1, authorNavIdent = "abc", json = "{}", - data = "{}", created = now, modified = now, ) @@ -127,6 +127,7 @@ class RepositoryTest { val document = testEntityManager.persistAndFlush( Document( + data = "{}", created = now, modified = now, ) @@ -191,6 +192,7 @@ class RepositoryTest { val document = testEntityManager.persistAndFlush( Document( + data = "{}", created = now, modified = now, ) @@ -202,7 +204,6 @@ class RepositoryTest { version = 1, authorNavIdent = "abc", json = "{}", - data = "{}", created = now, modified = now, ) @@ -214,7 +215,6 @@ class RepositoryTest { version = 2, authorNavIdent = "abc", json = "{}", - data = "{}", created = now, modified = now, ) @@ -239,6 +239,7 @@ class RepositoryTest { val document1 = testEntityManager.persistAndFlush( Document( + data = "{}", created = now, modified = now, ) @@ -246,6 +247,7 @@ class RepositoryTest { val document2 = testEntityManager.persistAndFlush( Document( + data = "{}", created = now, modified = now, ) @@ -261,7 +263,6 @@ class RepositoryTest { version = it + 1, authorNavIdent = "abc", json = "{}", - data = "{}", created = now, modified = now, ) @@ -275,7 +276,6 @@ class RepositoryTest { version = it + 1, authorNavIdent = "abc", json = "{}", - data = "{}", created = now, modified = now, ) @@ -291,4 +291,4 @@ class RepositoryTest { assertThat(latestVersionNumberDocument2).isEqualTo(numberOfDocumenVersionsToCreateDocument2) } -} +} \ No newline at end of file From af3ac4e1f052f78f28aec14027c6f6fefa3bf348 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Mon, 30 Sep 2024 11:38:28 +0200 Subject: [PATCH 09/10] Added back Prometheus. --- build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 86583ce..16360cc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,6 +40,8 @@ dependencies { implementation("com.zaxxer:HikariCP") implementation("org.postgresql:postgresql") + implementation("io.micrometer:micrometer-registry-prometheus") + implementation("ch.qos.logback:logback-classic") implementation("net.logstash.logback:logstash-logback-encoder:$logstashVersion") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1") From ee0a1a745fd7b29926d8ad5e080f096bfce4a89b Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Mon, 30 Sep 2024 12:07:30 +0200 Subject: [PATCH 10/10] Update `data`. --- .../no/nav/klage/document/service/DocumentService.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt b/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt index a25901e..8cd36f5 100644 --- a/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt +++ b/src/main/kotlin/no/nav/klage/document/service/DocumentService.kt @@ -89,6 +89,11 @@ class DocumentService( version = latestVersionNumber ) ).get() + + val document = documentRepository.findById(documentId).get() + document.data = data + document.modified = now + return mapToDocumentView( documentVersion = documentVersionRepository.save( DocumentVersion( @@ -100,7 +105,7 @@ class DocumentService( authorNavIdent = tokenUtil.getIdent() ) ), - document = documentRepository.findById(documentId).get() + document = document ) }