Skip to content

Commit

Permalink
nodetool: tasks: print empty string for start_time/end_time if unspec…
Browse files Browse the repository at this point in the history
…ified

If start_time/end_time is unspecified for a task, task_manager API
returns epoch. Nodetool prints the value in task status.

Fix nodetool tasks commands to print empty string for start_time/end_time
if it isn't specified.

Modify nodetool tasks status docs to show empty end_time.

Fixes: scylladb#22373.

Closes scylladb#22370
  • Loading branch information
Deexie authored and denesb committed Jan 30, 2025
1 parent 7db1442 commit 477ad98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/operating-scylla/nodetool-commands/tasks/status.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Example output
type: repair
kind: node
scope: keyspace
state: done
state: running
is_abortable: true
start_time: 2024-07-29T15:48:55Z
end_time: 2024-07-29T15:48:55Z
end_time:
error:
parent_id: none
sequence_number: 5
Expand Down
15 changes: 12 additions & 3 deletions tools/scylla-nodetool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2793,11 +2793,20 @@ void table_stats_operation(scylla_rest_client& client, const bpo::variables_map&
}
}

std::string get_time(std::string_view time) {
static constexpr const char* epoch = "1970-01-01T00:00:00Z";
return time == epoch ? "" : std::string{time};
}

void tasks_print_status(const rjson::value& res) {
auto status = res.GetObject();
for (const auto& x: status) {
if (x.value.IsString()) {
fmt::print("{}: {}\n", x.name.GetString(), x.value.GetString());
if (strcmp(x.name.GetString(), "start_time") == 0 || strcmp(x.name.GetString(), "end_time") == 0) {
fmt::print("{}: {}\n", x.name.GetString(), get_time(x.value.GetString()));
} else {
fmt::print("{}: {}\n", x.name.GetString(), x.value.GetString());
}
} else if (x.value.IsArray()) {
fmt::print("{}: [", x.name.GetString());
sstring delim = "";
Expand Down Expand Up @@ -2845,8 +2854,8 @@ void tasks_add_tree_to_statuses_lists(Tabulate& table, const rjson::value& res)
rjson::to_string_view(status["scope"]),
rjson::to_string_view(status["state"]),
status["is_abortable"].GetBool(),
rjson::to_string_view(status["start_time"]),
rjson::to_string_view(status["end_time"]),
get_time(rjson::to_string_view(status["start_time"])),
get_time(rjson::to_string_view(status["end_time"])),
rjson::to_string_view(status["error"]),
rjson::to_string_view(status["parent_id"]),
status["sequence_number"].GetUint64(),
Expand Down

0 comments on commit 477ad98

Please sign in to comment.