Skip to content

Commit f0abaad

Browse files
Remove all uses of logger now that we're done debugging system-tests issues. Also remove unused code.
1 parent 70d6db4 commit f0abaad

File tree

4 files changed

+10
-31
lines changed

4 files changed

+10
-31
lines changed

src/datadog/datadog_agent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ DatadogAgent::DatadogAgent(
171171
// Origin Detection headers are not necessary when Unix Domain Socket (UDS)
172172
// is used to communicate with the Datadog Agent.
173173
if (!contains(config.url.scheme, "unix")) {
174-
if (auto container_id = container::get_id(logger_)) {
174+
if (auto container_id = container::get_id()) {
175175
if (container_id->type == container::ContainerID::Type::container_id) {
176176
headers_.emplace("Datadog-Container-ID", container_id->value);
177177
headers_.emplace("Datadog-Entity-Id", "ci-" + container_id->value);

src/datadog/platform_util.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <cstdint>
55
#include <fstream>
66
#include <iostream>
7-
#include <memory>
87
#include <regex>
98

109
// clang-format off
@@ -46,8 +45,6 @@
4645
#endif
4746
// clang-format on
4847

49-
#include <datadog/logger.h>
50-
5148
namespace datadog {
5249
namespace tracing {
5350
namespace {
@@ -295,18 +292,10 @@ Expected<InMemoryFile> InMemoryFile::make(StringView) {
295292
namespace container {
296293
namespace {
297294
#if defined(__linux__) || defined(__unix__)
298-
/// Magic numbers from linux/magic.h:
299-
/// <https://github.com/torvalds/linux/blob/ca91b9500108d4cf083a635c2e11c884d5dd20ea/include/uapi/linux/magic.h#L71>
300-
// constexpr uint64_t CGROUP_SUPER_MAGIC = 0x27e0eb;
301-
// constexpr uint64_t CGROUP2_SUPER_MAGIC = 0x63677270;
302-
303295
/// Magic number from linux/proc_ns.h:
304296
/// <https://github.com/torvalds/linux/blob/5859a2b1991101d6b978f3feb5325dad39421f29/include/linux/proc_ns.h#L41-L49>
305297
constexpr ino_t HOST_CGROUP_NAMESPACE_INODE = 0xeffffffb;
306298

307-
/// Represents the cgroup version of the current process.
308-
// enum class Cgroup : char { v1, v2 };
309-
310299
Optional<ino_t> get_inode(std::string_view path) {
311300
struct stat buf;
312301
if (stat(path.data(), &buf) != 0) {
@@ -329,21 +318,18 @@ bool is_running_in_host_namespace() {
329318
return false;
330319
}
331320

332-
Optional<std::string> find_container_id_from_cgroup(
333-
const std::shared_ptr<tracing::Logger>& logger) {
321+
Optional<std::string> find_container_id_from_cgroup() {
334322
auto cgroup_fd = std::ifstream("/proc/self/cgroup", std::ios::in);
335323
if (!cgroup_fd.is_open()) {
336-
logger->log_error("failed to open /proc/self/cgroup");
337324
return nullopt;
338325
}
339326

340-
return find_container_id(cgroup_fd, logger);
327+
return find_container_id(cgroup_fd);
341328
}
342329
#endif
343330
} // namespace
344331

345-
Optional<std::string> find_container_id(std::istream& source,
346-
const std::shared_ptr<tracing::Logger>& logger) {
332+
Optional<std::string> find_container_id(std::istream& source) {
347333
static const std::string uuid_regex_str =
348334
"[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}"
349335
"|(?:[0-9a-f]{8}(?:-[0-9a-f]{4}){4}$)";
@@ -355,28 +341,25 @@ Optional<std::string> find_container_id(std::istream& source,
355341

356342
std::string line;
357343
while (std::getline(source, line)) {
358-
logger->log_error("Reading line: " + line);
359344
// Example:
360345
// `0::/system.slice/docker-abcdef0123456789abcdef0123456789.scope`
361346
std::smatch match;
362347
if (std::regex_match(line, match, path_reg)) {
363348
assert(match.ready());
364349
assert(match.size() == 2);
365350

366-
logger->log_error("Found container ID: " + match.str(1));
367351
return match.str(1);
368352
}
369353
}
370354

371-
logger->log_error("No container ID found");
372355
return nullopt;
373356
}
374357

375-
Optional<ContainerID> get_id(const std::shared_ptr<tracing::Logger>& logger) {
358+
Optional<ContainerID> get_id() {
376359
#if defined(__linux__) || defined(__unix__)
377360
// Determine the container ID or inode
378361
ContainerID id;
379-
if (auto maybe_id = find_container_id_from_cgroup(logger)) {
362+
if (auto maybe_id = find_container_id_from_cgroup()) {
380363
id.value = *maybe_id;
381364
id.type = ContainerID::Type::container_id;
382365
} else if (!is_running_in_host_namespace()) {

src/datadog/platform_util.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
// This component provides platform-dependent miscellanea.
44

55
#include <datadog/expected.h>
6-
#include <datadog/logger.h>
76
#include <datadog/string_view.h>
87

9-
#include <memory>
108
#include <string>
119

1210
namespace datadog {
@@ -92,14 +90,13 @@ struct ContainerID final {
9290
/// @param source The input from which to read the container ID.
9391
/// @return An Optional containing the container ID if found, otherwise
9492
/// nothing.
95-
Optional<std::string> find_container_id(std::istream& source,
96-
const std::shared_ptr<tracing::Logger>& logger);
93+
Optional<std::string> find_container_id(std::istream& source);
9794

9895
/// Function to retrieve the container metadata.
9996
///
10097
/// @return A `ContainerID` object containing id of the container in
10198
/// which the current process is running.
102-
Optional<ContainerID> get_id(const std::shared_ptr<tracing::Logger>& logger);
99+
Optional<ContainerID> get_id();
103100

104101
} // namespace container
105102

test/test_platform_util.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "platform_util.h"
44
#include "test.h"
5-
#include "null_logger.h"
65

76
using namespace datadog::tracing;
87

@@ -59,7 +58,7 @@ PLATFORM_UTIL_TEST("find docker container ID") {
5958

6059
std::istringstream is(test_case.input);
6160

62-
auto maybe_container_id = container::find_container_id(is, std::make_shared<NullLogger>());
61+
auto maybe_container_id = container::find_container_id(is);
6362
if (test_case.expected_container_id.has_value()) {
6463
REQUIRE(maybe_container_id.has_value());
6564
CHECK(*maybe_container_id == *test_case.expected_container_id);
@@ -187,7 +186,7 @@ PLATFORM_UTIL_TEST("find multiline container IDs") {
187186

188187
std::istringstream is(test_case.input);
189188

190-
auto maybe_container_id = container::find_container_id(is, std::make_shared<NullLogger>());
189+
auto maybe_container_id = container::find_container_id(is);
191190
if (test_case.expected_container_id.has_value()) {
192191
REQUIRE(maybe_container_id.has_value());
193192
CHECK(*maybe_container_id == *test_case.expected_container_id);

0 commit comments

Comments
 (0)