Commit Graph

124 Commits

Author SHA1 Message Date
Botond Dénes
a77796f484 test/nodetool: make test pass with cassandra nodetool
After the recent fixes 4 tests started failing with the java nodetool
implementation. We are about to ditch the java implementation, but until
we actually do, it is valuable to keep the tests passing with both the
native and java implementation.
So in this patch, these tests are fixed to pass with the java
implementation too.
There is one test, test_help.py, which fails only if run together with
all the tests. I couldn't confirm this 100%, but it seems like this is
due to JMX sending a rouge request on some timer, which happens to hit
this test. I don't think this is worth trying to fix.
2024-05-13 07:09:20 -04:00
Botond Dénes
bec4c17db4 tools/scylla-nodetool: status: fix token count for tablets
Currently, the token count column is always based on the vnodes, which
makes no sense for tablet keyspaces. If a tablet keyspace is provided as
the keyspace argument, don't print the vnode token count. If the user
provided a table argument as well, print the tablet count, otherwise
print "?".
2024-05-13 07:09:20 -04:00
Botond Dénes
e82455beab tools/scylla-nodetool: add tablet support to ring command
Add a table parameter. Pass both keyspace and table (when provided) to
the /storage_service/tokens_endpoint API endpoint, so that the returned
(and printed) token ring is that of the table's tablets, not the vnode
ring.
Also pass the table param to the ownership API, which will complain if
this param is missing for a tablet keyspace.
2024-05-13 07:09:20 -04:00
Kefu Chai
fd14b6f26b test/nodetool: do not accept 1 return code when passing --help to nodetool
in 906700d5, we accepted 0 as well as the return code of
"nodetool <command> --help", because we needed to be prepared for
the newer seastar submodule while be compatible with the older
seastar versions. now that in 305f1bd3, we bumped up the seastar
module, and this commit picked up the change to return 0 when
handling "--help" command line option in seastar, we are able to
drop the workaround.

so, in this change, we only use "0" as the expected return code.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#18627
2024-05-12 14:30:31 +03:00
Kefu Chai
906700d523 test/nodetool: accept -1 returncode also when --help is invoked
in newer seastar, 0 is returned as the returncode of the application
when handling `--help`. to prepare for this behavior, let's
accept it before updating the seastar submodule.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#18574
2024-05-09 08:26:44 +03:00
Kefu Chai
bd0d246b57 tools/scylla-nodetool: implement the resetlocalschema command
Fixes #18468
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#18470
2024-05-01 08:49:11 +03:00
Nadav Har'El
566223c34a Merge ' tools/scylla-nodetool: repair: abort on first failed repair' from Botond Dénes
When repairing multiple keyspaces, bail out on the first failed keyspace repair, instead of continuing and reporting all failures at the end. This is what Origin does as well.

To be able to test this, a bit of refactoring was needed, to be able to assert that `scylla-nodetool` doesn't make repair requests, beyond the expected ones.

Refs: https://github.com/scylladb/scylla-cluster-tests/issues/7226

Closes scylladb/scylladb#17678

* github.com:scylladb/scylladb:
  tools/scylla-nodetool: repair: abort on first failed repair
  test/nodetool: nodetool(): add check_return_code param
  test/nodetool: nodetool(): return res object instead of just stdout
  test/nodetool: count unexpected requests
2024-03-28 14:02:29 +02:00
Botond Dénes
81bbfae77a tools/scylla-nodetool: implement the checkAndRepairCdcStreams command
Closes scylladb/scylladb#18076
2024-03-28 13:54:37 +02:00
Kefu Chai
99e743de9d test: nodetool: match with vector printed by {fmt}
our homebrew formatter for std::vector<string> formats like

```
{hello, world}
```

while {fmt}'s formatter for sequence-like container formats like

```
["hello", "world"]
```

since we are moving to {fmt} formatters. and in this context,
quoting the verbatim text makes more sense to user. let's
support the format used by {fmt} as well.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#18057
2024-03-28 09:35:37 +02:00
Botond Dénes
f70f04c240 tools/scylla-nodetool: repair: abort on first failed repair
When repairing multiple keyspaces, bail out on the first failed keyspace
repair, instead of continuing and reporting all failures at the end.
This is what Origin does as well.
2024-03-27 05:46:18 -04:00
Botond Dénes
764e9a344d test/nodetool: nodetool(): add check_return_code param
When set to false, the returncode is not checked, this is left to the
caller. This in turn allows for checking the expected and unexpected
requests which is not checked when the nodetool process fails.
This is used by utils._do_check_nodetool_fails_with(), so that expected
and unexpected requests are checked even for failed invocations.

