Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Optional
import kotlin.jvm.optionals.getOrNull

private val logger = logger { }

typealias CachedVersionArtifact = VersionArtifacts?
typealias CachedVersionArtifact = Optional<VersionArtifacts>

private val prefetchScope = CoroutineScope(Dispatchers.IO)

Expand Down Expand Up @@ -120,7 +122,7 @@ private suspend fun ApplicationCall.toBindingArtifacts(
if (refresh) {
bindingsCache.invalidate(actionCoords)
}
return bindingsCache.get(actionCoords)
return bindingsCache.get(actionCoords).getOrNull()
}

private fun PrometheusMeterRegistry.incrementArtifactCounter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.micrometer.core.instrument.Tag
import io.micrometer.prometheusmetrics.PrometheusConfig
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import java.time.Duration
import java.util.Optional
import kotlin.time.Duration.Companion.hours

private val logger =
Expand Down Expand Up @@ -109,7 +110,7 @@ private fun buildBindingsCache(
.newBuilder()
.refreshAfterWrite(1.hours)
.recordStats()
.asLoadingCache<ActionCoords, CachedVersionArtifact> { buildVersionArtifacts(it, httpClient) }
.asLoadingCache { Optional.ofNullable(buildVersionArtifacts(it, httpClient)) }

@Suppress("ktlint:standard:function-signature") // Conflict with detekt.
private fun buildMetadataCache(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ class ArtifactRoutesTest :
// Then
response2.status shouldBe HttpStatusCode.NotFound

// This test shows the current behavior where requesting a resource
// that doesn't exist twice in a row causes calling the version artifact
// twice.
// Fix in scope of https://github.com/typesafegithub/github-workflows-kt/issues/2160
verify(exactly = 2) { mockBuildVersionArtifacts(any(), any()) }
// The fact that the resource doesn't exist is cached, and the
// resource generation logic isn't called in the second request.
verify(exactly = 1) { mockBuildVersionArtifacts(any(), any()) }
}
}

Expand Down
Loading