Copilot commented on code in PR #14066:
URL: https://github.com/apache/trafficserver/pull/14066#discussion_r4566857980
##########
src/proxy/HostStatus.cc:
##########
@@ -281,14 +328,35 @@ HostStatus::setHostStatus(const std::string_view name,
TSHostStatus status, cons
host_stat->status = status;
Dbg(dbg_ctl_host_statuses, "reasons: %d, status: %s",
host_stat->reasons, HostStatusNames[host_stat->status]);
}
+ effective_status = host_stat->status;
+ remaining_reasons = host_stat->reasons;
+ }
+
+ // Requested reasons are logged apart from the host's full set because
down_time applies only to the
+ // requested ones, and an UP request clears only those, so the host recovers
only when none remain.
+ auto reason_name = Reason::getReasonName(reason);
+ auto remaining_name = Reason::getReasonName(remaining_reasons);
+
+ // Bits outside the tracked set match no branch above, so they change no
state.
+ if (const unsigned int untracked = reason & ~Reason::ALL; untracked != 0) {
+ Warning("Host %.*s status request carries untracked reason bits 0x%x; they
were ignored.", int(name.size()), name.data(),
+ untracked);
}
- // log it.
if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
- Note("Host %.*s has been marked down, down_time: %d - %s.",
int(name.size()), name.data(), down_time,
- down_time == 0 ? "indefinitely." : "seconds.");
+ char down_time_text[32];
+ if (down_time == 0) {
+ std::snprintf(down_time_text, sizeof(down_time_text), "indefinitely");
+ } else {
+ std::snprintf(down_time_text, sizeof(down_time_text), "%u seconds",
down_time);
+ }
+ Note("Host %.*s has been marked down, down_time: %s, reasons: %s, all
reasons: %s.", int(name.size()), name.data(),
+ down_time_text, reason_name.c_str(), remaining_name.c_str());
+ } else if (effective_status == TSHostStatus::TS_HOST_STATUS_UP) {
+ Note("Host %.*s has been marked up, cleared reasons: %s.",
int(name.size()), name.data(), reason_name.c_str());
} else {
- Note("Host %.*s has been marked up.", int(name.size()), name.data());
+ Note("Host %.*s is still down, cleared reasons: %s, remaining reasons:
%s.", int(name.size()), name.data(), reason_name.c_str(),
+ remaining_name.c_str());
Review Comment:
The terminology in the log line is ambiguous: `reasons` vs `all reasons`
isn’t immediately clear as “requested/cleared reasons” vs “effective/current
reasons”. Consider renaming the fields in the log message to be explicit (e.g.,
`requested reasons` and `current reasons`, or `cleared reasons` and `remaining
reasons`) to reduce operator confusion.
##########
src/proxy/HostStatus.cc:
##########
@@ -281,14 +328,35 @@ HostStatus::setHostStatus(const std::string_view name,
TSHostStatus status, cons
host_stat->status = status;
Dbg(dbg_ctl_host_statuses, "reasons: %d, status: %s",
host_stat->reasons, HostStatusNames[host_stat->status]);
}
+ effective_status = host_stat->status;
+ remaining_reasons = host_stat->reasons;
+ }
+
+ // Requested reasons are logged apart from the host's full set because
down_time applies only to the
+ // requested ones, and an UP request clears only those, so the host recovers
only when none remain.
+ auto reason_name = Reason::getReasonName(reason);
+ auto remaining_name = Reason::getReasonName(remaining_reasons);
+
+ // Bits outside the tracked set match no branch above, so they change no
state.
+ if (const unsigned int untracked = reason & ~Reason::ALL; untracked != 0) {
+ Warning("Host %.*s status request carries untracked reason bits 0x%x; they
were ignored.", int(name.size()), name.data(),
+ untracked);
}
- // log it.
if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
- Note("Host %.*s has been marked down, down_time: %d - %s.",
int(name.size()), name.data(), down_time,
- down_time == 0 ? "indefinitely." : "seconds.");
+ char down_time_text[32];
+ if (down_time == 0) {
+ std::snprintf(down_time_text, sizeof(down_time_text), "indefinitely");
+ } else {
+ std::snprintf(down_time_text, sizeof(down_time_text), "%u seconds",
down_time);
Review Comment:
`std::snprintf` uses `%u` but `down_time` is passed as-is (and appears to be
an `int` in this function). That’s a varargs type mismatch and can cause
undefined behavior. Use `%d` for an `int`, or cast `down_time` to an unsigned
type and keep `%u` (ideally aligning the format string with the variable’s
declared type).
##########
src/proxy/HostStatus.cc:
##########
@@ -281,14 +328,35 @@ HostStatus::setHostStatus(const std::string_view name,
TSHostStatus status, cons
host_stat->status = status;
Dbg(dbg_ctl_host_statuses, "reasons: %d, status: %s",
host_stat->reasons, HostStatusNames[host_stat->status]);
}
+ effective_status = host_stat->status;
+ remaining_reasons = host_stat->reasons;
+ }
+
+ // Requested reasons are logged apart from the host's full set because
down_time applies only to the
+ // requested ones, and an UP request clears only those, so the host recovers
only when none remain.
+ auto reason_name = Reason::getReasonName(reason);
+ auto remaining_name = Reason::getReasonName(remaining_reasons);
+
+ // Bits outside the tracked set match no branch above, so they change no
state.
+ if (const unsigned int untracked = reason & ~Reason::ALL; untracked != 0) {
+ Warning("Host %.*s status request carries untracked reason bits 0x%x; they
were ignored.", int(name.size()), name.data(),
+ untracked);
}
- // log it.
if (status == TSHostStatus::TS_HOST_STATUS_DOWN) {
- Note("Host %.*s has been marked down, down_time: %d - %s.",
int(name.size()), name.data(), down_time,
- down_time == 0 ? "indefinitely." : "seconds.");
+ char down_time_text[32];
+ if (down_time == 0) {
+ std::snprintf(down_time_text, sizeof(down_time_text), "indefinitely");
+ } else {
+ std::snprintf(down_time_text, sizeof(down_time_text), "%u seconds",
down_time);
+ }
+ Note("Host %.*s has been marked down, down_time: %s, reasons: %s, all
reasons: %s.", int(name.size()), name.data(),
+ down_time_text, reason_name.c_str(), remaining_name.c_str());
+ } else if (effective_status == TSHostStatus::TS_HOST_STATUS_UP) {
+ Note("Host %.*s has been marked up, cleared reasons: %s.",
int(name.size()), name.data(), reason_name.c_str());
} else {
- Note("Host %.*s has been marked up.", int(name.size()), name.data());
+ Note("Host %.*s is still down, cleared reasons: %s, remaining reasons:
%s.", int(name.size()), name.data(), reason_name.c_str(),
+ remaining_name.c_str());
Review Comment:
`remaining_name` is computed unconditionally, but it’s only used in the DOWN
and “still down” branches (not when the host becomes UP). Consider computing
`remaining_name` lazily only in the branches that actually log it to avoid
unnecessary string allocations on the UP path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]