From 444f1a58b5fe415f9ff9430423405aea629a75e4 Mon Sep 17 00:00:00 2001 From: Piotr Krzeminski Date: Mon, 15 Dec 2025 12:24:24 +0100 Subject: [PATCH] chore(server): count calls to GitHub as metric --- .../workflows/jitbindingserver/Main.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt index adde97a79..b50513a05 100644 --- a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt +++ b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt @@ -12,6 +12,8 @@ import io.github.typesafegithub.workflows.mavenbinding.buildVersionArtifacts import io.github.typesafegithub.workflows.shared.internal.getGithubAuthToken import io.ktor.client.HttpClient import io.ktor.client.engine.cio.CIO +import io.ktor.client.plugins.HttpSend +import io.ktor.client.plugins.plugin import io.ktor.http.HttpStatusCode import io.ktor.server.application.Application import io.ktor.server.application.ApplicationCall @@ -66,7 +68,19 @@ fun Application.appModule( buildPackageArtifacts: suspend (ActionCoords, String, (Collection) -> Unit) -> Map, getGithubAuthToken: () -> String, ) { - val httpClient = HttpClient(CIO) + val httpClient = + HttpClient(CIO).apply { + plugin(HttpSend).intercept { request -> + if (request.url.host == "raw.githubusercontent.com") { + val counter = + prometheusRegistry.counter( + "calls_to_github", + ) + counter.increment() + } + execute(request) + } + } val bindingsCache = buildBindingsCache(buildVersionArtifacts, httpClient) val metadataCache = buildMetadataCache(bindingsCache, buildPackageArtifacts, getGithubAuthToken) installPlugins(prometheusRegistry)