Some test need adjustment to the stricter checks.
2024-03-27 04:18:19 -04:00
Botond Dénes
8f3b1db37f test/nodetool: nodetool(): return res object instead of just stdout
So callers have access to stderr, return code and more.
This causes some churn in the test, but the changes are mechanical.
2024-03-27 04:18:19 -04:00
Botond Dénes
4d98b7d532 test/nodetool: count unexpected requests
We currently check at the end of each test, that all expected requests
set by the test were consumed. This patch adds a mechanism to count
unexpected requests -- requests which didn't match any of the expected
ones set by the test. This can be used to asser that nodetool didn't
make any request to the server, beyond what the test expected it to do.
Before this patch, requests like this would only be noticed by the test,
if the response of 404/500 caused nodetool to fail, which is not always
the case.
2024-03-27 02:39:28 -04:00
Botond Dénes
1ea7b408db tools/scylla-nodetool: implement the sstableinfo command 2024-03-25 11:29:30 -04:00
Botond Dénes
50da93b9c8 tools/scylla-nodetool: implement the getsstables command 2024-03-25 11:29:30 -04:00
Botond Dénes
4ff88b848c test/nodetool: rest_api_mock.py: add expected_requests context manager
So tests and fixtures can use `with expected_requests():` and have
cleanup be taken care for them. I just discovered that some tests do not
clean up after themselves and when running all tests in a certain order,
this causes unrelated tests to fail.
Fix by using the context everywhere, getting guaranteed cleanup after
each test.
2024-03-25 11:29:30 -04:00
Patryk Wrobel
28ed20d65e scylla-nodetool: adjust effective ownership handling
When a keyspace uses tablets, then effective ownership
can be obtained per table. If the user passes only a
keyspace, then /storage_service/ownership/{keyspace}
returns an error.

This change:
 - adds an additional positional parameter to 'status'
   command that allows a user to query status for table
   in a keyspace
 - makes usage of /storage_service/ownership/{keyspace}
   optional to avoid errors when user tries to obtain
   effective ownership of a keyspace that uses tablets
 - implements new frontend tests in 'test_status.py'
   that verify the new logic

Refs: scylladb#17405
Signed-off-by: Patryk Wrobel <patryk.wrobel@scylladb.com>

Closes scylladb/scylladb#17827
2024-03-22 09:51:57 +02:00
Botond Dénes
c2425ca135 tools/scylla-nodetool: add --rest-api-port option
This option is an alternative to --port|-p and takes precedence over it.
This is meant to aid the switch from the legacy nodetool to the native
one. Users of the legacy nodetool pass the port of JMX to --port. We
need a way to provide both the JMX port (via --port) and also the REST
API port, which only the native nodetool will interpret. So we add this
new --rest-api-port, which when provided, overwrites the --port|-p
option. To ensure the legacy nodeotol doesn't try to interpret this,
this option can also be provided as -Dcom.scylladb.apiPort (which is
substituted to --rest-api-port behind the scenes).
2024-03-20 02:11:47 -04:00
Botond Dénes
a85ec6fc60 tools/scylla-nodetool: ignore JVM args
Legacy scripts and tests for nodetool, might pass JVM args like
-Dcom.sun.jndi.rmiURLParsing=legacy. Ignore these, by dropping anything
that starts with -D from the command line args.
2024-03-20 02:11:47 -04:00
Botond Dénes
12516b0861 tools/utils: make finding the operation command line option more flexible
Currently all scylla-tools assume that the operation/command is in
argv[1]. This is not very flexible, because most programs allow global
options (that are not dependent on the current operation/command) to be
passed before the operation name on the command line. Notably C*'s
nodetool is one such program and indeed scripts and tests using nodetool
do utilize this.
This patch makes this more flexible. Instead of looking at argv[1], do
an initial option parsing with boost::program_options to locate the
operation parameter. This initial parser knows about the global options,
and the operation positional argument. It allows for unrecognized
positional and non-positional arguments, but only after the command.
With this, any combination of global options + operation is allowed, in
any order.
2024-03-20 02:11:47 -04:00
Botond Dénes
a4e8bea679 tools/scylla-nodetool: status: handle missing host_id
Newly joining nodes may not have a host id yet. Handle this and print a
"?" for these nodes, instead of the host-id.
Extend the existing test for joining node case (also rename it and add
comment).

