Skip to content

Commit

Permalink
Bump felles.version og ktlint (#958)
Browse files Browse the repository at this point in the history
Co-authored-by: Stig Helge Strøm <stig.helge.strom@nav.no>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
dependabot[bot] and stigebil authored Oct 20, 2023
1 parent 185c1ae commit 56ffcb7
Show file tree
Hide file tree
Showing 108 changed files with 2,657 additions and 2,229 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
max_line_length = off
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<mockk.version>1.13.8</mockk.version>
<confluent.version>7.5.1</confluent.version>
<prosessering.version>2.20231006130620_9b45ded</prosessering.version>
<felles.version>2.20230905101454_06fa3d7</felles.version>
<felles.version>2.20231019114030_ef92457</felles.version>
<kontrakter.version>3.0_20230921075936_3adfc44</kontrakter.version>
<main-class>no.nav.familie.baks.mottak.LauncherKt</main-class>
<spring.cloud.version>4.0.4</spring.cloud.version>
Expand Down Expand Up @@ -419,9 +419,9 @@
</executions>
<dependencies>
<dependency>
<groupId>com.pinterest</groupId>
<artifactId>ktlint</artifactId>
<version>0.50.0</version>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-cli</artifactId>
<version>1.0.1</version>
</dependency>
<!-- additional 3rd party ruleset(s) can be specified here -->
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import java.time.temporal.ChronoUnit
@EnableOAuth2Client(cacheEnabled = true)
@EnableRetry
class ApplicationConfig {

@Bean
fun servletWebServerFactory(): ServletWebServerFactory {
return JettyServletWebServerFactory()
Expand Down Expand Up @@ -86,11 +85,12 @@ class ApplicationConfig {
fun prosesseringInfoProvider(
@Value("\${prosessering.rolle}") prosesseringRolle: String,
) = object : ProsesseringInfoProvider {
override fun hentBrukernavn(): String = try {
SpringTokenValidationContextHolder().tokenValidationContext.getClaims("azuread").getStringClaim("preferred_username")
} catch (e: Exception) {
"VL"
}
override fun hentBrukernavn(): String =
try {
SpringTokenValidationContextHolder().tokenValidationContext.getClaims("azuread").getStringClaim("preferred_username")
} catch (e: Exception) {
"VL"
}

override fun harTilgang(): Boolean = grupper().contains(prosesseringRolle)

Expand Down
45 changes: 24 additions & 21 deletions src/main/kotlin/no/nav/familie/baks/mottak/config/CacheConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,34 @@ import java.util.concurrent.TimeUnit
@Configuration
@EnableCaching
class CacheConfig {

@Bean
fun dailyCacheManager(): CacheManager = object : ConcurrentMapCacheManager() {
override fun createConcurrentMapCache(name: String): Cache {
val concurrentMap = Caffeine
.newBuilder()
.initialCapacity(100)
.maximumSize(1000)
.expireAfterWrite(24, TimeUnit.HOURS)
.recordStats().build<Any, Any>().asMap()
return ConcurrentMapCache(name, concurrentMap, true)
fun dailyCacheManager(): CacheManager =
object : ConcurrentMapCacheManager() {
override fun createConcurrentMapCache(name: String): Cache {
val concurrentMap =
Caffeine
.newBuilder()
.initialCapacity(100)
.maximumSize(1000)
.expireAfterWrite(24, TimeUnit.HOURS)
.recordStats().build<Any, Any>().asMap()
return ConcurrentMapCache(name, concurrentMap, true)
}
}
}

@Bean
@Primary
fun hourlyCacheManager(): CacheManager = object : ConcurrentMapCacheManager() {
override fun createConcurrentMapCache(name: String): Cache {
val concurrentMap = Caffeine
.newBuilder()
.initialCapacity(100)
.maximumSize(1000)
.expireAfterWrite(1, TimeUnit.HOURS)
.recordStats().build<Any, Any>().asMap()
return ConcurrentMapCache(name, concurrentMap, true)
fun hourlyCacheManager(): CacheManager =
object : ConcurrentMapCacheManager() {
override fun createConcurrentMapCache(name: String): Cache {
val concurrentMap =
Caffeine
.newBuilder()
.initialCapacity(100)
.maximumSize(1000)
.expireAfterWrite(1, TimeUnit.HOURS)
.recordStats().build<Any, Any>().asMap()
return ConcurrentMapCache(name, concurrentMap, true)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import java.time.Duration
matchIfMissing = true,
)
class KafkaAivenConfig(val environment: Environment) {

@Bean
fun kafkaAivenHendelseListenerContainerFactory(kafkaRestartingErrorHandler: KafkaRestartingErrorHandler): ConcurrentKafkaListenerContainerFactory<String, String> {
val factory = ConcurrentKafkaListenerContainerFactory<String, String>()
Expand Down Expand Up @@ -61,15 +60,16 @@ class KafkaAivenConfig(val environment: Environment) {

private fun consumerConfigs(): Map<String, Any> {
val kafkaBrokers = System.getenv("KAFKA_BROKERS") ?: "http://localhost:9092"
val consumerConfigs = mutableMapOf(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaBrokers,
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
ConsumerConfig.CLIENT_ID_CONFIG to "consumer-familie-baks-mottak-1",
ConsumerConfig.MAX_POLL_RECORDS_CONFIG to "50",
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG to "latest",
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG to false,
)
val consumerConfigs =
mutableMapOf(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaBrokers,
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
ConsumerConfig.CLIENT_ID_CONFIG to "consumer-familie-baks-mottak-1",
ConsumerConfig.MAX_POLL_RECORDS_CONFIG to "50",
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG to "latest",
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG to false,
)
if (environment.activeProfiles.none { it.contains("dev") || it.contains("postgres") }) {
return consumerConfigs + securityConfig()
}
Expand All @@ -81,19 +81,20 @@ class KafkaAivenConfig(val environment: Environment) {
val schemaRegisty = System.getenv("KAFKA_SCHEMA_REGISTRY") ?: "http://localhost:9093"
val schemaRegistryUser = System.getenv("KAFKA_SCHEMA_REGISTRY_USER") ?: "mangler i pod"
val schemaRegistryPassword = System.getenv("KAFKA_SCHEMA_REGISTRY_PASSWORD") ?: "mangler i pod"
val consumerConfigs = mutableMapOf(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaBrokers,
"schema.registry.url" to schemaRegisty,
"basic.auth.credentials.source" to "USER_INFO",
"basic.auth.user.info" to "$schemaRegistryUser:$schemaRegistryPassword",
"specific.avro.reader" to true,
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to KafkaAvroDeserializer::class.java,
ConsumerConfig.CLIENT_ID_CONFIG to "consumer-familie-baks-mottak-2",
ConsumerConfig.MAX_POLL_RECORDS_CONFIG to "1",
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG to "latest",
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG to "false",
)
val consumerConfigs =
mutableMapOf(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaBrokers,
"schema.registry.url" to schemaRegisty,
"basic.auth.credentials.source" to "USER_INFO",
"basic.auth.user.info" to "$schemaRegistryUser:$schemaRegistryPassword",
"specific.avro.reader" to true,
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to KafkaAvroDeserializer::class.java,
ConsumerConfig.CLIENT_ID_CONFIG to "consumer-familie-baks-mottak-2",
ConsumerConfig.MAX_POLL_RECORDS_CONFIG to "1",
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG to "latest",
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG to "false",
)
if (environment.activeProfiles.none { it.contains("dev") || it.contains("postgres") }) {
return consumerConfigs + securityConfig()
}
Expand All @@ -105,19 +106,20 @@ class KafkaAivenConfig(val environment: Environment) {
val schemaRegisty = System.getenv("KAFKA_SCHEMA_REGISTRY") ?: "http://localhost:9093"
val schemaRegistryUser = System.getenv("KAFKA_SCHEMA_REGISTRY_USER") ?: "mangler i pod"
val schemaRegistryPassword = System.getenv("KAFKA_SCHEMA_REGISTRY_PASSWORD") ?: "mangler i pod"
val consumerConfigs = mutableMapOf(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaBrokers,
"schema.registry.url" to schemaRegisty,
"basic.auth.credentials.source" to "USER_INFO",
"basic.auth.user.info" to "$schemaRegistryUser:$schemaRegistryPassword",
"specific.avro.reader" to true,
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to KafkaAvroDeserializer::class.java,
ConsumerConfig.CLIENT_ID_CONFIG to "consumer-familie-baks-mottak-2",
ConsumerConfig.MAX_POLL_RECORDS_CONFIG to "50",
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG to "earliest",
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG to false,
)
val consumerConfigs =
mutableMapOf(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaBrokers,
"schema.registry.url" to schemaRegisty,
"basic.auth.credentials.source" to "USER_INFO",
"basic.auth.user.info" to "$schemaRegistryUser:$schemaRegistryPassword",
"specific.avro.reader" to true,
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to KafkaAvroDeserializer::class.java,
ConsumerConfig.CLIENT_ID_CONFIG to "consumer-familie-baks-mottak-2",
ConsumerConfig.MAX_POLL_RECORDS_CONFIG to "50",
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG to "earliest",
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG to false,
)
if (environment.activeProfiles.none { it.contains("dev") || it.contains("postgres") }) {
return consumerConfigs + securityConfig()
}
Expand All @@ -130,7 +132,8 @@ class KafkaAivenConfig(val environment: Environment) {
val kafkaKeystorePath = System.getenv("KAFKA_KEYSTORE_PATH")
return mapOf(
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG to "SSL",
SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG to "", // Disable server host name verification
// Disable server host name verification
SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG to "",
SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG to "JKS",
SslConfigs.SSL_KEYSTORE_TYPE_CONFIG to "PKCS12",
SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG to kafkaTruststorePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import java.util.concurrent.atomic.AtomicLong
*/
@Component
class KafkaRestartingErrorHandler : CommonContainerStoppingErrorHandler() {

val LOGGER: Logger = LoggerFactory.getLogger(KafkaRestartingErrorHandler::class.java)
val SECURE_LOGGER: Logger = LoggerFactory.getLogger("secureLogger")
val logger: Logger = LoggerFactory.getLogger(KafkaRestartingErrorHandler::class.java)
val secureLogger: Logger = LoggerFactory.getLogger("secureLogger")

private val executor: Executor
private val counter = AtomicInteger(0)
private val lastError = AtomicLong(0)

override fun handleRemaining(
e: Exception,
records: List<ConsumerRecord<*, *>>?,
Expand All @@ -36,19 +36,19 @@ class KafkaRestartingErrorHandler : CommonContainerStoppingErrorHandler() {
Thread.sleep(1000)

if (records.isNullOrEmpty()) {
LOGGER.warn("Feil ved konsumering av melding. Ingen records. ${consumer.subscription()}", e)
logger.warn("Feil ved konsumering av melding. Ingen records. ${consumer.subscription()}", e)
scheduleRestart(
e,
container,
"Ukjent topic",
)
} else {
records.first().run {
LOGGER.warn(
logger.warn(
"Feil ved konsumering av melding fra ${this.topic()}. id ${this.key()}, " +
"offset: ${this.offset()}, partition: ${this.partition()}",
)
SECURE_LOGGER.warn("${this.topic()} - Problemer med prosessering av $records", e)
secureLogger.warn("${this.topic()} - Problemer med prosessering av $records", e)
scheduleRestart(
e,
container,
Expand All @@ -66,7 +66,7 @@ class KafkaRestartingErrorHandler : CommonContainerStoppingErrorHandler() {
val now = System.currentTimeMillis()
if (now - lastError.getAndSet(now) > COUNTER_RESET_TIME) { // Sjekker om perioden som det ventes er større enn counter_reset_time
if (counter.get() > 0) {
LOGGER.error(
logger.error(
"Feil ved prosessering av kafkamelding for $topic. Container har restartet ${counter.get()} ganger og " +
"man må se på hvorfor record ikke kan leses. " +
"Hvis denne meldingen gjentar seg hver ${Duration.ofMillis(LONG_SLEEP)} så klarer ikke tjenesten å hente seg inn",
Expand All @@ -80,10 +80,10 @@ class KafkaRestartingErrorHandler : CommonContainerStoppingErrorHandler() {
executor.execute {
try {
Thread.sleep(stopTime)
LOGGER.info("Starter kafka container for $topic")
logger.info("Starter kafka container for $topic")
container.start()
} catch (exception: Exception) {
LOGGER.error("Feil oppstod ved venting og oppstart av kafka container", exception)
logger.error("Feil oppstod ved venting og oppstart av kafka container", exception)
}
}
stopContainer(container) // i stedet for stopContainer i handleRemaining i parent som kaster error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.springframework.web.client.RestOperations
RestTemplateSts::class,
)
class RestTemplateConfig {

@Profile("!dev || !e2e || !postgres")
@Bean("clientCredentials")
fun restTemplateClientCredentials(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import java.net.URI

@Configuration
class StsRestClientConfig {

@Bean
@Autowired
@Profile("!mock-sts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,20 @@ import java.util.Properties
data class Hendelseslogg(
@Column(name = "kafka_offset")
val offset: Long,

@Column(name = "hendelse_id")
val hendelseId: String,

@Enumerated(EnumType.STRING)
@Column(name = "consumer")
val consumer: HendelseConsumer,

@Convert(converter = PropertiesToStringConverter::class)
@Column(name = "metadata")
val metadata: Properties = Properties(),

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hendelseslogg_seq")
@SequenceGenerator(name = "hendelseslogg_seq")
val id: Long? = null,

@Column(name = "opprettet_tid", nullable = false, updatable = false)
val opprettetTidspunkt: LocalDateTime = LocalDateTime.now(),

@Column(name = "ident", nullable = true)
val ident: String? = null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import org.springframework.stereotype.Repository

@Repository
interface HendelsesloggRepository : JpaRepository<Hendelseslogg, Long> {

@Lock(LockModeType.PESSIMISTIC_FORCE_INCREMENT)
fun save(hendelseslogg: Hendelseslogg): Hendelseslogg

fun existsByHendelseIdAndConsumer(hendelseId: String, consumer: HendelseConsumer): Boolean
fun existsByHendelseIdAndConsumer(
hendelseId: String,
consumer: HendelseConsumer,
): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ data class PdlHendelse(
val sivilstand: String? = null,
val sivilstandDato: LocalDate? = null,
) {

// TODO: Skal gjøres tydeligere og mer robust.
fun hentPersonident() = personIdenter.first { it.length == 11 }

fun hentPersonidenter() = personIdenter.filter { it.length == 11 }
}
Loading

0 comments on commit 56ffcb7

Please sign in to comment.