Skip to content

Commit f1835ef

Browse files
committed
- Fix #474: metrics output with zone statistics to change
disallowed characters in metric names to underscores.
1 parent 95ebfec commit f1835ef

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

doc/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
6 January 2026: Wouter
2+
- Fix #474: metrics output with zone statistics to change
3+
disallowed characters in metric names to underscores.
4+
15
21 December 2025: Willem
26
- Fix rr-test.tdir so AMTRELAY relay field is "." with type 0
37
- Fix checkconf.tdir test to anticipate default values for

doc/RELNOTES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ BUG FIXES:
1313
- Fix checkconf.tdir test to anticipate default values for
1414
send-buffer-size and receive-buffer-size when configured with 0
1515
- skip dns-cookies.tdir test with restricted unpriviledged userns
16+
- Fix #474: metrics output with zone statistics to change
17+
disallowed characters in metric names to underscores.
1618

1719
4.14.0
1820
================

metrics.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <errno.h>
1919
#include <event2/event.h>
2020
#include <event2/http.h>
21+
#include <ctype.h>
2122

2223
#include "nsd.h"
2324
#include "xfrd.h"
@@ -343,6 +344,22 @@ metrics_http_callback(struct evhttp_request *req, void *p)
343344
}
344345

345346
#ifdef BIND8_STATS
347+
/** Change disallowed characters, '.' ':' to underscores '_'. */
348+
static void
349+
change_string_underscores(char* prefix)
350+
{
351+
/* Prometheus does not want '.' in the metric names. But the zone
352+
* statistics could have then in their name.
353+
* Also ':' is not allowed. This routine enforeces that it
354+
* has letters,digits,underscores. */
355+
char* s = prefix;
356+
while(*s) {
357+
if(!isalnum((unsigned char)*s) && *s != '_')
358+
*s = '_';
359+
s++;
360+
}
361+
}
362+
346363
/** print long number*/
347364
static int
348365
print_longnum(struct evbuffer *buf, char* desc, uint64_t x)
@@ -381,6 +398,7 @@ print_stat_block(struct evbuffer *buf, struct nsdst* st,
381398
char prefix[512] = {0};
382399
if (name) {
383400
snprintf(prefix, sizeof(prefix), "nsd_zonestats_%s_", name);
401+
change_string_underscores(prefix);
384402
} else {
385403
snprintf(prefix, sizeof(prefix), "nsd_");
386404
}
@@ -504,6 +522,7 @@ metrics_zonestat_print_one(struct evbuffer *buf, char *name,
504522
{
505523
char prefix[512] = {0};
506524
snprintf(prefix, sizeof(prefix), "nsd_zonestats_%s_", name);
525+
change_string_underscores(prefix);
507526

508527
print_metric_help_and_type(buf, prefix, "queries_total",
509528
"Total number of queries received.", "counter");

0 commit comments

Comments
 (0)