From: Pieter Lexis Date: Wed, 26 Nov 2025 13:52:45 +0000 (+0100) Subject: fix(dnsdist): Add type of Rule to each Rule trace X-Git-Tag: rec-5.4.0-beta1~65^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d10787abfbf0b8851bc65467153348d7eceb559d;p=thirdparty%2Fpdns.git fix(dnsdist): Add type of Rule to each Rule trace --- diff --git a/pdns/dnsdistdist/dnsdist-idstate.cc b/pdns/dnsdistdist/dnsdist-idstate.cc index 37fb3a8e1d..19a92f6651 100644 --- a/pdns/dnsdistdist/dnsdist-idstate.cc +++ b/pdns/dnsdistdist/dnsdist-idstate.cc @@ -135,7 +135,7 @@ std::optional InternalQueryState::getClose return ret; } -std::optional InternalQueryState::getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName) +std::optional InternalQueryState::getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName, [[maybe_unused]] const std::string& ruleType) { std::optional ret(std::nullopt); #ifndef DISABLE_PROTOBUF @@ -145,7 +145,7 @@ std::optional InternalQueryState::getRules // Should tracing be disabled, *but* we have not processed query rules, we will still return a closer if tracing is globally enabled if (auto tracer = getTracer(); tracer != nullptr && (tracingEnabled || !rulesAppliedToQuery)) { auto parentSpanID = d_OTTracer->getLastSpanIDForName(std::string(parentSpanName)); - auto name = prefix + std::string(ruleName); + auto name = ruleType + prefix + std::string(ruleName); ret = std::optional(d_OTTracer->openSpan(name, parentSpanID)); } #endif diff --git a/pdns/dnsdistdist/dnsdist-idstate.hh b/pdns/dnsdistdist/dnsdist-idstate.hh index fec10cefdb..93de590824 100644 --- a/pdns/dnsdistdist/dnsdist-idstate.hh +++ b/pdns/dnsdistdist/dnsdist-idstate.hh @@ -151,7 +151,7 @@ struct InternalQueryState std::optional getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const SpanID& parentSpanID); std::optional getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const std::string_view& parentSpanName); std::optional getCloser([[maybe_unused]] const std::string_view& name); - std::optional getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName); + std::optional getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName, [[maybe_unused]] const std::string& ruleType); InternalQueryState() { diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 877db4f2ad..d66c4a483c 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -463,9 +463,10 @@ bool applyRulesToResponse(const std::vector& DNSResponseAction::Action action = DNSResponseAction::Action::None; std::string ruleresult; + static const std::string ruleType = "Response"; for (const auto& rrule : respRuleActions) { - auto ruleCloser = dnsResponse.ids.getRulesCloser(rrule.d_name, __func__); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) + auto ruleCloser = dnsResponse.ids.getRulesCloser(rrule.d_name, __func__, ruleType); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) if (rrule.d_rule->matches(&dnsResponse)) { ++rrule.d_rule->d_matches; action = (*rrule.d_action)(&dnsResponse, &ruleresult); @@ -1022,9 +1023,10 @@ static bool applyRulesChainToQuery(const std::vector bool drop = false; auto closer = dnsQuestion.ids.getCloser(__func__); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) + static const std::string ruleType; // Empty string for (const auto& rule : rules) { - auto ruleCloser = dnsQuestion.ids.getRulesCloser(rule.d_name, __func__); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) + auto ruleCloser = dnsQuestion.ids.getRulesCloser(rule.d_name, __func__, ruleType); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) if (!rule.d_rule->matches(&dnsQuestion)) { continue; diff --git a/regression-tests.dnsdist/test_OpenTelemetryTracing.py b/regression-tests.dnsdist/test_OpenTelemetryTracing.py index 8a78372617..3f90fa7329 100644 --- a/regression-tests.dnsdist/test_OpenTelemetryTracing.py +++ b/regression-tests.dnsdist/test_OpenTelemetryTracing.py @@ -150,7 +150,7 @@ class DNSDistOpenTelemetryProtobufTest(test_Protobuf.DNSDistProtobufTest): funcs.add("processResponse") if hasRemoteLogResponseAction: - funcs.add("Rule: Do PB logging") + funcs.add("ResponseRule: Do PB logging") if useTCP: funcs.add("IncomingTCPConnectionState::handleQuery") @@ -580,7 +580,7 @@ response_rules: hasRemoteLogResponseAction=False, useTCP=useTCP, extraFunctions={ - "Rule: Drop", + "ResponseRule: Drop", }, )