-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: http4s-metrics module * feat: standard HTTP and JVM metrics * feat: search-api to expose the /metrics API * feat: search-provision to expose the /metrics API * feat: metrics for monitoring Redis queues
- Loading branch information
Showing
31 changed files
with
758 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
modules/http4s-commons/src/main/scala/io/renku/search/http/HttpServerConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.http | ||
|
||
import com.comcast.ip4s.{Ipv4Address, Port} | ||
|
||
final case class HttpServerConfig(bindAddress: Ipv4Address, port: Port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/http4s-metrics/src/main/scala/io/renku/search/http/metrics/MetricsRoutes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.http.metrics | ||
|
||
import cats.effect.{Resource, Sync} | ||
import cats.syntax.all.* | ||
import io.renku.search.metrics.CollectorRegistryBuilder | ||
import org.http4s.HttpRoutes | ||
import org.http4s.metrics.prometheus.{Prometheus, PrometheusExportService} | ||
import org.http4s.server.middleware.Metrics | ||
|
||
final class MetricsRoutes[F[_]: Sync](registryBuilder: CollectorRegistryBuilder[F]): | ||
|
||
def makeRoutes(measuredRoutes: HttpRoutes[F]): Resource[F, HttpRoutes[F]] = | ||
for | ||
registry <- registryBuilder.makeRegistry | ||
metrics <- Prometheus.metricsOps[F](registry, prefix = "server") | ||
yield PrometheusExportService(registry).routes <+> Metrics[F](metrics)(measuredRoutes) | ||
|
||
def makeRoutes: Resource[F, HttpRoutes[F]] = | ||
registryBuilder.makeRegistry.map(PrometheusExportService.apply).map(_.routes) |
24 changes: 24 additions & 0 deletions
24
modules/http4s-metrics/src/main/scala/io/renku/search/metrics/Collector.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.metrics | ||
|
||
import io.prometheus.client.Collector as JCollector | ||
|
||
trait Collector: | ||
def asJCollector: JCollector |
56 changes: 56 additions & 0 deletions
56
modules/http4s-metrics/src/main/scala/io/renku/search/metrics/CollectorRegistryBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.metrics | ||
|
||
import cats.effect.{Resource, Sync} | ||
import cats.syntax.all.* | ||
import io.prometheus.client.{CollectorRegistry, Collector as JCollector} | ||
import org.http4s.metrics.prometheus.PrometheusExportService | ||
|
||
final case class CollectorRegistryBuilder[F[_]: Sync]( | ||
collectors: Set[Collector], | ||
standardJVMMetrics: Boolean | ||
): | ||
|
||
def withJVMMetrics: CollectorRegistryBuilder[F] = | ||
copy(standardJVMMetrics = true) | ||
|
||
def add(c: Collector): CollectorRegistryBuilder[F] = | ||
copy(collectors = collectors + c) | ||
|
||
def makeRegistry: Resource[F, CollectorRegistry] = | ||
val registry = new CollectorRegistry() | ||
(registerJVM(registry) >> registerCollectors(registry)) | ||
.as(registry) | ||
|
||
private def registerCollectors(registry: CollectorRegistry): Resource[F, Unit] = | ||
collectors.toList.map(registerCollector(registry)).sequence.void | ||
|
||
private def registerCollector(registry: CollectorRegistry)(collector: Collector) = | ||
val F = Sync[F] | ||
val acq = F.blocking(collector.asJCollector.register[JCollector](registry)) | ||
Resource.make(acq)(c => F.blocking(registry.unregister(c))) | ||
|
||
private def registerJVM(registry: CollectorRegistry) = | ||
if standardJVMMetrics then PrometheusExportService.addDefaults(registry) | ||
else Resource.pure[F, Unit](()) | ||
|
||
object CollectorRegistryBuilder: | ||
def apply[F[_]: Sync]: CollectorRegistryBuilder[F] = | ||
new CollectorRegistryBuilder[F](Set.empty, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.