Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid making further transport calls if paginationStrategy outputs empty entities #16444

Merged

Conversation

gargharsh3134
Copy link
Contributor

@gargharsh3134 gargharsh3134 commented Oct 23, 2024

Description

For paginated _list/indices and _list/shards APIs, if their corresponding strategies don't output any entities, the indicesToBeQueried gets set to empty and any subsequent IndicesStatsTransport action ends up fetching stats for all the indices. Change in this PR addresses and optimizes such scenarios.

Functional Testing:

Added following additional info logs just for the testing purpose (no need to include such logs in main):


protected Table buildTable(
        final RestRequest request,
        final Map<String, Settings> indicesSettings,
        final Map<String, ClusterIndexHealth> indicesHealths,
        final Map<String, IndexStats> indicesStats,
        final Map<String, IndexMetadata> indicesMetadatas,
        final Iterator<Tuple<String, Settings>> tableIterator,
        final PageToken pageToken
    ) {
        final String healthParam = request.param("health");
        final Table table = getTableWithHeader(request, pageToken);

        llogger.info("Building table after querying {} indices stats", indicesStats.size());

        while (tableIterator.hasNext()) {
            final Tuple<String, Settings> tuple = tableIterator.next();
            String indexName = tuple.v1();


// For paginated queries, if strategy outputs no indices to be returned,
 // avoid fetching indices stats.
 if (shouldSkipIndicesStatsRequest(paginationStrategy)) {
     logger.info("Skipping indices stats call");
      groupedListener.onResponse(EMPTY_INDICES_STATS_RESPONSE);
} 


private void sendIndicesStatsRequest(
        final String[] indices,
        final IndicesOptions indicesOptions,
        final boolean includeUnloadedSegments,
        final NodeClient client,
        final ActionListener<IndicesStatsResponse> listener
    ) {
        logger.info("Sending indices stats request");
        final IndicesStatsRequest request = new IndicesStatsRequest();
}

local cluster's indices:

gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_list/indices"    
green open index4-test s2AJ5CoYRru-8lbB871pWA 2 3 0 0 1.6kb 416b
green open test-index2 k5FNOQcvSV679Hcs1g-OwQ 2 3 0 0 1.6kb 416b
green open test-index  FclPNwqmQie3RnpoOYpLTg 2 3 0 0 1.6kb 417b
next_token null



Before making changes, querying for a wildcard which doesn't match any index was leading to all the index stats being fetched unnecessarily.

gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_list/indices/hi*"
next_token null



[2024-10-23T12:10:15,527][INFO ][o.o.r.a.l.RestIndicesListAction] [master1] Sending indices stats request
[2024-10-23T12:10:15,543][INFO ][o.o.r.a.l.RestIndicesListAction] [master1] Building table after querying 3 indices stats

After making the changes, stats call is not being made:

gkharsh@bcd07443f159 OpenSearch % curl "localhost:9200/_list/indices/hi*"
next_token null


[2024-10-23T12:13:31,506][INFO ][o.o.r.a.l.RestIndicesListAction] [master1] Skipping indices stats call
[2024-10-23T12:13:31,515][INFO ][o.o.r.a.l.RestIndicesListAction] [master1] Building table after querying 0 indices stats


Related Issues

Resolves #16448

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.

Copy link
Contributor

✅ Gradle check result for 523acf6: SUCCESS

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

Attention: Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Project coverage is 72.09%. Comparing base (9489a21) to head (6d0acfc).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...admin/cluster/shards/TransportCatShardsAction.java 0.00% 5 Missing ⚠️
.../opensearch/rest/action/cat/RestIndicesAction.java 0.00% 5 Missing ⚠️
...tion/admin/indices/stats/IndicesStatsResponse.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #16444      +/-   ##
============================================
+ Coverage     72.04%   72.09%   +0.05%     
- Complexity    65020    65056      +36     
============================================
  Files          5313     5313              
  Lines        303356   303365       +9     
  Branches      43900    43902       +2     
============================================
+ Hits         218551   218718     +167     
+ Misses        66905    66728     -177     
- Partials      17900    17919      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…entities

Signed-off-by: Harsh Garg <gkharsh@amazon.com>
@gargharsh3134 gargharsh3134 force-pushed the listShardsEmptyIndices branch from 523acf6 to b328dbc Compare October 23, 2024 06:11
Signed-off-by: Harsh Garg <gkharsh@amazon.com>
@github-actions github-actions bot added bug Something isn't working Cluster Manager labels Oct 23, 2024
Copy link
Contributor

❌ Gradle check result for 016fcaf: 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?

Copy link
Contributor

@rajiv-kv rajiv-kv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: Harsh Garg <gkharsh@amazon.com>
@gargharsh3134 gargharsh3134 force-pushed the listShardsEmptyIndices branch from 2099d92 to 40cc55a Compare October 23, 2024 10:16
@shwetathareja
Copy link
Member

@gargharsh3134 can we add test for it?

@shwetathareja shwetathareja added the backport 2.x Backport to 2.x branch label Oct 23, 2024
Copy link
Contributor

❌ Gradle check result for a44870a: 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?

Signed-off-by: Harsh Garg <gkharsh@amazon.com>
@gargharsh3134
Copy link
Contributor Author

can we add test for it?

@shwetathareja I did discuss this earlier with @rajiv-kv. But, we don't have any UTs for RestLayer and It won't be possible to assert this info in an Integ Test, that's why I just added functional testing details. It is the behaviour of each TransportNodesAction, that if indices in the request are not set, we end up fetching everything, Not really sure how to have this in tests. Would you have any suggestions?

Copy link
Contributor

❕ Gradle check result for 6d0acfc: 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.

@gargharsh3134
Copy link
Contributor Author

Opened an issue to track addition of integ tests inside TransportActions -> #16454

Copy link
Member

@shwetathareja shwetathareja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving it so that it can make it to 2.18. Test will be added as fast follow immediately.

@shwetathareja shwetathareja merged commit 9a476b6 into opensearch-project:main Oct 23, 2024
37 of 38 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 23, 2024
…pty entities (#16444)

Signed-off-by: Harsh Garg <gkharsh@amazon.com>
(cherry picked from commit 9a476b6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
shwetathareja pushed a commit that referenced this pull request Oct 23, 2024
…pty entities (#16444) (#16456)

(cherry picked from commit 9a476b6)

Signed-off-by: Harsh Garg <gkharsh@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch bug Something isn't working Cluster Manager skip-changelog
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Unoptimization in _list APIs leading to unnecessary IndicesStats call
3 participants