Skip to content

Commit c92d174

Browse files
authored
chore(deps): update spdlog to v1.16.0 (#402)
With move to debian:trixie, gcc -Werror complains about spdlog. Update spdlog. This also updates fmt which is now stricter. Add newly required formatters and fix logs.
1 parent 5f3caa6 commit c92d174

39 files changed

+406
-78
lines changed

build-tools/cpp_misc/spdlog

Submodule spdlog updated 169 files

channel/connection_caretaker.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ ConnectionCaretaker::ConnectionCaretaker(
5353
aws_metadata_->print_instance_metadata();
5454
aws_metadata_->print_interfaces();
5555
} else {
56-
LOG::warn("Unable to fetch AWS metadata: {}", aws_metadata.error());
56+
LOG::warn("Unable to fetch AWS metadata: {}", aws_metadata.error().what());
5757
}
5858

5959
LOG::trace_in(CloudPlatform::gcp, "--- resolving GCP metadata ---");
6060
if (auto gcp_metadata = GcpInstanceMetadata::fetch(metadata_timeout)) {
6161
gcp_metadata_.emplace(std::move(gcp_metadata.value()));
6262
gcp_metadata_->print();
6363
} else {
64-
LOG::warn("Unable to fetch GCP metadata: {}", gcp_metadata.error());
64+
LOG::warn("Unable to fetch GCP metadata: {}", gcp_metadata.error().what());
6565
}
6666

6767
int res = uv_timer_init(loop_, &heartbeat_timer_);

channel/file_channel.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ std::error_code FileChannel::send(const u8 *data, int size)
1919
std::string_view const buffer{reinterpret_cast<char const *>(data), static_cast<std::string_view::size_type>(size)};
2020

2121
if (auto const error = fd_.write_all(buffer)) {
22-
LOG::error("error while writing {} bytes into file channel: {}", size, error);
22+
const std::string error_message = error.message();
23+
LOG::error("error while writing {} bytes into file channel: {} ({})", size, error_message, error.value());
2324
return error;
2425
}
2526

@@ -35,7 +36,8 @@ std::error_code FileChannel::flush()
3536
{
3637
auto const error = fd_.flush_data();
3738
if (error) {
38-
LOG::error("error while flushing data for file channel: {}", error);
39+
const std::string error_message = error.message();
40+
LOG::error("error while flushing data for file channel: {} ({})", error_message, error.value());
3941
}
4042
return error;
4143
}

channel/reconnecting_channel.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <channel/reconnecting_channel.h>
66

77
#include <util/log.h>
8+
#include <util/log_formatters.h>
89

910
#include <stdexcept>
1011

channel/tcp_channel.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void TCPChannel::conn_connect_cb(uv_connect_t *req, int status)
117117
auto tcp = (TCPChannel *)req->handle->data;
118118

119119
if (status < 0) {
120-
LOG::trace_in(channel::Component::tcp, "TCPChannel::{}(): error {}", __func__, static_cast<std::errc>(-status));
120+
LOG::trace_in(channel::Component::tcp, "TCPChannel::{}(): error {}", __func__, uv_error_t{status});
121121
/* error occurred */
122122
tcp->connected_ = false;
123123
tcp->callbacks_->on_error(status);
@@ -182,7 +182,8 @@ void TCPChannel::connect(Callbacks &callbacks)
182182
int status = getaddrinfo(addr_.c_str(), port_.c_str(), &hints, &res);
183183

184184
if (status != 0) {
185-
LOG::critical("getaddrinfo failed: {} - calling abort", static_cast<std::errc>(status));
185+
const char *error_text = gai_strerror(status);
186+
LOG::critical("getaddrinfo failed: {} - calling abort", error_text ? error_text : "unknown error");
186187
// TODO: gracefully handle getaddrinfo errors
187188
std::abort();
188189
}

collector/cloud/enumerator.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,29 @@ void NetworkInterfacesEnumerator::handle_ec2_error(
132132
CollectorStatus status, Aws::Client::AWSError<Aws::EC2::EC2Errors> const &error)
133133
{
134134
if (error.GetErrorType() == Aws::EC2::EC2Errors::THROTTLING) {
135-
log_.error("{} - AWS API call throttled: {}", status, error.GetMessage());
135+
log_.error("{} - AWS API call throttled: {}", to_string(status), error.GetMessage());
136136
return;
137137
}
138138

139139
auto const http_status = static_cast<std::underlying_type_t<Aws::Http::HttpResponseCode>>(error.GetResponseCode());
140140

141-
LOG::trace("reporting cloud collector as unhealthy (status={} detail={})", status, http_status);
141+
LOG::trace("reporting cloud collector as unhealthy (status={} detail={})", to_string(status), http_status);
142142
writer_.collector_health(integer_value(status), http_status);
143143

144144
if (http_status >= 400 && http_status < 500) {
145145
log_.error(
146146
"{} - API call failed with http status {}. Double check that AWS credentials are"
147147
" properly set up for this pod. Check setup instructions for more information."
148148
" Error message from AWS: {}",
149-
status,
149+
to_string(status),
150150
http_status,
151151
error.GetMessage());
152152
} else {
153153
log_.error(
154-
"{} - API call failed with http status {}. Error message from AWS: {}", status, http_status, error.GetMessage());
154+
"{} - API call failed with http status {}. Error message from AWS: {}",
155+
to_string(status),
156+
http_status,
157+
error.GetMessage());
155158
}
156159
}
157160

collector/cloud/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
8080

8181
// resolve hostname
8282
std::string const hostname = get_host_name(MAX_HOSTNAME_LENGTH).recover([](auto &error) {
83-
LOG::error("Unable to retrieve host information from uname: {}", error);
83+
LOG::error("Unable to retrieve host information from uname: {}", log_waive(error.message()));
8484
return "(unknown)";
8585
});
8686

collector/k8s/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
8585

8686
// resolve hostname
8787
std::string const hostname = get_host_name(MAX_HOSTNAME_LENGTH).recover([](auto &error) {
88-
LOG::error("Unable to retrieve host information from uname: {}", error);
88+
LOG::error("Unable to retrieve host information from uname: {}", log_waive(error.message()));
8989
return "(unknown)";
9090
});
9191
LOG::info("Kubernetes Collector version {} ({}) started on host {}", versions::release, release_mode_string, hostname);

collector/kernel/buffered_poller.cc

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
#include <spdlog/fmt/bin_to_hex.h>
2424

2525
#include <chrono>
26+
#include <cstring>
2627
#include <iostream>
2728
#include <stdexcept>
29+
#include <string_view>
2830

2931
constexpr u16 DNS_MAX_PACKET_LEN = 512;
3032

@@ -34,6 +36,16 @@ static BufferedPoller *singleton_ = nullptr;
3436

3537
static constexpr u64 DNS_TIMEOUT_TIME_NS = 10'000'000'000ull;
3638

39+
namespace {
40+
41+
std::string_view comm_to_string(std::uint8_t const (&comm)[16])
42+
{
43+
auto const length = strnlen(reinterpret_cast<char const *>(comm), sizeof(comm));
44+
return std::string_view(reinterpret_cast<char const *>(comm), length);
45+
}
46+
47+
} // namespace
48+
3749
BufferedPoller::BufferedPoller(
3850
uv_loop_t &loop,
3951
PerfContainer &container,
@@ -1034,7 +1046,16 @@ void BufferedPoller::handle_pid_info(message_metadata const &metadata, jb_agent_
10341046
{
10351047
pid_count_++;
10361048

1037-
LOG::debug_in(AgentLogKind::PID, "{}: msg={} pid_count_={}", __func__, msg, pid_count_);
1049+
const std::string_view comm = comm_to_string(msg.comm);
1050+
LOG::debug_in(
1051+
AgentLogKind::PID,
1052+
"{}: pid={} parent={} cgroup=0x{:x} comm='{}' pid_count_={}",
1053+
__func__,
1054+
msg.pid,
1055+
msg.parent_pid,
1056+
msg.cgroup,
1057+
comm,
1058+
pid_count_);
10381059

10391060
cgroup_handler_.handle_pid_info(msg.pid, msg.cgroup, msg.comm);
10401061
process_handler_.on_new_process(std::chrono::nanoseconds{metadata.timestamp}, msg);
@@ -1057,23 +1078,25 @@ void BufferedPoller::handle_pid_close(message_metadata const &metadata, jb_agent
10571078
{
10581079
pid_count_--;
10591080

1060-
LOG::debug_in(AgentLogKind::PID, "{}: msg={} pid_count_={}", __func__, msg, pid_count_);
1081+
const std::string_view comm = comm_to_string(msg.comm);
1082+
LOG::debug_in(AgentLogKind::PID, "{}: pid={} comm='{}' pid_count_={}", __func__, msg.pid, comm, pid_count_);
10611083

10621084
process_handler_.on_process_end(std::chrono::nanoseconds{metadata.timestamp}, msg);
10631085
writer_.pid_close_info_tstamp(metadata.timestamp, msg.pid, msg.comm);
10641086
}
10651087

10661088
void BufferedPoller::handle_pid_set_comm(message_metadata const &metadata, jb_agent_internal__pid_set_comm &msg)
10671089
{
1068-
LOG::debug_in(AgentLogKind::PID, "{}: msg={}", __func__, msg);
1090+
const std::string_view comm = comm_to_string(msg.comm);
1091+
LOG::debug_in(AgentLogKind::PID, "{}: pid={} comm='{}'", __func__, msg.pid, comm);
10691092

10701093
process_handler_.set_process_command(std::chrono::nanoseconds{metadata.timestamp}, msg);
10711094
writer_.pid_set_comm_tstamp(metadata.timestamp, msg.pid, msg.comm);
10721095
}
10731096

10741097
void BufferedPoller::handle_pid_exit(message_metadata const &metadata, jb_agent_internal__pid_exit &msg)
10751098
{
1076-
LOG::debug_in(AgentLogKind::PID, "{}: msg={}", __func__, msg);
1099+
LOG::debug_in(AgentLogKind::PID, "{}: tgid={} pid={} exit_code={}", __func__, msg.tgid, msg.pid, msg.exit_code);
10771100

10781101
process_handler_.pid_exit(std::chrono::nanoseconds{metadata.timestamp}, msg);
10791102
}

collector/kernel/cgroup_handler.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <util/file_ops.h>
1212
#include <util/k8s_metadata.h>
1313
#include <util/log.h>
14+
#include <util/log_formatters.h>
1415
#include <util/nomad_metadata.h>
1516

1617
#include <generated/ebpf_net/agent_internal/wire_message.h>
@@ -299,7 +300,8 @@ void CgroupHandler::fetch_done_cb(CurlEngineStatus status, long responseCode, st
299300
queries_.erase(pos);
300301

301302
if (!success) {
302-
log_.error("docker fetch failed [{}:{}]: {}", status, responseCode, curlError);
303+
const std::string_view status_text = to_string(status);
304+
log_.error("docker fetch failed [{}:{}]: {}", status_text, responseCode, curlError);
303305
return;
304306
}
305307

@@ -433,7 +435,7 @@ void CgroupHandler::handle_docker_response(u64 cgroup, std::string const &respon
433435
}
434436

435437
if (docker_host_config.has_value()) {
436-
LOG::debug_in(AgentLogKind::DOCKER, "container resource limits: {}", *docker_host_config);
438+
LOG::debug_in(AgentLogKind::DOCKER, "container resource limits: {}", fmt::streamed(*docker_host_config));
437439

438440
auto const cpu_period = docker_host_config->cpu_period();
439441
auto const cpu_quota = docker_host_config->cpu_quota();

0 commit comments

Comments
 (0)