return ret;
}
+ std::vector<DNSName> toVector() const
+ {
+ std::vector<DNSName> ret;
+ for (const auto& n : d_nodes) {
+ ret.emplace_back(n);
+ }
+ return ret;
+ }
+
private:
mutable std::set<DNSName> d_nodes; // Only used for string generation
};
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<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;
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
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;
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;
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);
}
(&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", "otconditions"]) => {
+ *apifunc = Some(rustweb::apiServerOTConditionsGET);
+ }
+ (&Method::GET, ["api", "v1", "servers", "localhost", "otconditions", id]) => {
+ let decoded = form_urlencoded::parse(id.as_bytes());
+ // decoded should contain a single key without value
+ if let Some(kv) = decoded.last() {
+ request.parameters.push(rustweb::KeyValue {
+ key: String::from("id"),
+ value: kv.0.to_string(),
+ });
+ }
+ *apifunc = Some(rustweb::apiServerOTConditionDetailGET)
+ }
_ => *filefunc = Some(file),
}
}
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 jsonstat(request: &Request, response: &mut Response) -> Result<()>;
fn prometheusMetrics(request: &Request, response: &mut Response) -> Result<()>;
fn serveStuff(request: &Request, response: &mut Response) -> Result<()>;
WRAPPER(apiServerZoneDetailPUT)
WRAPPER(apiServerZonesGET)
WRAPPER(apiServerZonesPOST)
+WRAPPER(apiServerOTConditionsGET)
+WRAPPER(apiServerOTConditionDetailGET)
WRAPPER(jsonstat)
WRAPPER(prometheusMetrics)
WRAPPER(serveStuff)
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);
resp->setJsonBody(ret);
}
+static void apiServerOTConditionsGET(HttpRequest* /* req */, HttpResponse* resp)
+{
+ Json::array doc;
+ auto lock = g_initialOpenTelemetryConditions.lock();
+ if (*lock) {
+ for (const auto& condition : **lock) {
+ Json::object object{
+ {"acl", condition.first.toString()},
+ {"edns_option_required", condition.second.d_edns_option_required},
+ {"traceid_only", condition.second.d_traceid_only},
+ };
+ if (condition.second.d_qid) {
+ object.emplace("qid", *condition.second.d_qid);
+ }
+ if (condition.second.d_qnames) {
+ Json::array array;
+ for (const auto& name : condition.second.d_qnames->toVector()) {
+ array.emplace_back(name.toString());
+ }
+ object.emplace("qnames", array);
+ }
+ if (condition.second.d_qtypes) {
+ Json::array array;
+ for (const auto& name : *condition.second.d_qtypes) {
+ array.emplace_back(name.toString());
+ }
+ object.emplace("qtypes", array);
+ }
+
+ doc.emplace_back(std::move(object));
+ }
+ }
+ resp->setJsonBody(doc);
+}
+
+static void fillOTCondition(const Netmask& netmask, HttpResponse* resp)
+{
+ Json::array doc;
+ auto lock = g_initialOpenTelemetryConditions.lock();
+ if (*lock) {
+ auto condition = (*lock)->lookup(netmask);
+ if (condition != nullptr) {
+ Json::object object{
+ {"acl", condition->first.toString()},
+ {"edns_option_required", condition->second.d_edns_option_required},
+ {"traceid_only", condition->second.d_traceid_only},
+ };
+ if (condition->second.d_qid) {
+ object.emplace("qid", *condition->second.d_qid);
+ }
+ if (condition->second.d_qnames) {
+ Json::array array;
+ for (const auto& name : condition->second.d_qnames->toVector()) {
+ array.emplace_back(name.toString());
+ }
+ object.emplace("qnames", array);
+ }
+ if (condition->second.d_qtypes) {
+ Json::array array;
+ for (const auto& name : *condition->second.d_qtypes) {
+ array.emplace_back(name.toString());
+ }
+ object.emplace("qtypes", array);
+ }
+ resp->setJsonBody(object);
+ return;
+ }
+ }
+ throw ApiException("Could not find otcondition '" + netmask.toString() + "'");
+}
+
+static void apiServerOTConditionDetailGET(HttpRequest* req, HttpResponse* resp)
+{
+ try {
+ cerr << req->parameters["id"] << endl;
+ Netmask netmask{req->parameters["id"]};
+ cerr << netmask.toString() << endl;
+ fillOTCondition(netmask, resp);
+ }
+ catch (NetmaskException& ex) {
+ throw ApiException("Could not parse netmask");
+ }
+}
+
static void prometheusMetrics(HttpRequest* /* req */, HttpResponse* resp)
{
static MetricDefinitionStorage s_metricDefinitions;
WRAPPER(apiServerZoneDetailPUT)
WRAPPER(apiServerZonesGET)
WRAPPER(apiServerZonesPOST)
+WRAPPER(apiServerOTConditionsGET)
+WRAPPER(apiServerOTConditionDetailGET)
WRAPPER(prometheusMetrics)
WRAPPER(serveStuff)