]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
fix(dnsdist): Add type of Rule to each Rule trace
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 26 Nov 2025 13:52:45 +0000 (14:52 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 12 Dec 2025 15:30:51 +0000 (16:30 +0100)
pdns/dnsdistdist/dnsdist-idstate.cc
pdns/dnsdistdist/dnsdist-idstate.hh
pdns/dnsdistdist/dnsdist.cc
regression-tests.dnsdist/test_OpenTelemetryTracing.py

index 37fb3a8e1db33288a4b9a303030d558ddca138e4..19a92f66514489ff1ac2ab7f03ef0f55271ac774 100644 (file)
@@ -135,7 +135,7 @@ std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getClose
   return ret;
 }
 
-std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName)
+std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName, [[maybe_unused]] const std::string& ruleType)
 {
   std::optional<pdns::trace::dnsdist::Tracer::Closer> ret(std::nullopt);
 #ifndef DISABLE_PROTOBUF
@@ -145,7 +145,7 @@ std::optional<pdns::trace::dnsdist::Tracer::Closer> 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<pdns::trace::dnsdist::Tracer::Closer>(d_OTTracer->openSpan(name, parentSpanID));
   }
 #endif
index fec10cefdb276edbdbcfa8c1930b233106791a1f..93de5908249a50af19385783e04379cb1c6aae6f 100644 (file)
@@ -151,7 +151,7 @@ struct InternalQueryState
   std::optional<pdns::trace::dnsdist::Tracer::Closer> getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const SpanID& parentSpanID);
   std::optional<pdns::trace::dnsdist::Tracer::Closer> getCloser([[maybe_unused]] const std::string_view& name, [[maybe_unused]] const std::string_view& parentSpanName);
   std::optional<pdns::trace::dnsdist::Tracer::Closer> getCloser([[maybe_unused]] const std::string_view& name);
-  std::optional<pdns::trace::dnsdist::Tracer::Closer> getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName);
+  std::optional<pdns::trace::dnsdist::Tracer::Closer> getRulesCloser([[maybe_unused]] const std::string_view& ruleName, [[maybe_unused]] const std::string_view& parentSpanName, [[maybe_unused]] const std::string& ruleType);
 
   InternalQueryState()
   {
index 877db4f2ade7e927d1825e1568c1b33e9de30541..d66c4a483cf853cc288ef01f69323c708b621755 100644 (file)
@@ -463,9 +463,10 @@ bool applyRulesToResponse(const std::vector<dnsdist::rules::ResponseRuleAction>&
 
   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<dnsdist::rules::RuleAction>
   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;
index 8a7837261765bba05c5139983514a32be8a8c8b6..3f90fa73294b005800f032a6ecb7e8005fb9bfbe 100644 (file)
@@ -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",
             },
         )