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

[#235] Wrap pgagroal_prefill() #239

Closed
wants to merge 2 commits into from

Conversation

fluca1978
Copy link
Collaborator

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 #223

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
src/include/configuration.h Outdated Show resolved Hide resolved
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
@jesperpedersen jesperpedersen added the enhancement Improvement to an existing feature label May 23, 2022
@jesperpedersen
Copy link
Collaborator

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
Labels
enhancement Improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pgagroal-cli reload and added server
2 participants