8000 feat: no more display latency for query in text format by dmachard · Pull Request #967 · dmachard/DNS-collector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: no more display latency for query in text format #967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dnsutils/dnsmessage_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,11 @@ func (dm *DNSMessage) ToTextLine(format []string, fieldDelimiter string, fieldBo
case directive == "qclass":
s.WriteString(dm.DNS.Qclass)
case directive == "latency":
s.WriteString(fmt.Sprintf("%.9f", dm.DNSTap.Latency))
if dm.DNS.Type == DNSQuery {
s.WriteByte('-')
} else {
s.WriteString(fmt.Sprintf("%.9f", dm.DNSTap.Latency))
}
case directive == "malformed":
if dm.DNS.MalformedPacket {
s.WriteString("PKTERR")
Expand Down
12 changes: 6 additions & 6 deletions dnsutils/dnsmessage_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestDnsMessage_TextFormat_ToString(t *testing.T) {
format: config.Global.TextFormat,
qname: "dnscollector.fr",
identity: "collector",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b dnscollector.fr A 0.000000000",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b dnscollector.fr A -",
},
{
name: "custom_delimiter",
Expand All @@ -37,7 +37,7 @@ func TestDnsMessage_TextFormat_ToString(t *testing.T) {
format: config.Global.TextFormat,
qname: "dnscollector.fr",
identity: "collector",
expected: "-;collector;CLIENT_QUERY;NOERROR;1.2.3.4;1234;-;-;0b;dnscollector.fr;A;0.000000000",
expected: "-;collector;CLIENT_QUERY;NOERROR;1.2.3.4;1234;-;-;0b;dnscollector.fr;A;-",
},
{
name: "empty_delimiter",
Expand All @@ -46,7 +46,7 @@ func TestDnsMessage_TextFormat_ToString(t *testing.T) {
format: config.Global.TextFormat,
qname: "dnscollector.fr",
identity: "collector",
expected: "-collectorCLIENT_QUERYNOERROR1.2.3.41234--0bdnscollector.frA0.000000000",
expected: "-collectorCLIENT_QUERYNOERROR1.2.3.41234--0bdnscollector.frA-",
},
{
name: "qname_quote",
Expand All @@ -55,7 +55,7 @@ func TestDnsMessage_TextFormat_ToString(t *testing.T) {
format: config.Global.TextFormat,
qname: "dns collector.fr",
identity: "collector",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b \"dns collector.fr\" A 0.000000000",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b \"dns collector.fr\" A -",
},
{
name: "default_boundary",
Expand All @@ -64,7 +64,7 @@ func TestDnsMessage_TextFormat_ToString(t *testing.T) {
format: config.Global.TextFormat,
qname: "dns\"coll tor\".fr",
identity: "collector",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b \"dns\\\"coll tor\\\".fr\" A 0.000000000",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b \"dns\\\"coll tor\\\".fr\" A -",
},
{
name: "custom_boundary",
Expand All @@ -73,7 +73,7 @@ func TestDnsMessage_TextFormat_ToString(t *testing.T) {
format: config.Global.TextFormat,
qname: "dnscoll tor.fr",
identity: "collector",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b !dnscoll tor.fr! A 0.000000000",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b !dnscoll tor.fr! A -",
},
{
name: "custom_text",
Expand Down
10 changes: 5 additions & 5 deletions workers/stdout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@ func Test_StdoutTextMode(t *testing.T) {
delimiter: cfg.Global.TextFormatDelimiter,
boundary: cfg.Global.TextFormatBoundary,
qname: pkgconfig.ProgQname,
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b dns.collector A 0.000000000\n",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b dns.collector A -\n",
},
{
name: "custom_delimiter",
delimiter: ";",
boundary: cfg.Global.TextFormatBoundary,
qname: pkgconfig.ProgQname,
expected: "-;collector;CLIENT_QUERY;NOERROR;1.2.3.4;1234;-;-;0b;dns.collector;A;0.000000000\n",
expected: "-;collector;CLIENT_QUERY;NOERROR;1.2.3.4;1234;-;-;0b;dns.collector;A;-\n",
},
{
name: "default_boundary",
delimiter: cfg.Global.TextFormatDelimiter,
boundary: cfg.Global.TextFormatBoundary,
qname: "dns. collector",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b \"dns. collector\" A 0.000000000\n",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b \"dns. collector\" A -\n",
},
{
name: "custom_boundary",
delimiter: cfg.Global.TextFormatDelimiter,
boundary: "!",
qname: "dns. collector",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b !dns. collector! A 0.000000000\n",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b !dns. collector! A -\n",
},
{
name: "boundary_in_qname",
delimiter: cfg.Global.TextFormatDelimiter,
boundary: cfg.Global.TextFormatBoundary,
qname: "d ns.\"collector\"",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b \"d ns.\\\"collector\\\"\" A 0.000000000\n",
expected: "- collector CLIENT_QUERY NOERROR 1.2.3.4 1234 - - 0b \"d ns.\\\"collector\\\"\" A -\n",
},
}

Expand Down
0