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

count exceptions #49

Merged
merged 7 commits into from
Aug 24, 2020
Merged

count exceptions #49

merged 7 commits into from
Aug 24, 2020

Conversation

erez-rabih
Copy link
Contributor

No description provided.

@erez-rabih
Copy link
Contributor Author

replaces #48

@erez-rabih
Copy link
Contributor Author

erez-rabih commented Aug 14, 2020

@slipset I opened this PR instead of the other one
to go through the possible cases:

  1. if exception-status is not provided in the options map the behavior stays the same as it is now - the exception will be thrown and handled by the with-exceptions function
  2. if exception status is provided, and exception is thrown by handler it will be caught returned to the response var. ensure-response-map will convert it to the requested exception-status for recording. lastly, the exception would be thrown to be handled by with-exceptions and propagate

so either way the exception is eventually thrown - but if exception-status is provided it will be recorded before being thrown

what do you think?

I am still missing tests and documentation - will complete them when we agree on the changes

@erez-rabih
Copy link
Contributor Author

solves #47

Copy link
Member

@slipset slipset left a comment

Choose a reason for hiding this comment

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

Looks a lot better!
Some small nitpicks :)

(cond (nil? response) {:status 404}
(exception? response) {:status (:exception-status options)}
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather you pass exception-status as a param instead of the whole options map

Copy link
Contributor Author

@erez-rabih erez-rabih Aug 14, 2020

Choose a reason for hiding this comment

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

solved by cf51b3b

(defn- run-instrumented
[{:keys [handler] :as options} request]
(ex/with-exceptions (exception-counter-for options request)
(let [start-time (System/nanoTime)
response (handler request)
response (safe options #(handler request))
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need safe, I think it suffices to do

response (try (handler request) (catch Exception e e))

Copy link
Contributor Author

@erez-rabih erez-rabih Aug 14, 2020

Choose a reason for hiding this comment

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

we can do this but it introduces a subtle difference in behavior:
it means we will always catch an exception thrown in (handler request) and this exception will always be counted in the totals
it also means we will have to provide some default value to :exception-status since now there is no conditional relying on this value being provided

what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Let's go with your solution 👍

Copy link
Member

Choose a reason for hiding this comment

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

If you could pass exception status as a param like

(defn- maybe-safe [catch-exceptions? f]
  (if catch-exceptions?
     (try (f) (catch Exception e e))
     (f)))

That'd be great.

You could then call it with (safe (:exception-status options) #(handler request))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure e8e5715

(record-metrics! options delta request))
(when (exception? response) (throw response))
Copy link
Member

Choose a reason for hiding this comment

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

(if-not (exception? response) response (throw exception))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved by 370a50e

@MalloZup
Copy link
Member

@slipset thx

@erez-rabih
Copy link
Contributor Author

@slipset I added tests and documentation in the readme
if you think I should add documentation on the function metadata itself I can do that as well
please let me know if there is anything missing on the PR

@slipset
Copy link
Member

slipset commented Aug 18, 2020

It looks good now I think. @MalloZup you have anything?

@erez-rabih
Copy link
Contributor Author

It looks good now I think. @MalloZup you have anything?

@MalloZup @slipset ping

@slipset slipset merged commit 62229e0 into clj-commons:master Aug 24, 2020
@erez-rabih
Copy link
Contributor Author

@slipset just to tie this up - what is the release schedule for this library?
the new logic is not available right now on the pre-built jars

@slipset
Copy link
Member

slipset commented Aug 31, 2020

Released as 0.1.11 Thanks a lot for reminding me!

@erez-rabih erez-rabih deleted the count-exceptions branch August 31, 2020 14:37
@erez-rabih
Copy link
Contributor Author

Released as 0.1.11 Thanks a lot for reminding me!

thanks!

meraymond2 pushed a commit to Cervest/iapetos that referenced this pull request Apr 30, 2021
…mmons#49)

The old behaviour was not to report thrown exceptions as 5XX status class to the http_requests_total metric.
This change gives the client the option to count exceptions in the total as well as exceptions.

Please refer to the Readme for further details.
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.

3 participants