@@ -42,8 +42,10 @@ private val bindingsCache =
42
42
.recordStats()
43
43
.asLoadingCache<ActionCoords , ArtifactResult > { runCatching { it.buildVersionArtifacts()!! } }
44
44
45
- fun Routing.artifactRoutes (prometheusRegistry : PrometheusMeterRegistry ) {
46
- CaffeineCacheMetrics .monitor(prometheusRegistry, bindingsCache.underlying(), " bindings_cache" )
45
+ fun Routing.artifactRoutes (prometheusRegistry : PrometheusMeterRegistry ? = null) {
46
+ prometheusRegistry?.let {
47
+ CaffeineCacheMetrics .monitor(it, bindingsCache.underlying(), " bindings_cache" )
48
+ }
47
49
48
50
route(" {owner}/{name}/{version}/{file}" ) {
49
51
artifact(prometheusRegistry, refresh = false )
@@ -55,15 +57,15 @@ fun Routing.artifactRoutes(prometheusRegistry: PrometheusMeterRegistry) {
55
57
}
56
58
57
59
private fun Route.artifact (
58
- prometheusRegistry : PrometheusMeterRegistry ,
60
+ prometheusRegistry : PrometheusMeterRegistry ? ,
59
61
refresh : Boolean = false,
60
62
) {
61
63
headArtifact(prometheusRegistry, refresh)
62
64
getArtifact(prometheusRegistry, refresh)
63
65
}
64
66
65
67
private fun Route.headArtifact (
66
- prometheusRegistry : PrometheusMeterRegistry ,
68
+ prometheusRegistry : PrometheusMeterRegistry ? ,
67
69
refresh : Boolean ,
68
70
) {
69
71
head {
@@ -77,12 +79,12 @@ private fun Route.headArtifact(
77
79
call.respondNotFound()
78
80
}
79
81
80
- incrementArtifactCounter(prometheusRegistry, call)
82
+ prometheusRegistry?. incrementArtifactCounter(call)
81
83
}
82
84
}
83
85
84
86
private fun Route.getArtifact (
85
- prometheusRegistry : PrometheusMeterRegistry ,
87
+ prometheusRegistry : PrometheusMeterRegistry ? ,
86
88
refresh : Boolean ,
87
89
) {
88
90
get {
@@ -99,7 +101,7 @@ private fun Route.getArtifact(
99
101
is JarArtifact -> call.respondBytes(artifact.data(), ContentType .parse(" application/java-archive" ))
100
102
}
101
103
102
- incrementArtifactCounter(prometheusRegistry, call)
104
+ prometheusRegistry?. incrementArtifactCounter(call)
103
105
}
104
106
}
105
107
@@ -119,10 +121,7 @@ private suspend fun ApplicationCall.toBindingArtifacts(refresh: Boolean): Map<St
119
121
return bindingsCache.get(actionCoords).getOrNull()
120
122
}
121
123
122
- private fun incrementArtifactCounter (
123
- prometheusRegistry : PrometheusMeterRegistry ,
124
- call : ApplicationCall ,
125
- ) {
124
+ private fun PrometheusMeterRegistry.incrementArtifactCounter (call : ApplicationCall ) {
126
125
val owner = call.parameters[" owner" ] ? : " unknown"
127
126
val name = call.parameters[" name" ] ? : " unknown"
128
127
val version = call.parameters[" version" ] ? : " unknown"
@@ -135,7 +134,7 @@ private fun incrementArtifactCounter(
135
134
?.toString() ? : " unknown"
136
135
137
136
val counter =
138
- prometheusRegistry .counter(
137
+ this .counter(
139
138
" artifact_requests_total" ,
140
139
listOf (
141
140
Tag .of(" owner" , owner),
0 commit comments