OpenSearch icon indicating copy to clipboard operation
OpenSearch copied to clipboard

Implementing pagination for _cat/shards

Open gargharsh3134 opened this issue 1 year ago • 5 comments

Description

This change is targeted towards implementing pagination for _cat/shards API. A new parameter, nextToken, has been introduced as both the query parameter as well as in the response body.

Functional Testing Details:

Started a 6 data nodes local cluster having 3 indices (each with 2 primaries and 3 replicas).

% curl "localhost:9200/_cluster/health?pretty"      
{
  "cluster_name" : "gkharsh-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 9,
  "number_of_data_nodes" : 6,
  "discovered_master" : true,
  "discovered_cluster_manager" : true,
  "active_primary_shards" : 6,
  "active_shards" : 24,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

_cat/shards with plain text response:


gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?nextToken=null"                                    
index4-test 0 r STARTED 0 208b 127.0.0.1 data2
index4-test 0 p STARTED 0 208b 127.0.0.1 data5
index4-test 0 r STARTED 0 208b 127.0.0.1 data4
index4-test 0 r STARTED 0 208b 127.0.0.1 data3

nextToken MCQwJDE3MTk0Mjc0OTc0NDQkaW5kZXg0LXRlc3Q=
gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?nextToken=MCQwJDE3MTk0Mjc0OTc0NDQkaW5kZXg0LXRlc3Q="
index4-test 1 r STARTED 0 208b 127.0.0.1 data1
index4-test 1 p STARTED 0 208b 127.0.0.1 data6
index4-test 1 r STARTED 0 208b 127.0.0.1 data4
index4-test 1 r STARTED 0 208b 127.0.0.1 data3

nextToken MSQwJDE3MTk0Mjc0OTc0NDQkaW5kZXg0LXRlc3Q=
gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?nextToken=MSQwJDE3MTk0Mjc0OTc0NDQkaW5kZXg0LXRlc3Q="
test-index2 0 r STARTED 0 208b 127.0.0.1 data6
test-index2 0 r STARTED 0 208b 127.0.0.1 data2
test-index2 0 r STARTED 0 208b 127.0.0.1 data5
test-index2 0 p STARTED 0 208b 127.0.0.1 data4

nextToken MCQxJDE3MTk0Mjc1MzczNzAkdGVzdC1pbmRleDI=
gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?nextToken=MCQxJDE3MTk0Mjc1MzczNzAkdGVzdC1pbmRleDI="
test-index2 1 p STARTED 0 208b 127.0.0.1 data1
test-index2 1 r STARTED 0 208b 127.0.0.1 data6
test-index2 1 r STARTED 0 208b 127.0.0.1 data2
test-index2 1 r STARTED 0 208b 127.0.0.1 data3

nextToken MSQxJDE3MTk0Mjc1MzczNzAkdGVzdC1pbmRleDI=
gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?nextToken=MSQxJDE3MTk0Mjc1MzczNzAkdGVzdC1pbmRleDI="
test-index 0 r STARTED 0 208b 127.0.0.1 data1
test-index 0 r STARTED 0 208b 127.0.0.1 data6
test-index 0 p STARTED 0 208b 127.0.0.1 data2
test-index 0 r STARTED 0 208b 127.0.0.1 data5

nextToken MCQyJDE3MTk0Mjc1NTYzODEkdGVzdC1pbmRleA==
gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?nextToken=MCQyJDE3MTk0Mjc1NTYzODEkdGVzdC1pbmRleA=="
test-index 1 p STARTED 0 208b 127.0.0.1 data1
test-index 1 r STARTED 0 208b 127.0.0.1 data5
test-index 1 r STARTED 0 208b 127.0.0.1 data4
test-index 1 r STARTED 0 208b 127.0.0.1 data3

nextToken null

_cat/shards with JSON response format (pasted only half the response, the rest of the queries will be similar to the ones added as part of plain text response):


gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?format=json&pretty&nextToken=null"                                    
{
  "nextToken" : "MCQwJDE3MTk0Mjc0OTc0NDQkaW5kZXg0LXRlc3Q=",
  "shards" : [
    {
      "index" : "index4-test",
      "shard" : "0",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data2"
    },
    {
      "index" : "index4-test",
      "shard" : "0",
      "prirep" : "p",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data5"
    },
    {
      "index" : "index4-test",
      "shard" : "0",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data4"
    },
    {
      "index" : "index4-test",
      "shard" : "0",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data3"
    }
  ]
}
gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?format=json&pretty&nextToken=MCQwJDE3MTk0Mjc0OTc0NDQkaW5kZXg0LXRlc3Q="
{
  "nextToken" : "MSQwJDE3MTk0Mjc0OTc0NDQkaW5kZXg0LXRlc3Q=",
  "shards" : [
    {
      "index" : "index4-test",
      "shard" : "1",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data1"
    },
    {
      "index" : "index4-test",
      "shard" : "1",
      "prirep" : "p",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data6"
    },
    {
      "index" : "index4-test",
      "shard" : "1",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data4"
    },
    {
      "index" : "index4-test",
      "shard" : "1",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data3"
    }
  ]
}
.
.
.
.
.
gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_cat/shards?format=json&pretty&nextToken=MCQyJDE3MTk0Mjc1NTYzODEkdGVzdC1pbmRleA=="
{
  "nextToken" : null,
  "shards" : [
    {
      "index" : "test-index",
      "shard" : "1",
      "prirep" : "p",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data1"
    },
    {
      "index" : "test-index",
      "shard" : "1",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data5"
    },
    {
      "index" : "test-index",
      "shard" : "1",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data4"
    },
    {
      "index" : "test-index",
      "shard" : "1",
      "prirep" : "r",
      "state" : "STARTED",
      "docs" : "0",
      "store" : "208b",
      "ip" : "127.0.0.1",
      "node" : "data3"
    }
  ]
}

Related Issues

Resolves #14257

Check List

  • [ ] Functionality includes testing.
  • [ ] API changes companion pull request created, if applicable.
  • [ ] Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check here.

gargharsh3134 avatar Jul 04 '24 05:07 gargharsh3134

:x: Gradle check result for 671bb92490ef11b044c2198088df1ab0d606c324: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

github-actions[bot] avatar Jul 04 '24 05:07 github-actions[bot]

:white_check_mark: Gradle check result for 549427a6f9882d0a9453dc08f593f6ed24718604: SUCCESS

github-actions[bot] avatar Jul 09 '24 06:07 github-actions[bot]

Codecov Report

Attention: Patch coverage is 79.21569% with 53 lines in your changes missing coverage. Please review.

Project coverage is 72.01%. Comparing base (7a58f5e) to head (10f82d2). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...admin/cluster/shards/TransportCatShardsAction.java 0.00% 20 Missing :warning:
...g/opensearch/rest/action/cat/RestShardsAction.java 47.05% 9 Missing :warning:
...a/org/opensearch/action/pagination/PageParams.java 75.00% 1 Missing and 5 partials :warning:
...rch/action/pagination/IndexPaginationStrategy.java 78.26% 0 Missing and 5 partials :warning:
...va/org/opensearch/action/pagination/PageToken.java 75.00% 1 Missing and 4 partials :warning:
...action/admin/cluster/shards/CatShardsResponse.java 81.81% 2 Missing and 2 partials :warning:
...rch/action/pagination/ShardPaginationStrategy.java 95.55% 1 Missing and 3 partials :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14641      +/-   ##
============================================
+ Coverage     71.88%   72.01%   +0.12%     
- Complexity    64546    64714     +168     
============================================
  Files          5296     5298       +2     
  Lines        301754   301952     +198     
  Branches      43588    43627      +39     
============================================
+ Hits         216910   217439     +529     
+ Misses        67040    66723     -317     
+ Partials      17804    17790      -14     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 09 '24 06:07 codecov[bot]

Please make sure to queue up an update to the OpenAPI spec in https://github.com/opensearch-project/opensearch-api-specification with this.

dblock avatar Jul 10 '24 15:07 dblock

This PR is stalled because it has been open for 30 days with no activity.

:x: Gradle check result for 437b87ffd800952a296d35cfb6b058f0a08613b5: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

github-actions[bot] avatar Sep 26 '24 11:09 github-actions[bot]

:x: Gradle check result for 6c855ce7f9c2c0cc65e47e501dc96974b635942e: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

github-actions[bot] avatar Sep 27 '24 11:09 github-actions[bot]

:white_check_mark: Gradle check result for d723978287b5acbc67657dd85fadb7a1fe3280b9: SUCCESS

github-actions[bot] avatar Sep 30 '24 01:09 github-actions[bot]

:grey_exclamation: Gradle check result for ee923607baf762588caa88c50b471d5c4d402ae5: UNSTABLE

  • TEST FAILURES:
      1 org.opensearch.index.IndexServiceTests.testAsyncTranslogTrimTaskOnClosedIndex

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

github-actions[bot] avatar Sep 30 '24 07:09 github-actions[bot]

:x: Gradle check result for d51a28280c361ba111d4679d02f8bba500ce2b3a: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

github-actions[bot] avatar Oct 01 '24 06:10 github-actions[bot]

:x: Gradle check result for e9993a147634273643b52ec876b09254baa8d187: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

github-actions[bot] avatar Oct 03 '24 07:10 github-actions[bot]

:white_check_mark: Gradle check result for ede07004b459dfa4bcf1d50e49e88abffeb4f65f: SUCCESS

github-actions[bot] avatar Oct 03 '24 13:10 github-actions[bot]

:x: Gradle check result for 757b837100f2e0d6d096acf585527f91ae542a05: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

github-actions[bot] avatar Oct 03 '24 19:10 github-actions[bot]

:grey_exclamation: Gradle check result for 46988583ae22dbe92e4158a984b9959a27f84c52: UNSTABLE

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

github-actions[bot] avatar Oct 03 '24 21:10 github-actions[bot]

:white_check_mark: Gradle check result for 10f82d2e9f2a96f714c66a4ba3b4cdc44752e743: SUCCESS

github-actions[bot] avatar Oct 07 '24 07:10 github-actions[bot]

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.x
# Create a new branch
git switch --create backport/backport-14641-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 a81b868facc186728b3d35fd65a6d95621f1dd82
# Push it to GitHub
git push --set-upstream origin backport/backport-14641-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-14641-to-2.x.