Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Prometheus middleware usage example #3279

Merged
merged 2 commits into from
Apr 24, 2020

Conversation

gannicottb
Copy link
Contributor

Show how the PrometheusExportService can be used to expose the metrics for scraping. I spent a long time trying to figure it out, would like to pay it forward.

Show how the PrometheusExportService can be used to expose the metrics for scraping. I spent a long time trying to figure it out, would like to pay it forward.
@gannicottb gannicottb changed the title Improve Prometheus middleware usage example fixes #3278 Improve Prometheus middleware usage example Mar 25, 2020
@gannicottb
Copy link
Contributor Author

fixes #3278

```
```tut:book
implicit val clock = Clock.create[IO]

val meteredRoutes: Resource[IO, HttpRoutes[IO]] =
def meteredRouter(routes: HttpRoutes[IO]): Resource[IO, HttpRoutes[IO]] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called somewhere with the apiService now its just a function that is not used in this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I guess I thought getting the reader to a Resource[IO, HttpRoutes[IO]] would be sufficient (without writing an entire sample server).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better, but we should still call this method with apiService to show use.
or we can change this back to use the apiService directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. I'll make that change.

Copy link
Contributor

@Daenyth Daenyth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks reasonable to me but it would be good to get feedback from someone more familiar with prometheus usage.

for {
registry <- Prometheus.collectorRegistry[IO]
metrics <- Prometheus.metricsOps[IO](registry, "server")
} yield Metrics[IO](metrics)(apiService)
metricsSvc <- PrometheusExportService.build[IO]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this require the registry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChristopherDavenport The apply method requires the registry, the build methods creates a new registry.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case this would need to be first and be the registry used for metering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally missed the difference between build and apply. I can fix that up.

@rossabaker
Copy link
Member

Thanks! Test failures are unrelated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants