-
Notifications
You must be signed in to change notification settings - Fork 63
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
[#235] Wrap pgagroal_prefill()
#239
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In order to make calls to `pgagroal_prefill()` consistent around the code and avoid repetitions, there is a new function named `pgagroal_prefill_if_can()` that wraps several checks and does the forking and prefilling. Therefore there is no need to check against the configuration limits and users before calling `pgagroal_prefill()` because `pgagroal_prefill_if_can()` will do by itself. Also `pgagroal_prefill_if_can()` will check for a primary server, and in the case there is none, will avoid issuing the prefill at all. Last, this introduces also the `pgagroal_can_prefill()` function that is used in turn by `pgagroal_prefill_if_can()` and aims at testing the configuration for the presence of limits and users. This function can be used as a condition checker before doing clean-up stuff right before calling `pgagroal_prefill_if_can()`. Close agroal#223
jesperpedersen
requested changes
May 19, 2022
As per discussion <agroal#239 (comment)> the function `pgagroal_can_prefill()` is able to obtain the configuration from the shared memory instead of using an explicit parameter. This changes also the `pgagroal_prefill_if_can()` invocation of the same function and the `main` block of code. Close agroal#239
Merged. Thanks for your contribution ! |
fluca1978
added a commit
to fluca1978/pgagroal
that referenced
this pull request
May 30, 2022
This commit refactors the way the Prometheus metrics are served in order to provide the capability to cache the responses for a specified amount of time. A new setting, named `metrics_cache` is defined and parsed as an "age" string. The value will be stored as a number of seconds. This required the refactoring of some configuration code, with particular regard to `as_logging_rotation_age()` in order to extract the "as age" logic into an utility function that can be used for different "age"-like strings. Moreover, some methods and configuration parameters have been changed from `int` to `unsigned int` (e.g., it does not make any sense to have a log rotation age negative!). The configuration related code has been changed to intercept wrong strings, e.g., when `log_rotation_age = -2m` the system disables the rotation and warns the user as the parameter is unknown. Also `+1m` is considered a bogus string. The `struct prometheus` has been expanded with an inner struct, named `struct prometheus_cache` that holds the cache payload and the timestamp the cache will be valid until. The `metrics_page()` has been refactored to check if the cache is configured and valid, in such case the response is served out of cache. On the other hand, the cache is reset and the response is served as a new one, with all the inner methods adding the result to the cache for the next time. A few utility functions have been introduced: - `is_metrics_cache_configured()` checks that the current configuration allows for the usage of cache, i.e., `metrics_cache` have been set; - `is_metrics_cache_valid()` checks hat the cache does handle some good stuff to be served; - `metrics_cache_reset()` to reset the cache, once it has been set within the shared memory; - `metrics_cache_add()` appends data to the cache. This methods is invoked whenever a new Prometheus message is spurt. In the case the overall amount of data overflows, the cache is made not valid. It is safe to call this function everywhere because it does nothing if the caching system is not enabled. If the cache overflows, it is set to "invalid" so that is not gong to be served anymore. The max size of the cache is defined as a constant value within the source code, and is set to 8kB (that should be reasonable since the average Prometheus response on a unloaded server is around 4kB). The documentation has been updated to reflect changes. Close agroal#239
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In order to make calls to
pgagroal_prefill()
consistent around thecode and avoid repetitions, there is a new function named
pgagroal_prefill_if_can()
that wraps several checks and does theforking and prefilling.
Therefore there is no need to check against the configuration limits
and users before calling
pgagroal_prefill()
becausepgagroal_prefill_if_can()
will do by itself.Also
pgagroal_prefill_if_can()
will check for a primary server, andin the case there is none, will avoid issuing the prefill at all.
Last, this introduces also the
pgagroal_can_prefill()
function thatis used in turn by
pgagroal_prefill_if_can()
and aims at testing theconfiguration for the presence of limits and users. This function can
be used as a condition checker before doing clean-up stuff right
before calling
pgagroal_prefill_if_can()
.Close #223