Closes scylladb/scylladb#17853
2024-03-18 12:26:59 +02:00
Botond Dénes
03c47bc30b tools/scylla-nodetool: status: handle nodes without load
Some nodes may not have a load yet. Handle this. Also add a test
covering this case.

Closes scylladb/scylladb#17823
2024-03-16 17:38:53 +02:00
Botond Dénes
ad9bad4700 tools/scylla-nodetool: {proxy,table}histograms: handle empty histograms
Empty histograms are missing some of the members that non-empty
histograms have. The code handling these histograms assumed all required
members are always present and thus error out when receiving an empty
histogram.
Add tests for empty histograms and fix the code handling them to check
for the potentially missing members, instead of making assumptions.

Closes scylladb/scylladb#17816
2024-03-15 15:59:31 +03:00
Avi Kivity
0f188f2d9f Merge 'tools/scylla-nodetool: implement the status command' from Botond Dénes
The status command has an extensive amount of requests to the server. To be able to handle this more easily, the rest api mock server is refactored extensively to be more flexible, accepting expected requests out-of-order. While at it, the rest api mock server also moves away from a deprecated `aiohttp` feature: providing custom router argument to the `aiohttp` app. This forces us to pre-register all API endpoints that any test currently uses, although due to some templateing support, this is not as bad as it sounds. Still, this is an annoyance, but this point we have implemented almost all commands, so this won't be much a of a problem going forward.

Refs: https://github.com/scylladb/scylladb/issues/15588

Closes scylladb/scylladb#17547

* github.com:scylladb/scylladb:
  tools/scylla-nodetool: implement the status command
  test/nodetool: rest_api_mock.py: match requests out-of-order
  test/nodetool: rest_api_mock.py: remove trailing / from request paths
  test/nodetool: rest_api_mock.py: use static routes
  test/nodetool: check only non-exhausted requests
  tools/scylla-nodetool: repair: set the jobThreads request parameter
2024-03-14 18:42:54 +02:00
Botond Dénes
d6103dc1b6 tools/scylla-nodetool: snapshot: handle ks.tbl positional args correctly
Nodetool currently assumes that positional arguments are only keyspaces.
ks.tbl pairs are only provided when --kt-list or friends are used. This
is not the case however. So check positional args too, and if they look
like ks.tbl, handle them accordingly.

While at it, also make sure that alternator keyspace and tables names
are handled correctly.

Closes scylladb/scylladb#17480
2024-03-14 13:42:23 +02:00
Botond Dénes
20d5c536b5 tools/scylla-nodetool: implement the status command
Contrary to Origin, the single-token case is not discriminated in the
native implementation, for two reasons:
* ScyllaDB doesn't ever run with a single token, it is even moving away
  from vnodes.
* Origin implemented the logic to detect single-token with a mistake: it
  compares the number of tokens to the number of DCs, not the number of
  nodes.

Another difference is that the native implementation doesn't request
ownership information when a keyspace argument was not provided -- it is
not printed anyway.
2024-03-14 03:27:04 -04:00
Botond Dénes
2d4f4cfad4 test/nodetool: rest_api_mock.py: match requests out-of-order
In the previous patch, we made matching requests to different endpoints
be matched out-of-order. In this patch we go one step further and make
matching requests to the same endpoint match out-of-order too.
With this, tests can register the expected requests in any order, not in
the same order as the nodetool-under-test is expected to send them. This
makes testing more flexible. Also, how requests are ordered is not
interesting from the correctness' POV anyway.
2024-03-14 03:27:04 -04:00
Botond Dénes
09a27f49ea test/nodetool: rest_api_mock.py: remove trailing / from request paths
The legacy nodetool likes to append an "/" to the requests paths every
now and then, but not consistently. Unfortunately, request path matching
in the mock rest server and in aiohttp is quite sensitive to this
currently. Reduce friction by removing trailing "/" from paths in the
mock api, allowing paths to match each other even if one has a trailing
"/" but the other doesn't.
Unfortunately there is nothing we can do about the aiohttp part, so some
API endpoints have to be registered with a trailing "/".
2024-03-14 03:27:04 -04:00
Botond Dénes
5659f23b2a test/nodetool: rest_api_mock.py: use static routes
The mock server currently provides its own router to the aiohttp.web
app. The ability to provide custom routers  however is deprecated and
can be removed at any point. So refactor the mock server to use the
built-in router. This requires some changes, because the built-in router
does not allow adding/removing routes once the server starts. However
the mock server only learns of the used routes when the tests run.
This unfortunately means that we have to statically register all
possible routes the tests will use. Fortunately, aiohttp has variable
route support (templated routes) and with this, we can get away with
just 9 statically registered routes, which is not too bad.

