From: Markus Valentin Date: Wed, 6 Dec 2023 10:11:19 +0000 (+0100) Subject: stats: Use http_server_init_auto() X-Git-Tag: 2.4.1~1053 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92d407303d33b175e834d15446ea20b14d799ffc;p=thirdparty%2Fdovecot%2Fcore.git stats: Use http_server_init_auto() This adds stats_server { .. } named filter, which can be used to override http-server settings. The following settings were replaced: * stats_http_rawlog_dir-> http_server_rawlog_dir --- diff --git a/src/stats/client-http.c b/src/stats/client-http.c index 1ca9a99e53..add8d6ade4 100644 --- a/src/stats/client-http.c +++ b/src/stats/client-http.c @@ -12,6 +12,7 @@ #include "stats-metrics.h" #include "stats-service.h" #include "client-http.h" +#include "settings.h" struct stats_http_client; @@ -213,18 +214,18 @@ stats_http_resource_root_request(void *context ATTR_UNUSED, * Server */ -void client_http_init(const struct stats_settings *set, struct event *event) +void client_http_init(struct event *parent_event) { - struct http_server_settings http_set; - - http_server_settings_init(null_pool, &http_set); - http_set.rawlog_dir = set->stats_http_rawlog_dir, - + const char *error; i_array_init(&stats_http_resources, 8); - stats_http_server = http_server_init(&http_set, event); + struct event *event = event_create(parent_event); + event_set_ptr(parent_event, SETTINGS_EVENT_FILTER_NAME, STATS_SERVER_FILTER); + if (http_server_init_auto(event, &stats_http_server, &error) < 0) + i_fatal("http_server_init() failed: %s", error); stats_http_resource_add("/", NULL, stats_http_resource_root_request, NULL); + event_unref(&event); } void client_http_deinit(void) diff --git a/src/stats/client-http.h b/src/stats/client-http.h index be99671192..93492a77fa 100644 --- a/src/stats/client-http.h +++ b/src/stats/client-http.h @@ -22,7 +22,7 @@ void stats_http_resource_add(const char *path, const char *title, typeof(context), struct http_server_request *req, \ const char *sub_path)))) -void client_http_init(const struct stats_settings *set, struct event *event); +void client_http_init(struct event *event); void client_http_deinit(void); #endif diff --git a/src/stats/main.c b/src/stats/main.c index b2399f1c11..16bb7f473f 100644 --- a/src/stats/main.c +++ b/src/stats/main.c @@ -59,8 +59,7 @@ static void main_init(void) stats_event_categories_init(); client_readers_init(); client_writers_init(); - client_http_init(stats_settings, - master_service_get_event(master_service)); + client_http_init(master_service_get_event(master_service)); stats_services_init(); } diff --git a/src/stats/stats-settings.c b/src/stats/stats-settings.c index b4a340897e..b8f44dd8af 100644 --- a/src/stats/stats-settings.c +++ b/src/stats/stats-settings.c @@ -145,8 +145,7 @@ const struct setting_parser_info stats_metric_setting_parser_info = { SETTING_DEFINE_STRUCT_##type(#name, name, struct stats_settings) static const struct setting_define stats_setting_defines[] = { - DEF(STR, stats_http_rawlog_dir), - + { .type = SET_FILTER_NAME, .key = STATS_SERVER_FILTER }, { .type = SET_FILTER_ARRAY, .key = "metric", .offset = offsetof(struct stats_settings, metrics), .filter_array_field_name = "metric_name", @@ -159,8 +158,6 @@ static const struct setting_define stats_setting_defines[] = { }; const struct stats_settings stats_default_settings = { - .stats_http_rawlog_dir = "", - .metrics = ARRAY_INIT, .exporters = ARRAY_INIT, }; diff --git a/src/stats/stats-settings.h b/src/stats/stats-settings.h index 4ed079e80b..0c075545a4 100644 --- a/src/stats/stats-settings.h +++ b/src/stats/stats-settings.h @@ -5,6 +5,8 @@ "name hostname timestamps categories fields" /* */ +#define STATS_SERVER_FILTER "stats_server" + /* * We allow a selection of a timestamp format. * @@ -119,7 +121,6 @@ struct stats_metric_settings { struct stats_settings { pool_t pool; - const char *stats_http_rawlog_dir; ARRAY_TYPE(const_string) exporters; ARRAY_TYPE(const_string) metrics;