Skip to content

Commit

Permalink
Mulighet til å konfigurere hvilke endepunkt man skal lage metrikker med
Browse files Browse the repository at this point in the history
  • Loading branch information
stigebil committed Apr 18, 2024
1 parent e60e612 commit b67a282
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
class TellAPIEndepunkterIBrukInitialiserer(
@Value("\${NAIS_APP_NAME}") private val applicationName: String,
private val applicationContext: ApplicationContext,
@Value("\${familie.tellAPIEndepunkterIBruk.paths:/api}") private val pathStartWidth: List<String>,
) {
init {
metrikker.clear()
Expand All @@ -30,7 +31,7 @@ class TellAPIEndepunkterIBrukInitialiserer(

requestMappings.forEach { (info, handler) ->
info.patternValues.forEach { path ->
if (path.startsWith("/api")) {
if (pathStartWidth.any { 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 @@ -10,6 +10,10 @@ import org.springframework.web.servlet.HandlerMapping
/**
* Sett property familie.tellAPIEndepunkterIBruk: 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
*
*/
@Component
@ConditionalOnProperty("familie.tellAPIEndepunkterIBruk")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TellAPIEndepunkterIBrukTest {
fun `skal opprette map med key og counter når det finnes en requestmapping`() {
settOppTestData("/api/foo", RequestMethod.GET)

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

assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter).hasSize(1)
assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter.containsKey("[GET]/api/foo")).isTrue()
Expand All @@ -39,7 +39,7 @@ 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).populerMapMedCountersForRestEndepunkt()
TellAPIEndepunkterIBrukInitialiserer("test", applicationContext, listOf("/api")).populerMapMedCountersForRestEndepunkt()

assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter).hasSize(1)
assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter.containsKey("[POST]/api/foo/{fooId}")).isTrue()
Expand All @@ -52,7 +52,7 @@ 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).populerMapMedCountersForRestEndepunkt()
TellAPIEndepunkterIBrukInitialiserer("test", applicationContext, listOf("/api")).populerMapMedCountersForRestEndepunkt()

assertThat(TellAPIEndepunkterIBrukInitialiserer.metrikkerForEndepunkter).hasSize(0)
}
Expand Down

0 comments on commit b67a282

Please sign in to comment.