A (desired) side-effect of this refactoring is that now requests to
different routes do not have to arrive in order. This constraint of the
previous implementation proved to be not useful, and even made writing
certain tests awkward.
2024-03-14 03:27:04 -04:00
Botond Dénes
061bd89957 test/nodetool: check only non-exhausted requests
Refactor how the tests check for expected requests which were never
invoked. At the end of every test, the nodetool fixture requests all
unconsumed expected requests from the rest_api_mock.py and checks that
there is none. This mechanism has some interaction with requests which
have a "multiple" set: rest_api_mock.py allows registering requests with
different "multiple" requirements -- how many times a request is
expected to be invoked:
* ANY: [0, +inf)
* ONE: 1
* MULTIPLE: [1, +inf)

Requests are stored in a stack. When a request arrives, we pop off
requests from the top until we find a perfect match. We pop off
requests, iff: multiple == ANY || multiple == MULTIPLE and was hit at
least once.
This works as long as we don't have an multiple=ANY request at the
bottom of the stack which is never invoked. Or a multiple=MULTIPLE one.
This will get worse once we refactor requests to be not stored in a
stack.

So in this patch, we filter requests when collecting unexhausted ones,
dropping those which would be qualified to be popped from the stack.
2024-03-14 03:27:04 -04:00
Botond Dénes
be5a18c07d tools/scylla-nodetool: repair: set the jobThreads request parameter
Although ScyllaDB ignores this request parameter, the Java nodetools
sets it, so it is better to have the native one do the same for
symmetry. It makes testing easier.
Discovered with the more strict request matching introduced in the next
patches.
2024-03-14 03:26:13 -04:00
Botond Dénes
a329cc34b7 tools/scylla-nodetool: implement the proxyhistograms command 2024-03-13 02:06:30 -04:00
Botond Dénes
a52eddc9c1 tools/scylla-nodetool: implement the tableshistograms command 2024-03-13 02:06:30 -04:00
Botond Dénes
006bc84761 tools/scylla-nodetool: implement the netstats command 2024-03-13 02:06:10 -04:00
Botond Dénes
630be97d2f Merge 'tools/scylla-nodetool: print hostname if --resolve-ip is passed to "ring"' from Kefu Chai
before this change, "ring" subcommand has two issues:

1. `--resolve-ip` option accepts a boolean argument, but this option
   should be a switch, which does not accept any argument at all
2. it always prints the endpoint no matter if `--resolve-ip` is
   specified or not. but it should print the resolved name, instead
   of an IP address if `--resolve-ip` is specified.

in this change, both issues are addressed. and the test is updated
accordingly to exercise the case where `--resolve-ip` is used.

Closes scylladb/scylladb#17553

* github.com:scylladb/scylladb:
  tools/scylla-nodetool: print hostname if --resolve-ip is passed to "ring"
  test/nodetool: calc max_width from all_hosts
  test/nodetool: keep tokens as Host's member
  test/nodetool: remove unused import
2024-03-08 15:15:19 +02:00
Nadav Har'El
ea53db379f Merge 'tools/scylla-nodetool: listsnapshot: make it compatible with origin' from Botond Dénes
The following incompatibilities were identified by `listsnapshots_test.py` in dtests:
* Command doesn't bail out when there are no snapshots, instead it prints meaningless empty report
* Formatting is incompatible

Both are fixed in this mini-series.

Closes scylladb/scylladb#17541

* github.com:scylladb/scylladb:
  tools/scylla-nodetool: listsnapshots: make the formatting compatible with origin's
  tools/scylla-nodetool: listsnapshots: bail out if there are no snapshots
2024-03-08 10:08:09 +01:00
Kefu Chai
de276901f2 tools/scylla-nodetool: print hostname if --resolve-ip is passed to "ring"
before this change, "ring" subcommand has two issues:

1. `--resolve-ip` option accepts a boolean argument, but this option
   should be a switch, which does not accept any argument at all
2. it always prints the endpoint no matter if `--resolve-ip` is
   specified or not. but it should print the resolved name, instead
   of an IP address if `--resolve-ip` is specified.

