🚀 Advanced HTTP Client for Ruby. Fueled with interceptors.
GPL-3.0 License
Bot releases are visible (Hide)
Fixes the gemspec license version as mentioned in https://github.com/local-ch/lhc/issues/176
ignored_errors
and error_handler
have been for a long time being the only option applied to LHC requests which were not following the general, verb-kind-a wording that we use for all the other options and methods, like .get
, cache:
, retry:
, followlocation``auth
etc.
This PR renames the ignored_errors:
option to ignore:
and the error_handler
option to rescue
.
I tried to use handle
instead of rescue
but handle
seems to be a ruby internal that we cannot use.
ignored_errors
to ignore
in your entire projecterror_handler
to rescue
in your entire projectWe discovered a bug in LHS where including resources that can not be found wouldn't work as expected.
This is a first improvement (minor) to solve the overall issue.
It allows to pass single keys to ignored_errors
e.g.:
LHC.get('https://local.ch', ignored_errors: LHC::NotFound)
When this feature was introduced, there was only 1 bearer token format, the one from auth.local.ch.
Now with Salesforce we have a second bearer token issuer, and this PR weakens the criterias under which a reauthenticate? is performed to refresh client tokens.
The setting of the registering is not atomic, so it could happen that on start up, the registered flag is not yet set when a second thread initialises the Prometheus interceptor again. Simply adding a rescue for this case prevents an exception.
This should be idiomatic anyway.
Up to now, the timings from the prometheus monitoring were not very useful. They were using a key that is not following conventions and also using milliseconds with histogram buckets that only go up to 10. Meaning every request that takes longer than 10ms was not even monitored any more.
This follows the convention for histograms more closely and also adds the host label, so we can determine which requests are actually slow instead of guessing.
Also we now use a single key, lhc_requests and lhc_request_seconds, and differentiate the event using a label. This allows us to create a board that shows all of the LHC requests over several apps.
PATCH
#165
This release improves on the Rollbar interceptor. Up until now it was possible to loose Rollbar messages when they caused a Encoding::UndefinedConversionError
.
Now it will:
Encoding::UndefinedConversionError
during Rollbar.warn
fix_invalid_encoding
on the valuesFor this to work easily we introduced:
into our codebase
PATCH
This release makes the necessary changes to be ready for Rails 6 and takes care of some annoying deprecation warnings. It also introduces explicit rspec runs for Rails 4 / 5 / 6
PATCH
This PR makes the retry interceptor consider to not retry a request if the error (response) was explicitly ignored. (Which was expected to work that way.)
If you do not want to retry based on certain response codes, use retry in combination with explicit ignore_errors
:
LHC.get('http://local.ch', ignore_errors: [LHC::NotFound], retry: { max: 1 })
Or if you use LHC::Retry.all
:
LHC.get('http://local.ch', ignore_errors: [LHC::NotFound])
Having throttling expire is kind of necessary, that's also why this PR is patching the version.
Otherwise, as soon as the throttling interceptor hits the break, he will never get out of the break state again, as no further request would be allowed, which would update the current quota.
The throttle interceptor allows you to raise an exception if a predefined quota of an provider request limit is reached in advance.
LHC.configure do |c|
c.interceptors = [LHC::Throttle]
end
options = {
throttle: {
track: true, # enables tracking of current limit/remaining requests of rate-limiting
break: '80%', # quota in percent after which errors are raised
provider: 'local.ch', # name of the provider under which throttling tracking is aggregated,
limit: { header: 'Rate-Limit-Limit' }, # either a hard-coded integer, or a hash pointing at the response header containing the limit value
remaining: { header: 'Rate-Limit-Remaining' }, # a hash pointing at the response header containing the current amount of remaining requests
}
}
LHC.get('http://local.ch', options)
# { headers: { 'Rate-Limit-Limit' => 100, 'Rate-Limit-Remaining' => 19 } }
LHC.get('http://local.ch', options)
# raises LHC::Throttle::OutOfQuota: Reached predefined quota for local.ch
If you want to retry all requests made from your application, you just need to configure it globally:
LHC::Retry.all = true
configuration.interceptors = [LHC::Retry]
In case this causes retried requests during your tests, tell your test suite to not retry requests during tests:
# spec/support/lhc.rb
LHC::Retry.all = false
We get the following warnings a lot (unnecessarily)
[WARNING] Zipkin interceptor is enabled but dependencies are not found. See: https://github.com/local-ch/lhc#zipkin
This PR decouples tracing? (if tracing is happening) from dependencies? (which clearly just checks for dependencies.
So in your tests it would still complain if Zipkin has wrong dependencies (which might make your app crash when deployed), but it's not flooding you with warnings any longer, just because there is no current trace!