Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/maven/io.kotest-kotest-runner-jun…
Browse files Browse the repository at this point in the history
…it5-jvm-5.9.0
  • Loading branch information
stigebil authored May 14, 2024
2 parents cf0761e + 7943d92 commit 9c7b475
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfo
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

@Component
@ConditionalOnProperty("familie.tellAPIEndepunkterIBruk")
@ConditionalOnProperty("familie.tellAPIEndepunkterIBruk.enabled")
class TellAPIEndepunkterIBrukInitialiserer(
@Value("\${NAIS_APP_NAME}") private val applicationName: String,
private val applicationContext: ApplicationContext,
@Value("\${familie.tellAPIEndepunkterIBruk.paths:/api}") private val pathStartWidth: List<String>,
@Value("\${familie.tellAPIEndepunkterIBruk.ekskluder:/internal}") private val ekskludertePaths: List<String>,
) {
init {
metrikker.clear()
Expand All @@ -31,7 +31,7 @@ class TellAPIEndepunkterIBrukInitialiserer(

requestMappings.forEach { (info, handler) ->
info.patternValues.forEach { path ->
if (pathStartWidth.any { path.startsWith(it) }) {
if (ekskludertePaths.none { path.startsWith(it) }) {
val metrikknavn = "$applicationName.${info.methodsCondition}$path".tilMetrikknavn()
val key = "${info.methodsCondition}$path"
metrikker.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import org.springframework.web.servlet.AsyncHandlerInterceptor
import org.springframework.web.servlet.HandlerMapping

/**
* Sett property familie.tellAPIEndepunkterIBruk: true i application.yaml for å skru
* Sett property familie.tellAPIEndepunkterIBruk.enabled: true i application.yaml for å skru
* på metrikker for hvor mange ganger et endepunkt har blitt kalt
*
* For å konfigurere andre endepunkter enn de som starter på /api så kan man bruke
* familie.tellAPIEndepunkterIBruk.paths: /foo,/bar
* For å ekskludere endepunkter så kan man bruke
* familie.tellAPIEndepunkterIBruk.ekskluder: /foo,/bar
*
*/
@Component
@ConditionalOnProperty("familie.tellAPIEndepunkterIBruk")
@ConditionalOnProperty("familie.tellAPIEndepunkterIBruk.enabled")
class TellAPIEndepunkterIBrukInterceptor : AsyncHandlerInterceptor {
override fun preHandle(
request: HttpServletRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
@ConditionalOnProperty("familie.tellAPIEndepunkterIBruk")
@ConditionalOnProperty("familie.tellAPIEndepunkterIBruk.enabled")
open class TellAPIEndpunkterIBrukWebConfig : WebMvcConfigurer {
override fun addInterceptors(registry: InterceptorRegistry) {
registry.addInterceptor(TellAPIEndepunkterIBrukInterceptor()).addPathPatterns("/api/**")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class TellAPIEndepunkterIBrukTest {
fun `skal opprette map med key og counter når det finnes en requestmapping`() {
settOppTestData("/api/foo", RequestMethod.GET)

TellAPIEndepunkterIBrukInitialiserer("test", applicationContext, listOf("/api")).populerMapMedCountersForRestEndepunkt()
TellAPIEndepunkterIBrukInitialiserer(
"test",
applicationContext,
listOf("/internal"),
).populerMapMedCountersForRestEndepunkt()

assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter).hasSize(1)
assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter.containsKey("[GET]/api/foo")).isTrue()
Expand All @@ -39,7 +43,11 @@ class TellAPIEndepunkterIBrukTest {
fun `skal opprette map med key og counter når det finnes en requestmapping med pathParam og navnet på counteren saneres`() {
settOppTestData("/api/foo/{fooId}", RequestMethod.POST)

TellAPIEndepunkterIBrukInitialiserer("test", applicationContext, listOf("/api")).populerMapMedCountersForRestEndepunkt()
TellAPIEndepunkterIBrukInitialiserer(
"test",
applicationContext,
listOf("/internal"),
).populerMapMedCountersForRestEndepunkt()

assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter).hasSize(1)
assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter.containsKey("[POST]/api/foo/{fooId}")).isTrue()
Expand All @@ -52,7 +60,11 @@ class TellAPIEndepunkterIBrukTest {
fun `skal ikke opprette map med counter for annet enn pathparam som starter med api`() {
settOppTestData("/internal/foobar", RequestMethod.POST)

TellAPIEndepunkterIBrukInitialiserer("test", applicationContext, listOf("/api")).populerMapMedCountersForRestEndepunkt()
TellAPIEndepunkterIBrukInitialiserer(
"test",
applicationContext,
listOf("/internal"),
).populerMapMedCountersForRestEndepunkt()

assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter).hasSize(0)
}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

<kontrakter.version>3.0_20230428084827_0b6a892-JAKARTA</kontrakter.version>
<kotest.version>5.9.0</kotest.version>
<kotlin.version>1.9.23</kotlin.version>
<kotlin.version>1.9.24</kotlin.version>
<mockk.version>1.13.10</mockk.version>
<nav.security.token.version>4.1.4</nav.security.token.version>
<wiremock.version>3.5.3</wiremock.version>
<wiremock.version>3.5.4</wiremock.version>
</properties>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion unleash/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>io.getunleash</groupId>
<artifactId>unleash-client-java</artifactId>
<version>9.2.0</version>
<version>9.2.1</version>
</dependency>
</dependencies>

Expand Down

0 comments on commit 9c7b475

Please sign in to comment.