From 208f48d83e9ccd5243ca78dfae9678fbcd894f7d Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 26 Jan 2024 14:37:56 +0100 Subject: [PATCH] src/daemon/plugin.c: Log a debug message when a metric family has no metrics. --- src/daemon/plugin.c | 3 +++ src/utils/format_json/format_json_test.c | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 7ed260503..0ab5999db 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -2105,6 +2105,9 @@ EXPORT int plugin_dispatch_metric_family(metric_family_t const *fam) { return EINVAL; } if (fam->metric.num == 0) { + DEBUG("plugin_dispatch_metric_family: Metric family \"%s\" contains zero " + "metrics.", + fam->name); return 0; } diff --git a/src/utils/format_json/format_json_test.c b/src/utils/format_json/format_json_test.c index 528be87c0..9f73a00a7 100644 --- a/src/utils/format_json/format_json_test.c +++ b/src/utils/format_json/format_json_test.c @@ -136,7 +136,7 @@ static int expect_json_labels(char *json, label_pair_t *labels, DEF_TEST(notification) { label_pair_t labels[] = { - {"summary", "this is a message"}, + {"summary", "this is a \"message\""}, {"alertname", "collectd_unit_test"}, {"instance", "example.com"}, {"service", "collectd"}, @@ -144,19 +144,21 @@ DEF_TEST(notification) { }; /* 1448284606.125 ^= 1555083754651779072 */ - notification_t n = {NOTIF_WARNING, - 1555083754651779072ULL, - "this is a message", - "example.com", - "unit", - "", - "test", - "case", - NULL}; + notification_t n = { + .severity = NOTIF_WARNING, + .time = 1555083754651779072ULL, + .message = "this is a \"message\"", + .host = "example.com", + .plugin = "unit", + .plugin_instance = "", + .type = "test", + .type_instance = "case", + .meta = NULL, + }; char got[1024]; CHECK_ZERO(format_json_notification(got, sizeof(got), &n)); - // printf ("got = \"%s\";\n", got); + printf("got = \"%s\";\n", got); return expect_json_labels(got, labels, STATIC_ARRAY_SIZE(labels)); } -- 2.47.2