Skip to content
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
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ oskar
otherdomain
otherpool
othervariant
ottracecondition
ourname
ourserial
outpacket
Expand Down
10 changes: 10 additions & 0 deletions pdns/dnsname.hh
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,16 @@ struct SuffixMatchNode
return ret;
}

std::vector<DNSName> toVector() const
{
std::vector<DNSName> ret;
ret.reserve(d_nodes.size());
for (const auto& n : d_nodes) {
ret.emplace_back(n);
}
return ret;
}

private:
mutable std::set<DNSName> d_nodes; // Only used for string generation
};
Expand Down
32 changes: 32 additions & 0 deletions pdns/recursordist/docs/http-api/endpoint-ottraceconditions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
OpenTelemetryTraceConditions endpoint
=====================================

.. Note::
All modifications using this endpoint are not persistent.
Reloading the configuration using ``rec_control reload-yaml`` will revert the trace conditions back to the conditions read from the configuration file(s).

.. http:get:: /api/v1/servers/:server_id/ottraceconditions

Get all :json:object:`OpenTelemetryTraceCondition` from the server. Note that while the settings file allows a list of subnets to be associated with a condition, this list will be flattened, with only one subnet per condition.

:query server_id: The name of the server

.. http:post:: /api/v1/servers/:server_id/ottraceconditions

Creates a new trace condition. The client body must contain a :json:object:`OpenTelemetryTraceCondition`.

:query server_id: The name of the server

.. http:get:: /api/v1/servers/:server_id/ottraceconditions/:ip/:prefixlen

Returns trace condition information.

:query server_id: The name of the server
:query ip/prefixlen: The subnet of the :json:object:`OpenTelemetryTraceCondition`.

.. http:delete:: /api/v1/servers/:server_id/ottraceconditions/:ip/:prefixlen

Deletes this zone, all attached metadata and rrsets.

:query server_id: The name of the server
:query ip/prefixlen: The subnet of the :json:object:`OpenTelemetryTraceCondition`.
3 changes: 2 additions & 1 deletion pdns/recursordist/docs/http-api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The following documents contain the information for the PowerDNS API:
zone
../common/api/configsetting
../common/api/statisticitem

ottracecondition

Webserver
---------
Expand Down Expand Up @@ -104,3 +104,4 @@ All API endpoints for the PowerDNS Recursor are documented here:
endpoint-failure
endpoint-rpz-stats
endpoint-jsonstat
endpoint-ottraceconditions
32 changes: 32 additions & 0 deletions pdns/recursordist/docs/http-api/ottracecondition.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
OpenTelemetryTraceCondition
---------------------------

An ``OpenTelemetryTraceCondition`` object represents a condition to trigger generating :ref:`opentelemetry_tracing`.
These conditions con be configured in a settings file (see :ref:`setting-yaml-logging.opentelemetry_trace_conditions`) or manipulated at runtime using the REST API calls listed in :doc:`endpoint-ottraceconditions`.

.. json:object:: OpenTelemetryTraceCondition

Represents an OpenTelemetryTrace condition.

:property string acl: The subnet of the entry. Note that the YAML settings file allows multiple subnets for convenience. This object does not allow multiple subnets to be specified.
:property string type: set to "OpenTelemetryTraceCondition"
:property bool edns_option_required: See :ref:`opentelemetry_tracing`
:property number qid: A specific query id
:property [DNSName] qnames: List of names
:property [QType] qtypes: List of qtypes, represented as string
:property bool traceid_only: See :ref:`opentelemetry_tracing`

**Example**:

.. code-block:: json

{
"acl": "192.0.2.1/32",
"edns_option_required": false,
"qid": 1,
"qnames": ["example.com.", "example.net."],
"qtypes": ["AAAA", "A"],
"traceid_only": false
"type": "OpenTelemetryTraceCondition"
}

8 changes: 5 additions & 3 deletions pdns/recursordist/pdns_recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2156,8 +2156,9 @@ bool matchOTConditions(const std::unique_ptr<OpenTelemetryTraceConditions>& cond
if (condition.d_traceid_only) {
return false;
}
return true;
}
return true;
return false;
}

bool matchOTConditions(RecEventTrace& eventTrace, const std::unique_ptr<OpenTelemetryTraceConditions>& conditions, const ComboAddress& source, const DNSName& qname, QType qtype, uint16_t qid, bool edns_option_present)
Expand All @@ -2182,10 +2183,11 @@ bool matchOTConditions(RecEventTrace& eventTrace, const std::unique_ptr<OpenTele
if (condition.d_qnames && !condition.d_qnames->check(qname)) {
return false;
}
eventTrace.setThisOTTraceEnabled();
return true;
}

eventTrace.setThisOTTraceEnabled();
return true;
return false;
}

