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

Middleware #142

Merged
merged 1 commit into from
Apr 7, 2023
Merged

Middleware #142

merged 1 commit into from
Apr 7, 2023

Conversation

rtrox
Copy link
Collaborator

@rtrox rtrox commented Apr 3, 2023

Description of the change

Adds middleware for all collectors. Two middlewares are added:

  1. Metrics middleware -- collects metrics related to the scrape itself (specifically latency & request count).
  2. Recovery middleware -- after panic: runtime error: index out of range #138, I added some recovery specifically in the client, which I think is still valuable, so that we can log json blobs which fail to unmarshal. But for the sake of reliability, we should really add a catch-all recover middleware. With this middleware, rather than panics cause a crash, they'll instead log, and return a 500 to prometheus.

Since I had to add a writer wrapper to collect the status code for requests, I went ahead and added it to the logger middleware we already had, too, as a QoL change.

Benefits

  1. Prevents panic-crashes
  2. Exports metrics about scrapes.

Possible drawbacks

Applicable issues

  • fixes #

Additional information

@rtrox rtrox requested a review from onedr0p as a code owner April 3, 2023 21:26
@rtrox rtrox marked this pull request as draft April 3, 2023 21:27
@rtrox
Copy link
Collaborator Author

rtrox commented Apr 3, 2023

This is ready to go, but draft until #141 lands, so this is easier to review.

@rtrox rtrox force-pushed the middleware branch 2 times, most recently from a432768 to 583b11e Compare April 6, 2023 19:31
Signed-off-by: Russell Troxel <russell@troxel.io>
@rtrox rtrox marked this pull request as ready for review April 6, 2023 19:35
@onedr0p onedr0p merged commit 9d4a8a1 into master Apr 7, 2023
@onedr0p onedr0p deleted the middleware branch March 29, 2024 12:32
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.

None yet

2 participants