fix(metrics): preserve request size from plugins (#7313)

The rewrite plugin modifies DNS messages, affecting the request
size observed in the coredns_dns_request_size_bytes metric.

This change captures the original request size before any plugins
can modify it. It adds a functional options pattern to Report() to
pass this information while maintaining API compatibility.

Tests have been added to verify the fix prevents rewrite from
affecting the request size metrics.

Docs included.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
Ville Vesilehto
2025-05-22 16:38:22 +03:00
committed by GitHub
parent 528cc26a4c
commit 32ea433a29
7 changed files with 337 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
.\" Generated by Mmark Markdown Processer - mmark.miek.nl
.TH "COREDNS-METRICS" 7 "March 2021" "CoreDNS" "CoreDNS Plugins"
.TH "COREDNS-METRICS" 7 "May 2025" "CoreDNS" "CoreDNS Plugins"
.SH "NAME"
.PP
@@ -10,30 +10,38 @@
.PP
With \fIprometheus\fP you export metrics from CoreDNS and any plugin that has them.
The default location for the metrics is \fB\fClocalhost:9153\fR. The metrics path is fixed to \fB\fC/metrics\fR.
The following metrics are exported:
.PP
In addition to the default Go metrics exported by the Prometheus Go client
\[la]https://prometheus.io/docs/guides/go-application/\[ra],
the following metrics are exported:
.IP \(bu 4
\fB\fCcoredns_build_info{version, revision, goversion}\fR - info about CoreDNS itself.
.IP \(bu 4
\fB\fCcoredns_panics_total{}\fR - total number of panics.
.IP \(bu 4
\fB\fCcoredns_dns_requests_total{server, zone, proto, family, type}\fR - total query count.
\fB\fCcoredns_dns_requests_total{server, zone, view, proto, family, type}\fR - total query count.
.IP \(bu 4
\fB\fCcoredns_dns_request_duration_seconds{server, zone, type}\fR - duration to process each query.
\fB\fCcoredns_dns_request_duration_seconds{server, zone, view, type}\fR - duration to process each query.
.IP \(bu 4
\fB\fCcoredns_dns_request_size_bytes{server, zone, proto}\fR - size of the request in bytes.
\fB\fCcoredns_dns_request_size_bytes{server, zone, view, proto}\fR - size of the request in bytes. Uses the original size before any plugin rewrites.
.IP \(bu 4
\fB\fCcoredns_dns_do_requests_total{server, zone}\fR - queries that have the DO bit set
\fB\fCcoredns_dns_do_requests_total{server, view, zone}\fR - queries that have the DO bit set
.IP \(bu 4
\fB\fCcoredns_dns_response_size_bytes{server, zone, proto}\fR - response size in bytes.
\fB\fCcoredns_dns_response_size_bytes{server, zone, view, proto}\fR - response size in bytes.
.IP \(bu 4
\fB\fCcoredns_dns_responses_total{server, zone, rcode}\fR - response per zone and rcode.
\fB\fCcoredns_dns_responses_total{server, zone, view, rcode, plugin}\fR - response per zone, rcode and plugin.
.IP \(bu 4
\fB\fCcoredns_plugin_enabled{server, zone, name}\fR - indicates whether a plugin is enabled on per server and zone basis.
\fB\fCcoredns_dns_https_responses_total{server, status}\fR - responses per server and http status code.
.IP \(bu 4
\fB\fCcoredns_dns_quic_responses_total{server, status}\fR - responses per server and QUIC application code.
.IP \(bu 4
\fB\fCcoredns_plugin_enabled{server, zone, view, name}\fR - indicates whether a plugin is enabled on per server, zone and view basis.
.PP
Each counter has a label \fB\fCzone\fR which is the zonename used for the request/response.
Almost each counter has a label \fB\fCzone\fR which is the zonename used for the request/response.
.PP
Extra labels used are:
@@ -48,14 +56,35 @@ this is \fB\fCdns://:53\fR. If you are using the \fIbind\fP plugin an IP address
The address family (\fB\fCfamily\fR) of the transport (1 = IP (IP version 4), 2 = IP6 (IP version 6)).
.IP \(bu 4
\fB\fCtype\fR which holds the query type. It holds most common types (A, AAAA, MX, SOA, CNAME, PTR, TXT,
NS, SRV, DS, DNSKEY, RRSIG, NSEC, NSEC3, IXFR, AXFR and ANY) and "other" which lumps together all
NS, SRV, DS, DNSKEY, RRSIG, NSEC, NSEC3, HTTPS, IXFR, AXFR and ANY) and "other" which lumps together all
other types.
.IP \(bu 4
\fB\fCstatus\fR which holds the https status code. Possible values are:
.RS
.IP \(en 4
200 - request is processed,
.IP \(en 4
404 - request has been rejected on validation,
.IP \(en 4
400 - request to dns message conversion failed,
.IP \(en 4
500 - processing ended up with no response.
.RE
.IP \(bu 4
the \fB\fCplugin\fR label holds the name of the plugin that made the write to the client. If the server
did the write (on error for instance), the value is empty.
.PP
If monitoring is enabled, queries that do not enter the plugin chain are exported under the fake
name "dropped" (without a closing dot - this is never a valid domain name).
.PP
Other plugins may export additional stats when the \fIprometheus\fP plugin is enabled. Those stats are documented in each
plugin's README.
.PP
This plugin can only be used once per Server Block.