One case goes wrong: old-style tracing enabled and OT tracing enabled, but traceid_only is set
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
return false;
}
-static bool match(const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source, const DNSName& qname, QType qtype, uint16_t qid, bool edns_option_present)
+bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source)
+{
+ if (conditions == nullptr || conditions->size() == 0) {
+ return false;
+ }
+ if (auto const* match = conditions->lookup(source); match != nullptr) {
+ const auto& condition = match->second;
+ if (condition.d_traceid_only) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source, const DNSName& qname, QType qtype, uint16_t qid, bool edns_option_present)
{
if (conditions == nullptr || conditions->size() == 0) {
- cerr << "match 0 false" << endl;
return false;
}
if (auto const* match = conditions->lookup(source); match != nullptr) {
- cerr << "match 1" << endl;
const auto& condition = match->second;
if (condition.d_traceid_only) {
- cerr << "match 2 false" << endl;
return false;
}
if (condition.d_edns_option_required && !edns_option_present) {
- cerr << "match 3 false" << endl;
return false;
}
if (condition.d_qid && condition.d_qid != qid) {
- cerr << "match 4 false" << endl;
return false;
}
if (condition.d_qtypes && condition.d_qtypes->count(qtype) == 0) {
- cerr << "match 5 false" << endl;
return false;
}
if (condition.d_qnames && !condition.d_qnames->check(qname)) {
- cerr << "match 6 false" << endl;
return false;
}
}
- cerr << "match return true" << endl;
return true;
}
if (SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
bool ednsFound = pdns::trace::extractOTraceIDs(ednsOptions, otTrace);
- if (!match(t_OTConditions, source, qname, qtype, ntohs(headerdata->id), ednsFound)) {
+ if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(t_OTConditions, mappedSource, qname, qtype, ntohs(headerdata->id), ednsFound)) {
eventTrace.setEnabled(false);
}
}
destination = destaddr;
}
+ if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(t_OTConditions, mappedSource)) {
+ eventTrace.setEnabled(false);
+ }
eventTrace.add(RecEventTrace::ReqRecv, 0, false, match);
if (RecThreadInfo::weDistributeQueries()) {
std::string localdata = data;
pbMessage.setNewlyObservedDomain(false);
}
#endif
- if (eventTrace.enabled() && (SyncRes::s_event_trace_enabled & SyncRes::event_trace_to_pb) != 0) {
+ if (eventTrace.enabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_pb)) {
pbMessage.addEvents(eventTrace);
}
- if (eventTrace.enabled() && (SyncRes::s_event_trace_enabled & SyncRes::event_trace_to_ot) != 0) {
+ if (eventTrace.enabled() && SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
auto trace = pdns::trace::TracesData::boilerPlate("rec", eventTrace.convertToOT(otTrace),
{{"query.qname", {qname.toLogString()}},
{"query.qtype", {qtype.toString()}}},
void requestWipeCaches(const DNSName& canon);
void startDoResolve(void*);
bool expectProxyProtocol(const ComboAddress& from, const ComboAddress& listenAddress);
+bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source);
+bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source, const DNSName& qname, QType qtype, uint16_t qid, bool edns_option_present);
void finishTCPReply(std::unique_ptr<DNSComboWriter>&, bool hadError, bool updateInFlight);
void checkFastOpenSysctl(bool active, Logr::log_t);
void checkTFOconnect(Logr::log_t);
boost::optional<uint32_t> ednsVersion;
comboWriter->d_eventTrace.setEnabled(SyncRes::s_event_trace_enabled != 0);
+ if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(t_OTConditions, comboWriter->d_mappedSource)) {
+ comboWriter->d_eventTrace.setEnabled(false);
+ }
+
// eventTrace uses monotonic time, while OpenTelemetry uses absolute time. setEnabled()
// established the reference point, get an absolute TS as close as possible to the
// eventTrace start of trace time.
qnameParsed = true;
if (SyncRes::eventTraceEnabled(SyncRes::event_trace_to_ot)) {
- pdns::trace::extractOTraceIDs(ednsOptions, comboWriter->d_otTrace);
+ bool ednsFound = pdns::trace::extractOTraceIDs(ednsOptions, comboWriter->d_otTrace);
+ if (SyncRes::eventTraceEnabledOnly(SyncRes::event_trace_to_ot) && !matchOTConditions(t_OTConditions, comboWriter->d_mappedSource, qname, qtype, ntohs(comboWriter->d_mdp.d_header.id), ednsFound)) {
+ comboWriter->d_eventTrace.setEnabled(false);
+ }
}
if (t_pdl) {
try {
{
return (s_event_trace_enabled & flag) != 0;
}
+ static bool eventTraceEnabledOnly(int flag)
+ {
+ return s_event_trace_enabled == flag;
+ }
std::unordered_map<std::string, bool> d_discardedPolicies;
DNSFilterEngine::Policy d_appliedPolicy;
std::unordered_set<std::string> d_policyTags;