// fromaddr: the address from which the query is coming
Expand Down
8 changes: 4 additions & 4 deletions pdns/recursordist/rec-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ uint32_t g_disthashseed;
bool g_useIncomingECS;
static shared_ptr<NetmaskGroup> g_initialProxyProtocolACL;
static shared_ptr<std::set<ComboAddress>> g_initialProxyProtocolExceptions;
static shared_ptr<OpenTelemetryTraceConditions> g_initialOpenTelemetryConditions; // XXX shared ptr needed?
std::optional<ComboAddress> g_dns64Prefix{std::nullopt};
DNSName g_dns64PrefixReverse;
unsigned int g_maxChainLength;
LockGuarded<std::shared_ptr<SyncRes::domainmap_t>> g_initialDomainMap; // new threads needs this to be setup
LockGuarded<std::shared_ptr<NetmaskGroup>> g_initialAllowFrom; // new thread needs to be setup with this
LockGuarded<std::shared_ptr<NetmaskGroup>> g_initialAllowNotifyFrom; // new threads need this to be setup
LockGuarded<std::shared_ptr<notifyset_t>> g_initialAllowNotifyFor; // new threads need this to be setup
LockGuarded<std::shared_ptr<OpenTelemetryTraceConditions>> g_initialOpenTelemetryConditions; // new threads need this to be setup
static time_t s_statisticsInterval;
static std::atomic<uint32_t> s_counter;
int g_argc;
Expand All @@ -129,7 +129,6 @@ std::vector<RecThreadInfo> RecThreadInfo::s_threadInfos;
std::unique_ptr<ProxyMapping> g_proxyMapping; // new threads needs this to be setup
thread_local std::unique_ptr<ProxyMapping> t_proxyMapping;

std::unique_ptr<OpenTelemetryTraceConditions> g_OTConditions; // new threads needs this to be setup
thread_local std::unique_ptr<OpenTelemetryTraceConditions> t_OTConditions;