in this change, both issues are addressed. and the test is updated
accordingly to exercise the case where `--resolve-ip` is used.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-03-07 22:29:31 +08:00
Kefu Chai
d927ee8d8f test/nodetool: calc max_width from all_hosts
for better readability. as `token_to_endpoint` is but a derived
variable from `all_hosts`.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-03-07 22:28:54 +08:00
Kefu Chai
4a748c7fb0 test/nodetool: keep tokens as Host's member
to be more consistent with the test_status.py.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-03-07 22:28:54 +08:00
Kefu Chai
aefc385786 test/nodetool: remove unused import
and add two empty lines in between global functions

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-03-07 22:28:54 +08:00
Botond Dénes
09068d20ea tools/scylla-nodetool: scrub: make keyspace parameter optional
When no keyspace is provided, request all keyspaces from the server,
then scrub all of them. This is what the legacy nodetool does, for some
reason this was missed when re-implementing scrub.

Closes scylladb/scylladb#17495
2024-03-07 11:15:46 +02:00
Botond Dénes
5dfaa69bde tools/scylla-nodetool: listsnapshots: make the formatting compatible with origin's
The author (me) tried to be clever and fix the formatting, but then he
realized this just means a lot of unnecessary fighting with tests. So
this patch makes the formatting compatible with that of the legacy
nodetool:
* Use compatible rounding and precision formatting
* Use incorrect unit (KB instead of KiB)
* Align numbers to the left
* Add trailing white-space to "Snapshot Details: "
2024-03-07 03:54:54 -05:00
Botond Dénes
80483ba732 tools/scylla-nodetool: listsnapshots: bail out if there are no snapshots
Print a message and exit, don't continue to output the snapshot table.
This is what the legacy nodetool does too.
2024-03-07 03:54:54 -05:00
Botond Dénes
ac15e4c109 tools/scylla-nodetool: repair: accept and ignore -full/--full and -j/--job-threads
These two parameters are not used by the native nodetool, because
ScyllaDB itself doesn't support them. These should be just ignored and
indeed there was a unit test checking that this is the case. However,
due to a mistake in the unit test, this was not actually tested and
nodetool complained when seeing these params.
This patch fixes both the test and the native nodetool.

Closes scylladb/scylladb#17477
2024-03-07 11:53:50 +03:00
Botond Dénes
8dd6fe75e7 Merge 'tools/scylla-nodetool: implement info ' from Kefu Chai
Refs #15588

Closes scylladb/scylladb#17498

* github.com:scylladb/scylladb:
  tools/scylla-nodetool: implement info
  test/nodetool: move format_size into utils.py
2024-03-07 07:14:51 +02:00
Botond Dénes
58265a7dc1 tools/utils: fix use-after-free when printing error message for unknown operation
When a tool application is invoked with an unknown operation, an error
message is printed, which includes all the known operations, with all
their aliases. This is collected in `std::vector<std::string_view>`. The
problem is that the vector containing alias names, is returned as a
value, so the code ends up creating views to temporaries.
Fix this by returning alias vector with const&.

Fixes: #17584

Closes scylladb/scylladb#17586
2024-03-06 10:42:02 +02:00
Kefu Chai
e248ab48db tools/scylla-nodetool: correct tablestats filtering
before this change, we failed to apply the filtering of tablestats
command in the right way:

1. `table_filter` failed to check if delimiter is npos before
   extract the cf component from the specified table name.
2. the stats should not included the keyspace which are not
   included by the filter.
3. the total number of tables in the stats report should contain
   all tables no matter they are filtered or not.

in this change, all the problems above are addressed. and the tests
are updated to cover these use cases.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#17468
2024-03-06 10:36:20 +02:00
Kefu Chai
a53457f740 tools/scylla-nodetool: only print the specified sampling
before this change, we print all samplings returned by the API,
but this is not what cassandra nodetool's behavior, which only
prints out the specified one. and the toppartitions_test.py
in dtest actually expects that the number of sampling should
match with the one specified with command line.

so, in this change, we only print out the specified samplings.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-02-29 16:17:44 +08:00
Kefu Chai
604c7440d2 tools/scylla-nodetool: use /storage_service/toppartition/
instead of using the endpoint of /storage_service/toppartition,
use /storage_service/toppartition/. otherwise API server refuses
to return the expected result. as it does match with any API endpoint.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-02-29 16:17:44 +08:00
Kefu Chai
3d6948c13e tools/scylla-nodetool: implement info
Refs #15588

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-02-26 14:52:22 +08:00