stats-metrics.c (dovecot-2.3.16) | : | stats-metrics.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 13 | skipping to change at line 13 | |||
#include "stats-common.h" | #include "stats-common.h" | |||
#include "array.h" | #include "array.h" | |||
#include "str.h" | #include "str.h" | |||
#include "str-sanitize.h" | #include "str-sanitize.h" | |||
#include "stats-dist.h" | #include "stats-dist.h" | |||
#include "time-util.h" | #include "time-util.h" | |||
#include "event-filter.h" | #include "event-filter.h" | |||
#include "event-exporter.h" | #include "event-exporter.h" | |||
#include "stats-settings.h" | #include "stats-settings.h" | |||
#include "stats-metrics.h" | #include "stats-metrics.h" | |||
#include "settings-parser.h" | ||||
#include <ctype.h> | #include <ctype.h> | |||
#define LOG_EXPORTER_LONG_FIELD_TRUNCATE_LEN 1000 | #define LOG_EXPORTER_LONG_FIELD_TRUNCATE_LEN 1000 | |||
struct stats_metrics { | struct stats_metrics { | |||
pool_t pool; | pool_t pool; | |||
struct event_filter *filter; /* stats & export */ | struct event_filter *filter; /* stats & export */ | |||
ARRAY(struct exporter *) exporters; | ARRAY(struct exporter *) exporters; | |||
ARRAY(struct metric *) metrics; | ARRAY(struct metric *) metrics; | |||
skipping to change at line 159 | skipping to change at line 160 | |||
metric->export_info.include |= EVENT_EXPORTER_INCL_TIMEST AMPS; | metric->export_info.include |= EVENT_EXPORTER_INCL_TIMEST AMPS; | |||
else if (strcmp(*tmp, "categories") == 0) | else if (strcmp(*tmp, "categories") == 0) | |||
metric->export_info.include |= EVENT_EXPORTER_INCL_CATEGO RIES; | metric->export_info.include |= EVENT_EXPORTER_INCL_CATEGO RIES; | |||
else if (strcmp(*tmp, "fields") == 0) | else if (strcmp(*tmp, "fields") == 0) | |||
metric->export_info.include |= EVENT_EXPORTER_INCL_FIELDS ; | metric->export_info.include |= EVENT_EXPORTER_INCL_FIELDS ; | |||
else | else | |||
i_warning("Ignoring unknown exporter include '%s'", *tmp) ; | i_warning("Ignoring unknown exporter include '%s'", *tmp) ; | |||
} | } | |||
} | } | |||
static struct stats_metric_settings * | ||||
stats_metric_settings_dup(pool_t pool, const struct stats_metric_settings *src) | ||||
{ | ||||
struct stats_metric_settings *set = p_new(pool, struct stats_metric_setti | ||||
ngs, 1); | ||||
set->metric_name = p_strdup(pool, src->metric_name); | ||||
set->description = p_strdup(pool, src->description); | ||||
set->fields = p_strdup(pool, src->fields); | ||||
set->group_by = p_strdup(pool, src->group_by); | ||||
set->filter = p_strdup(pool, src->filter); | ||||
set->exporter = p_strdup(pool, src->exporter); | ||||
set->exporter_include = p_strdup(pool, src->exporter_include); | ||||
return set; | ||||
} | ||||
static struct metric * | ||||
stats_metrics_find(struct stats_metrics *metrics, | ||||
const char *name, unsigned int *idx_r) | ||||
{ | ||||
struct metric *const *m; | ||||
array_foreach(&metrics->metrics, m) { | ||||
if (strcmp((*m)->name, name) == 0) { | ||||
*idx_r = array_foreach_idx(&metrics->metrics, m); | ||||
return *m; | ||||
} | ||||
} | ||||
return NULL; | ||||
} | ||||
bool stats_metrics_add_dynamic(struct stats_metrics *metrics, | ||||
struct stats_metric_settings *set, | ||||
const char **error_r) | ||||
{ | ||||
unsigned int existing_idx ATTR_UNUSED; | ||||
if (stats_metrics_find(metrics, set->metric_name, &existing_idx) != NULL) | ||||
{ | ||||
*error_r = "Metric already exists"; | ||||
return FALSE; | ||||
} | ||||
struct stats_metric_settings *_set = | ||||
stats_metric_settings_dup(metrics->pool, set); | ||||
if (!stats_metric_setting_parser_info.check_func(_set, metrics->pool, er | ||||
ror_r)) | ||||
return FALSE; | ||||
stats_metrics_add_set(metrics, _set); | ||||
return TRUE; | ||||
} | ||||
bool stats_metrics_remove_dynamic(struct stats_metrics *metrics, | ||||
const char *name) | ||||
{ | ||||
unsigned int m_idx; | ||||
struct metric *m = stats_metrics_find(metrics, name, &m_idx); | ||||
if (m != NULL) { | ||||
array_delete(&metrics->metrics, m_idx, 1); | ||||
return event_filter_remove_queries_with_context(metrics->filter, | ||||
m); | ||||
} | ||||
return FALSE; | ||||
} | ||||
static void | static void | |||
stats_metrics_add_from_settings(struct stats_metrics *metrics, | stats_metrics_add_from_settings(struct stats_metrics *metrics, | |||
const struct stats_settings *set) | const struct stats_settings *set) | |||
{ | { | |||
/* add all the exporters first */ | /* add all the exporters first */ | |||
if (!array_is_created(&set->exporters)) { | if (!array_is_created(&set->exporters)) { | |||
p_array_init(&metrics->exporters, metrics->pool, 0); | p_array_init(&metrics->exporters, metrics->pool, 0); | |||
} else { | } else { | |||
struct stats_exporter_settings *exporter_set; | struct stats_exporter_settings *exporter_set; | |||
End of changes. 2 change blocks. | ||||
0 lines changed or deleted | 65 lines changed or added |