bool RecThreadInfo::s_weDistributeQueries; // if true, 1 or more threads listen on the incoming query sockets and distribute them to workers
Expand Down Expand Up @@ -2790,8 +2789,9 @@ static void recursorThread()
else {
t_proxyMapping = nullptr;
}
if (g_OTConditions) {
t_OTConditions = make_unique<OpenTelemetryTraceConditions>(*g_OTConditions);
auto lock = g_initialOpenTelemetryConditions.lock();
if (*lock) {
t_OTConditions = make_unique<OpenTelemetryTraceConditions>(**lock);
}
else {
t_OTConditions = nullptr;
Expand Down
1 change: 1 addition & 0 deletions pdns/recursordist/rec-main.hh
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ extern LockGuarded<std::shared_ptr<SyncRes::domainmap_t>> g_initialDomainMap; //
extern LockGuarded<std::shared_ptr<NetmaskGroup>> g_initialAllowFrom; // new thread needs to be setup with this
extern LockGuarded<std::shared_ptr<NetmaskGroup>> g_initialAllowNotifyFrom; // new threads need this to be setup
extern LockGuarded<std::shared_ptr<notifyset_t>> g_initialAllowNotifyFor; // new threads need this to be setup
extern LockGuarded<std::shared_ptr<OpenTelemetryTraceConditions>> g_initialOpenTelemetryConditions; // new threads need this to be set
extern thread_local std::shared_ptr<Regex> t_traceRegex;
extern thread_local FDWrapper t_tracefd;
extern string g_programname;
Expand Down
4 changes: 4 additions & 0 deletions pdns/recursordist/rec-rust-lib/rust/src/bridge.hh
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ void apiServerSearchData(const Request& rustRequest, Response& rustResponse);
void apiServerZoneDetailGET(const Request& rustRequest, Response& rustResponse);
void apiServerZoneDetailPUT(const Request& rustRequest, Response& rustResponse);
void apiServerZoneDetailDELETE(const Request& rustRequest, Response& rustResponse);
void apiServerOTConditionsGET(const Request& rustRequest, Response& rustResponse);
void apiServerOTConditionDetailGET(const Request& rustRequest, Response& rustResponse);
void apiServerOTConditionDetailDELETE(const Request& rustRequest, Response& rustResponse);
void apiServerOTConditionDetailPOST(const Request& rustRequest, Response& rustResponse);
}
24 changes: 24 additions & 0 deletions pdns/recursordist/rec-rust-lib/rust/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,26 @@ fn matcher(
(&Method::GET, ["api", "v1"]) => *apifunc = Some(rustweb::apiDiscoveryV1),
(&Method::GET, ["api"]) => *apifunc = Some(rustweb::apiDiscovery),
(&Method::GET, ["metrics"]) => *rawfunc = Some(rustweb::prometheusMetrics),
(&Method::GET, ["api", "v1", "servers", "localhost", "ottraceconditions"]) => {
*apifunc = Some(rustweb::apiServerOTConditionsGET);
}
(&Method::GET, ["api", "v1", "servers", "localhost", "ottraceconditions", ip, pflen]) => {
request.parameters.push(rustweb::KeyValue {
key: String::from("acl"),
value: String::from(*ip) + "/" + *pflen,
});
*apifunc = Some(rustweb::apiServerOTConditionDetailGET)
}
(&Method::DELETE, ["api", "v1", "servers", "localhost", "ottraceconditions", ip, pflen]) => {
request.parameters.push(rustweb::KeyValue {
key: String::from("acl"),
value: String::from(*ip) + "/" + *pflen,
});
*apifunc = Some(rustweb::apiServerOTConditionDetailDELETE)
}
(&Method::POST, ["api", "v1", "servers", "localhost", "ottraceconditions"]) => {
*apifunc = Some(rustweb::apiServerOTConditionDetailPOST)
}
_ => *filefunc = Some(file),
}
}
Expand Down Expand Up @@ -1146,6 +1166,10 @@ mod rustweb {
fn apiServerZoneDetailPUT(request: &Request, response: &mut Response) -> Result<()>;
fn apiServerZonesGET(request: &Request, response: &mut Response) -> Result<()>;
fn apiServerZonesPOST(requst: &Request, response: &mut Response) -> Result<()>;
fn apiServerOTConditionsGET(request: &Request, response: &mut Response) -> Result<()>;
fn apiServerOTConditionDetailGET(request: &Request, response: &mut Response) -> Result<()>;
fn apiServerOTConditionDetailDELETE(request: &Request, response: &mut Response) -> Result<()>;
fn apiServerOTConditionDetailPOST(request: &Request, response: &mut Response) -> Result<()>;
fn jsonstat(request: &Request, response: &mut Response) -> Result<()>;
fn prometheusMetrics(request: &Request, response: &mut Response) -> Result<()>;
fn serveStuff(request: &Request, response: &mut Response) -> Result<()>;
Expand Down
4 changes: 4 additions & 0 deletions pdns/recursordist/rec-web-stubs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ WRAPPER(apiServerZoneDetailGET)
WRAPPER(apiServerZoneDetailPUT)
WRAPPER(apiServerZonesGET)
WRAPPER(apiServerZonesPOST)
WRAPPER(apiServerOTConditionsGET)
WRAPPER(apiServerOTConditionDetailGET)
WRAPPER(apiServerOTConditionDetailDELETE)
WRAPPER(apiServerOTConditionDetailPOST)
WRAPPER(jsonstat)
WRAPPER(prometheusMetrics)
WRAPPER(serveStuff)
Expand Down
2 changes: 2 additions & 0 deletions pdns/recursordist/rec_channel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@ void registerAllStats();
void doExitNicely();
RecursorControlChannel::Answer doQueueReloadLuaScript(vector<string>::const_iterator begin, vector<string>::const_iterator end);
RecursorControlChannel::Answer luaconfig(bool broadcast);
struct OpenTelemetryTraceCondition;
void updateOTConditions(const NetmaskTree<OpenTelemetryTraceCondition>& conditions);
11 changes: 9 additions & 2 deletions pdns/recursordist/rec_channel_rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,12 @@ static void* pleaseSupplantOTConditions(const OpenTelemetryTraceConditions& cond
return nullptr;
}

void updateOTConditions(const OpenTelemetryTraceConditions& conditions)
{
// XXX YAML settings are not updated, so rec_control get-parameter won't show runtime updated conditions
broadcastFunction([conditions] { return pleaseSupplantOTConditions(conditions); });
}

static RecursorControlChannel::Answer help(ArgIterator /* begin */, ArgIterator /* end */)
{
static const std::map<std::string, std::string> commands = {
Expand Down Expand Up @@ -2123,14 +2129,15 @@ RecursorControlChannel::Answer luaconfig(bool broadcast)
lci = g_luaconfs.getCopy();
if (broadcast) {
startLuaConfigDelayedThreads(lci, lci.generation);

*g_initialOpenTelemetryConditions.lock() = conditions.empty() ? nullptr : std::make_unique<OpenTelemetryTraceConditions>(conditions);
broadcastFunction([pmap = std::move(proxyMapping)] { return pleaseSupplantProxyMapping(pmap); });
broadcastFunction([conds = std::move(conditions)] { return pleaseSupplantOTConditions(conds); });
}
else {
extern std::unique_ptr<OpenTelemetryTraceConditions> g_OTConditions;
// Initial proxy mapping
g_proxyMapping = proxyMapping.empty() ? nullptr : std::make_unique<ProxyMapping>(proxyMapping);
g_OTConditions = conditions.empty() ? nullptr : std::make_unique<OpenTelemetryTraceConditions>(conditions);
*g_initialOpenTelemetryConditions.lock() = conditions.empty() ? nullptr : std::make_unique<OpenTelemetryTraceConditions>(conditions);
}
TCPOutConnectionManager::setupOutgoingTLSConfigTables(settings);

Expand Down
Loading
Loading