Skip to content

Commit

Permalink
Merge pull request #822 from lenguyenthanh/prometheus-exporter/0
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive authored Oct 28, 2024
2 parents 7ad915b + 2a1f53a commit 9a49965
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object PrometheusHttpRoutes {

val routes: HttpRoutes[F] = HttpRoutes.of {
case Request(GET, _, _, headers, _, _) =>
if (headers.get[Accept].forall(_.values.exists(_.mediaRange.satisfiedBy(MediaRange.`text/*`)))) {
if (headers.get[Accept].forall(_.values.exists(_.mediaRange.satisfies(MediaRange.`text/*`)))) {
for {
metrics <- exporter.metricReader.collectAllMetrics
} yield Response().withEntity(writer.write(metrics)).withHeaders("Content-Type" -> writer.contentType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ class PrometheusHttpRoutesSuite extends CatsEffectSuite with SuiteRuntimePlatfor
}
}

test("respond with a text on GET request and text/plain accept") {
PrometheusMetricExporter.builder[IO].build.flatMap { exporter =>
val routes: HttpRoutes[IO] = PrometheusHttpRoutes.routes(exporter, PrometheusWriter.Config.default)

routes.orNotFound
.run(
Request(method = Method.GET, uri = uri"/", headers = Headers(Accept(MediaType.text.plain)))
)
.flatMap { response =>
IO {
assertEquals(response.status, Status.Ok)
assertEquals(response.contentType.exists(_.mediaType.isText), true)
}
}
}
}

test("respond with a text on GET request and wildcard accept") {
PrometheusMetricExporter.builder[IO].build.flatMap { exporter =>
val routes: HttpRoutes[IO] = PrometheusHttpRoutes.routes(exporter, PrometheusWriter.Config.default)
Expand Down

0 comments on commit 9a49965

Please sign in to comment.