-
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
Enable Vault Prometheus #454
Conversation
src/libpgagroal/prometheus.c
Outdated
|
||
void | ||
pgagroal_prometheus(int client_fd) | ||
{ | ||
if (!is_prometheus_enabled()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should do this after the variable definitions
src/libpgagroal/prometheus.c
Outdated
void | ||
pgagroal_vault_prometheus(int client_fd) | ||
{ | ||
if (!is_prometheus_enabled()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
@@ -244,6 +312,11 @@ pgagroal_init_prometheus(size_t* p_size, void** p_shmem) | |||
void | |||
pgagroal_prometheus_session_time(double time) | |||
{ | |||
if (!is_prometheus_enabled()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
@@ -330,6 +403,11 @@ pgagroal_prometheus_session_time(double time) | |||
void | |||
pgagroal_prometheus_connection_error(void) | |||
{ | |||
if (!is_prometheus_enabled()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
@@ -340,6 +418,11 @@ pgagroal_prometheus_connection_error(void) | |||
void | |||
pgagroal_prometheus_connection_kill(void) | |||
{ | |||
if (!is_prometheus_enabled()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
src/libpgagroal/prometheus.c
Outdated
data = pgagroal_append(data, " </p>\n"); | ||
data = pgagroal_append(data, " <h2>pgagroal_self_sockets</h2>\n"); | ||
data = pgagroal_append(data, " <p>\n"); | ||
data = pgagroal_append(data, " Number of sockets used by pgagroal itself\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pgagroal-vault
@@ -503,6 +656,11 @@ pgagroal_prometheus_auth_user_error(void) | |||
void | |||
pgagroal_prometheus_client_wait_add(void) | |||
{ | |||
if (!is_prometheus_enabled()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, all of them...
src/libpgagroal/prometheus.c
Outdated
data = pgagroal_append(data, " <p>\n"); | ||
data = pgagroal_append(data, " <a href=\"/metrics\">Metrics</a>\n"); | ||
data = pgagroal_append(data, " </p>\n"); | ||
data = pgagroal_append(data, " <h2>pgagroal_logging_info</h2>\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be called pgagroal_vault_XYZ
src/libpgagroal/prometheus.c
Outdated
|
||
prometheus = (struct prometheus*)prometheus_shmem; | ||
|
||
data = pgagroal_append(data, "#HELP pgagroal_logging_info The number of INFO logging statements\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pgagroal_vault_logging_info
|
||
data = pgagroal_append(data, "#HELP pgagroal_client_sockets Number of sockets the client used\n"); | ||
data = pgagroal_append(data, "#TYPE pgagroal_client_sockets gauge\n"); | ||
data = pgagroal_append(data, "pgagroal_client_sockets "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pgagroal_vault_XYZ
Remember the tutorial, man page and manual as well |
Yeah working on it parallely |
Maybe enable metrics by default in the |
I think that your "Future" section should be easy as well |
It is documented in the configuration files - users doesn't need to know about the internals |
Yeah, but for new developers it might be required |
6bebd7a
to
67ecc0d
Compare
@jesperpedersen The suggested changes have been integrated PTAL. |
src/libpgagroal/prometheus.c
Outdated
@@ -2267,6 +2824,7 @@ pgagroal_init_prometheus_cache(size_t* p_size, void** p_shmem) | |||
|
|||
error: | |||
// disable caching | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the empty line and leave the comment near the code
static bool | ||
is_prometheus_enabled(void) | ||
{ | ||
struct configuration* config = (struct configuration*)shmem; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test against nulls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required as we initiate prometheus
memory allocation only if config->metrics
> 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required as we initiate
prometheus
memory allocation only ifconfig->metrics
> 0.
Well, but if we export the function to somewhere else, we could need some extra (redundant) checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, will add the NULL
check for prometheus
to avoid any unlikely cases that may occur.
@@ -742,20 +742,23 @@ main(int argc, char** argv) | |||
errx(1, "Failed to start logging"); | |||
} | |||
|
|||
if (pgagroal_init_prometheus(&prometheus_shmem_size, &prometheus_shmem)) | |||
if (config->common.metrics > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we export is_prometheus_active
function and use it so the code is consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah can be done, but won't it waste some memory and computation as config
is already there in the program it will again define struct configuration
in the check function.
However, as far as consistency is concerned it can be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah can be done, but won't it waste some memory and computation as
config
is already there in the program it will again definestruct configuration
in the check function.
The only waste I can see is the function call, but I don't think we are optimizing at this level right now.
It could also be a macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only waste I can see is the function call, but I don't think we are optimizing at this level right now.
Okay 👍
It could also be a macro.
Not sure how a macro could solve the issue, can you please elaborate a little.
Also, if we add NULL
check of prometheus
in is_prometheus_enabled()
function (as per the aforementioned change request) then we can't use it in this scenario as it will always fail the test (since prometheus
is checked before it is being initialised), and the only test which should be checked is metrics > 0
. So I believe the current setup is ok.
What do you think about it? @fluca1978.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if we add
NULL
check ofprometheus
inis_prometheus_enabled()
function (as per the aforementioned change request) then we can't use it in this scenario as it will always fail the test (sinceprometheus
is checked before it is being initialised), and the only test which should be checked ismetrics > 0
. So I believe the current setup is ok.
Indeed having the test against nulls will fail in this case, so better leave it off the is_prometheus_enabled
. Sorry, I was running out of coffee.
@@ -1044,14 +1047,14 @@ main(int argc, char** argv) | |||
ev_periodic_start (main_loop, &rotate_frontend_password); | |||
} | |||
|
|||
if (config->metrics > 0) | |||
if (config->common.metrics > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@@ -379,6 +435,25 @@ main(int argc, char** argv) | |||
errx(1, "Failed to start logging"); | |||
} | |||
|
|||
if (config->common.metrics > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@@ -445,21 +529,64 @@ main(int argc, char** argv) | |||
|
|||
start_vault_io(); | |||
|
|||
if (config->common.metrics > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
/** @struct | ||
* Defines the Main Prometheus metrics | ||
*/ | ||
struct main_prometheus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get the point in splitting the prometheus
structure into two parts, it seems to me it is useless: if metrics > 0
prometheus is active, so there is no advantage in memory allocation. Also, while vault_configuration
added fields around configuration
, here you are narrowing the structure only to the fields you need.
While I don't dislike in total this approach, it seems counterintuitive to have prometheus
not being the main metrics structure as I would at glange expect. I would rather make a prometheus_logging
structure, a prometheus_socket
one and have prometheus
to wrap the above, so that prometheus_vault
can handle only the former twos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if metrics > 0 prometheus is active, so there is no advantage in memory allocation.
True, the aim of splitting prometheus
is to separate the memory space allocation for different programs (main
/vault
) as there as several fields which are not utilized by vault but are still allocated extra memory for unused fields.
Also, while vault_configuration added fields around configuration, here you are narrowing the structure only to the
fields you need.
As of now I have added just the required fields and more fields can be added as and when required.
While I don't dislike in total this approach, it seems counterintuitive to have prometheus not being the main metrics
structure as I would at glange expect. I would rather make a prometheus_logging structure, a prometheus_socket
one and have prometheus to wrap the above, so that prometheus_vault can handle only the former twos.
Can be done that way also. The thing i kept in my mind was that if in future if the project integrates other such service programs like vault
, that will need prometheus
then it can directly inherit the common fields (common for all services/servers) while keep on adding its specific fields in its prometheus
structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be done that way also. The thing i kept in my mind was that if in future if the project integrates other such service programs like
vault
, that will needprometheus
then it can directly inherit the common fields (common for all services/servers) while keep on adding its specific fields in itsprometheus
structure.
This is clear, and is a good approach, but I don't think that common
is the right name for the structure. It seems, so far, you need only a subset of the structure for the vault, so I'm not sure if this effort in splitting the structure is worth. I suspect you will find the need to add more fields here and there from time to time, so at this stage I would not split the structure. Surely, I will not name it as common
, since that makes me think at common fields, while so far there are only "basic" fields like logging counters.
@jesperpedersen what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prometheus_base
is an alternative
/** @struct | ||
* Defines the Main Prometheus metrics | ||
*/ | ||
struct main_prometheus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prometheus_base
is an alternative
I think it looks good but |
67ecc0d
to
bb3253a
Compare
Merged. Thanks for your contribution ! |
Enable Prometheus in vault
About this commit
pgagroal-vault
at portmetrics
in configuration to track server activitiesmetrics
,hugepage
,metric_cache_max_age
andmetric_cache_max_size
in the common configurationis_prometheus_enabled
on all theprometheus
functions and code blocks which basically checks whether the metrics port is active or not.metric
port value we allocate memory toprometheus
structure andprometheus_cache
Future work
prometheus
structure formain
andvault
similar toconfiguration
for optimal memory management.prometheus
should be initiated only whenmetric
port is active --> Document it properly somewhere.@jesperpedersen @fluca1978 PTAL.