Skip to content

Commit 9698245

Browse files
authored
chore(server): count calls to GitHub for static resources as metric (#2166)
Part of #2160. Thanks to this, we'll be able to assess the load on GitHub, and perhaps come up with reasons why the server has been unstable. This PR only deals with static resources. Fetching versions via API will be covered in another PR.
1 parent 87b5ebc commit 9698245

File tree

1 file changed

+15
-1
lines changed
  • jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver

1 file changed

+15
-1
lines changed

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import io.github.typesafegithub.workflows.mavenbinding.buildVersionArtifacts
1212
import io.github.typesafegithub.workflows.shared.internal.getGithubAuthToken
1313
import io.ktor.client.HttpClient
1414
import io.ktor.client.engine.cio.CIO
15+
import io.ktor.client.plugins.HttpSend
16+
import io.ktor.client.plugins.plugin
1517
import io.ktor.http.HttpStatusCode
1618
import io.ktor.server.application.Application
1719
import io.ktor.server.application.ApplicationCall
@@ -66,7 +68,19 @@ fun Application.appModule(
6668
buildPackageArtifacts: suspend (ActionCoords, String, (Collection<ActionCoords>) -> Unit) -> Map<String, String>,
6769
getGithubAuthToken: () -> String,
6870
) {
69-
val httpClient = HttpClient(CIO)
71+
val httpClient =
72+
HttpClient(CIO).apply {
73+
plugin(HttpSend).intercept { request ->
74+
if (request.url.host == "raw.githubusercontent.com") {
75+
val counter =
76+
prometheusRegistry.counter(
77+
"calls_to_github",
78+
)
79+
counter.increment()
80+
}
81+
execute(request)
82+
}
83+
}
7084
val bindingsCache = buildBindingsCache(buildVersionArtifacts, httpClient)
7185
val metadataCache = buildMetadataCache(bindingsCache, buildPackageArtifacts, getGithubAuthToken)
7286
installPlugins(prometheusRegistry)

0 commit comments

Comments
 (0)