-
Notifications
You must be signed in to change notification settings - Fork 61
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
Split struct prometheus from struct configuration #155
Conversation
src/include/pgagroal.h
Outdated
@@ -142,6 +142,11 @@ extern void* shmem; | |||
*/ | |||
extern void* pipeline_shmem; | |||
|
|||
/** | |||
* The shared memory segment for prometheus connection |
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 connection" -> "the Prometheus data"
src/include/pgagroal.h
Outdated
*/ | ||
struct prometheus_connection | ||
{ | ||
char database[MAX_DATABASE_LENGTH]; /**< The database */ |
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.
struct prometheus_connection
will have a 1-to-1 relationship with struct connection
, so this can be an empty struct to begin with
src/include/pgagroal.h
Outdated
@@ -235,6 +250,7 @@ struct prometheus | |||
|
|||
atomic_ulong server_error[NUMBER_OF_SERVERS]; /**< The number of errors for a server */ | |||
atomic_ulong failed_servers; /**< The number of failed servers */ | |||
struct prometheus_connection prometheus_connections[MAX_NUMBER_OF_CONNECTIONS]; /**< The number of prometheus connections */ |
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.
This needs to be a FMA field, so we only use the memory that we need.
See how struct connection[];
is initialized after max_connections
is known.
src/libpgagroal/prometheus.c
Outdated
|
||
for (int i = 0; i < config->max_connections; i++) | ||
{ | ||
memset(prometheus->prometheus_connections[i].database, 0, MAX_DATABASE_LENGTH); |
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.
Remove this memset
with a general memset(&prometheus->prometheus_connections[i], 0, sizeof(struct prometheus_connection);
|
||
for (int i = 0; i < NUMBER_OF_SERVERS; i++) | ||
{ | ||
atomic_store(&config->prometheus.server_error[i], 0); | ||
atomic_store(&prometheus->server_error[i], 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.
This needs to reset the prometheus_connections
as well
src/libpgagroal/prometheus.c
Outdated
@@ -795,6 +845,10 @@ general_information(int client_fd) | |||
|
|||
config = (struct configuration*)shmem; | |||
|
|||
struct prometheus* 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.
Keep definitions at the start of the function
src/main.c
Outdated
@@ -396,6 +398,19 @@ main(int argc, char **argv) | |||
pgagroal_init_configuration(shmem); | |||
config = (struct configuration*)shmem; | |||
|
|||
prometheus_shmem_size = sizeof(struct prometheus); | |||
if (pgagroal_create_shared_memory(prometheus_shmem_size, HUGEPAGE_OFF, &prometheus_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.
Huge page settings needs to come from the configuration
Look at my comments, then squash and force push |
Done |
src/libpgagroal/prometheus.c
Outdated
return 1; | ||
} | ||
|
||
struct prometheus* 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.
Move this to the beginning of the function
struct configuration* config; | ||
|
||
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.
Create local variables for the size and the memory segment.
Set p_size
and p_shmem
to 0
and NULL
in the beginning of the function, and only assign them if everything is successful
src/libpgagroal/prometheus.c
Outdated
@@ -791,6 +849,11 @@ static void | |||
general_information(int client_fd) | |||
{ | |||
char* data = NULL; | |||
|
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.
White space
Just a few more |
Done |
Thanks for your contribution ! |
Split struct prometheus from struct configuration.
Close #153