bneradt commented on code in PR #14066:
URL: https://github.com/apache/trafficserver/pull/14066#discussion_r4593483452
##########
src/proxy/HostStatus.cc:
##########
@@ -40,7 +41,7 @@ const std::string STATUS_KEY{"status"};
struct HostCmdInfo {
TSHostStatus type{TSHostStatus::TS_HOST_STATUS_INIT};
- unsigned int reasonType{0};
+ unsigned int reasonType{Reason::MANUAL};
Review Comment:
This changes behavior for JSON-RPC `admin_host_set_status` callers that
leave out `reason`. Before, they got mask 0, so a down request set `DOWN` with
no reason bit, and any later up request cleared it. Now they get `manual`. That
matches what `jsonrpc-api.en.rst` already documents ("manual ... is the default
reason"), so I think it's the right call. It has nothing to do with logging,
though, so please mention it in the PR description and commit message so it
isn't missed when backporting.
##########
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.
Review Comment:
"They change no state" and "they were ignored" only hold for UP. For DOWN,
the `else` branch above sets `host_stat->status = status` no matter which bits
matched, so `TSHostStatusSet(host, DOWN, 0, 0x20)` marks the host down with
`reasons == 0`. The diags.log then has a Warning saying the request was
ignored, followed by a Note saying `has been marked down, ... all reasons:
none`.
Either reword the comment and Warning to say only the untracked bits were
dropped, or (probably better) stop a request that has no tracked bits from
changing `status`. Also, the Note already prints these bits as `unknown(0x..)`
through `getReasonName()`, so the Warning repeats information that is already
in the log. One of the two is probably enough.
##########
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];
Review Comment:
Nit: a fixed buffer plus `snprintf` is a lot of machinery for a constant
string or a number. Something like
```cpp
std::string const down_time_text = down_time == 0 ? "indefinitely" :
std::to_string(down_time) + " seconds";
```
reads more simply. The same goes for the `unknown(0x%x)` buffer in
`getReasonName()`, where `swoc::bwprint`/`swoc::LocalBufferWriter` would avoid
the C-style buffer.
##########
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(),
Review Comment:
The unit test covers `getReasonName()`, but nothing exercises the down /
still-down / marked-up branching here, which is the user-visible part of this
change. Could you add a urtest, modeled on
`tests/uranium_tests/cache/test_host_down_range_recursion.py` (it already
drives `Request.admin_host_set_status`)? It would mark a host down with
`active`, then `manual`, then up with `active`, and assert that diags.log has
`is still down, cleared reasons: active, remaining reasons: manual`. A final up
with `manual` should then give `has been marked up`. That would also catch the
expiry path in `getStatus()`, which calls `setHostStatus()` once per expired
reason.
--
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]