• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 13494306182

24 Feb 2025 09:01AM UTC coverage: 60.607% (-1.6%) from 62.24%
13494306182

Pull #15203

github

web-flow
Merge 023bafd01 into 83beff6d6
Pull Request #15203: rec: switch back to serde_yaml

34838 of 90428 branches covered (38.53%)

Branch coverage included in aggregate %.

25 of 25 new or added lines in 1 file covered. (100.0%)

6482 existing lines in 72 files now uncovered.

120907 of 166548 relevant lines covered (72.6%)

4692544.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.12
/pdns/recursordist/rec-carbon.cc
1
#ifdef HAVE_CONFIG_H
2
#include "config.h"
3
#endif
4
#include "mtasker.hh"
5
#include "syncres.hh"
6
#include "rec_channel.hh"
7
#include "iputils.hh"
8
#include "logger.hh"
9
#include "logging.hh"
10
#include "arguments.hh"
11
#include "lock.hh"
12

13
GlobalStateHolder<CarbonConfig> g_carbonConfig;
14

15
void doCarbonDump(void*)
16
{
15✔
17
  auto log = g_slog->withName("carbon");
15✔
18
  try {
15✔
19
    static thread_local auto configHolder = g_carbonConfig.getLocal();
15✔
20

21
    auto config = *configHolder;
15✔
22
    if (config.servers.empty()) {
15!
23
      return;
15✔
24
    }
15✔
25

UNCOV
26
    if (config.namespace_name.empty()) {
×
27
      config.namespace_name = "pdns";
×
28
    }
×
29

UNCOV
30
    if (config.hostname.empty()) {
×
31
      try {
×
32
        config.hostname = getCarbonHostName();
×
33
      }
×
34
      catch (const std::exception& e) {
×
35
        throw std::runtime_error(std::string("The 'carbon-ourname' setting has not been set and we are unable to determine the system's hostname: ") + e.what());
×
36
      }
×
37
    }
×
UNCOV
38
    if (config.instance_name.empty()) {
×
39
      config.instance_name = "recursor";
×
40
    }
×
41

UNCOV
42
    PacketBuffer msg;
×
UNCOV
43
    for (const auto& carbonServer : config.servers) {
×
UNCOV
44
      ComboAddress remote(carbonServer, 2003);
×
UNCOV
45
      Socket s(remote.sin4.sin_family, SOCK_STREAM);
×
UNCOV
46
      s.setNonBlocking();
×
UNCOV
47
      std::shared_ptr<TLSCtx> tlsCtx{nullptr};
×
UNCOV
48
      const struct timeval timeout{
×
UNCOV
49
        g_networkTimeoutMsec / 1000, static_cast<suseconds_t>(g_networkTimeoutMsec) % 1000 * 1000};
×
UNCOV
50
      auto handler = std::make_shared<TCPIOHandler>("", false, s.releaseHandle(), timeout, tlsCtx);
×
UNCOV
51
      handler->tryConnect(SyncRes::s_tcp_fast_open_connect, remote); // we do the connect so the first attempt happens while we gather stats
×
52

UNCOV
53
      if (msg.empty()) {
×
UNCOV
54
        auto all = getAllStatsMap(StatComponent::Carbon);
×
55

UNCOV
56
        ostringstream str;
×
UNCOV
57
        time_t now = time(0);
×
58

UNCOV
59
        for (const auto& val : all) {
×
UNCOV
60
          str << config.namespace_name << '.' << config.hostname << '.' << config.instance_name << '.' << val.first << ' ' << val.second.d_value << ' ' << now << "\r\n";
×
UNCOV
61
        }
×
UNCOV
62
        const string& x = str.str();
×
UNCOV
63
        msg.insert(msg.end(), x.cbegin(), x.cend());
×
UNCOV
64
      }
×
65

UNCOV
66
      auto ret = asendtcp(msg, handler); // this will actually do the right thing waiting on the connect
×
UNCOV
67
      if (ret == LWResult::Result::Timeout) {
×
68
        SLOG(g_log << Logger::Warning << "Timeout connecting/writing carbon data to " << remote.toStringWithPort() << endl,
×
69
             log->info(Logr::Warning, "Timeout connecting/writing carbon data", "address", Logging::Loggable(remote)));
×
70
      }
×
UNCOV
71
      else if (ret != LWResult::Result::Success) {
×
72
        int err = errno;
×
73
        SLOG(g_log << Logger::Warning << "Error writing carbon data to " << remote.toStringWithPort() << ": " << stringerror(err) << endl,
×
74
             log->error(Logr::Warning, err, "Error writing carbon data", "address", Logging::Loggable(remote)));
×
75
      }
×
UNCOV
76
      handler->close();
×
UNCOV
77
    }
×
UNCOV
78
  }
×
79
  catch (const PDNSException& e) {
15✔
80
    SLOG(g_log << Logger::Error << "Error in carbon thread: " << e.reason << endl,
×
81
         log->error(Logr::Error, e.reason, "Error in carbon thread", "exception", Logging::Loggable("PDNSException")));
×
82
  }
×
83
  catch (const std::exception& e) {
15✔
84
    SLOG(g_log << Logger::Error << "Error in carbon thread: " << e.what() << endl,
×
85
         log->error(Logr::Error, e.what(), "Error in carbon thread", "exception", Logging::Loggable("std::exception")));
×
86
  }
×
87
  catch (...) {
15✔
88
    SLOG(g_log << Logger::Error << "Unknown error in carbon thread" << endl,
×
89
         log->info(Logr::Error, "Error in carbon thread"));
×
90
  }
×
91
}
15✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc