- Notifications
You must be signed in to change notification settings - Fork 25.6k
Include search idle info to shard stats #95740
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
Merged
salvatore-campagna merged 21 commits into elastic:main from salvatore-campagna:feature/95727-indices-stats-search-idle-time May 16, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits Select commit Hold shift + click to select a range
1b9b293 feature: include search idle info to shard stats
salvatore-campagna ad1e040 fix: remove unnecessary variables
salvatore-campagna dbcefda Update docs/changelog/95740.yaml
salvatore-campagna bba65f4 Update docs/changelog/95740.yaml
salvatore-campagna b66bb7f fix: changelog area does not support array of values
salvatore-campagna c04195f fix: remove check on idle time
salvatore-campagna 44380fd fix: udpate constructor invocation
salvatore-campagna db879e2 fix: udpate constructor invocation
salvatore-campagna 562575f Merge branch 'main' into feature/95727-indices-stats-search-idle-time
salvatore-campagna b7986e5 fix: move idle info to SearchStats
salvatore-campagna 83d7776 test: include a yaml test
salvatore-campagna 632193a fix: remove check on search idle
salvatore-campagna 51af680 fix: update yaml summary
salvatore-campagna 4d43908 fix: add missing skip
salvatore-campagna a72ecbd fix: apply settings to the test index only
salvatore-campagna 8015723 Revert "fix: apply settings to the test index only"
salvatore-campagna be7810d Revert "fix: update yaml summary"
salvatore-campagna 5e27ca6 Revert "fix: remove check on search idle"
salvatore-campagna 1caac8c Revert "fix: move idle info to SearchStats"
salvatore-campagna 75d025c fix: move search idle stats back into ShardStats
salvatore-campagna 99a77ae fix: remove 'is' prefix
salvatore-campagna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 95740 | ||
| summary: Include search idle info to shard stats | ||
| area: "Search" | ||
| type: enhancement | ||
| issues: | ||
| - 95727 |
28 changes: 28 additions & 0 deletions 28 ...-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.stats/100_search_idle.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --- | ||
| setup: | ||
| - do: | ||
| indices.create: | ||
| index: test | ||
| body: | ||
| settings: | ||
| number_of_shards: 2 | ||
| number_of_replicas: 0 | ||
| index: | ||
| search: | ||
| idle: | ||
| after: 60s | ||
| | ||
| --- | ||
| "Search idle stats": | ||
| - skip: | ||
| version: " - 8.8.99" | ||
| reason: "search idle stats added in 8.9.0" | ||
| | ||
| - do: | ||
| indices.stats: { level: shards } | ||
| | ||
| - is_false: indices.test.shards.0.0.search_idle | ||
| - gte: { indices.test.shards.0.0.search_idle_time: 0 } | ||
| | ||
| - is_false: indices.test.shards.1.0.search_idle | ||
| - gte: { indices.test.shards.1.0.search_idle_time: 0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -9,9 +9,13 @@ | |
| package org.elasticsearch.index.shard; | ||
| | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; | ||
| import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; | ||
| import org.elasticsearch.action.admin.indices.stats.ShardStats; | ||
| import org.elasticsearch.action.get.GetRequest; | ||
| import org.elasticsearch.action.get.MultiGetRequest; | ||
| import org.elasticsearch.action.index.IndexResponse; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.index.IndexService; | ||
| | @@ -21,9 +25,11 @@ | |
| import org.elasticsearch.xcontent.XContentType; | ||
| | ||
| import java.util.Arrays; | ||
| import java.util.Locale; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.Phaser; | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.function.IntToLongFunction; | ||
| | ||
| | @@ -127,6 +133,12 @@ public void onFailure(Exception e) { | |
| } | ||
| indexingDone.await(); | ||
| t.join(); | ||
| final IndicesStatsResponse statsResponse = client().admin().indices().stats(new IndicesStatsRequest()).actionGet(); | ||
| for (ShardStats shardStats : statsResponse.getShards()) { | ||
| if (randomTimeValue != null && shardStats.isSearchIdle()) { | ||
| assertTrue(shardStats.getSearchIdleTime() >= randomTimeValue.millis()); | ||
| } | ||
| } | ||
| } | ||
| | ||
| public void testPendingRefreshWithIntervalChange() throws Exception { | ||
| | @@ -167,6 +179,12 @@ public void testPendingRefreshWithIntervalChange() throws Exception { | |
| assertFalse(shard.hasRefreshPending()); | ||
| assertTrue(shard.isSearchIdle()); | ||
| assertHitCount(client().prepareSearch().get(), 3); | ||
| final IndicesStatsResponse statsResponse = client().admin().indices().stats(new IndicesStatsRequest()).actionGet(); | ||
| for (ShardStats shardStats : statsResponse.getShards()) { | ||
| if (shardStats.isSearchIdle()) { | ||
| assertTrue(shardStats.getSearchIdleTime() >= TimeValue.ZERO.millis()); | ||
| } | ||
| } | ||
| } | ||
| | ||
| private void ensureNoPendingScheduledRefresh(ThreadPool threadPool) { | ||
| | @@ -182,4 +200,27 @@ private void ensureNoPendingScheduledRefresh(ThreadPool threadPool) { | |
| barrier.arriveAndAwaitAdvance(); | ||
| } | ||
| | ||
| public void testSearchIdleStats() throws InterruptedException { | ||
| int searchIdleAfter = randomIntBetween(2, 5); | ||
| final String indexName = randomAlphaOfLength(5).toLowerCase(Locale.ROOT); | ||
| client().admin() | ||
| .indices() | ||
| .prepareCreate(indexName) | ||
| .setSettings( | ||
| Settings.builder() | ||
| .put(IndexSettings.INDEX_SEARCH_IDLE_AFTER.getKey(), searchIdleAfter + "s") | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe reduce this idle after to something like 100ms here? Otherwise it increases the time to run this test significantly. | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(2, 7)) | ||
| ) | ||
| .get(); | ||
| waitUntil( | ||
| () -> Arrays.stream(client().admin().indices().prepareStats(indexName).get().getShards()).allMatch(ShardStats::isSearchIdle), | ||
| searchIdleAfter, | ||
| TimeUnit.SECONDS | ||
| ); | ||
| | ||
| final IndicesStatsResponse statsResponse = client().admin().indices().prepareStats(indexName).get(); | ||
| assertTrue(Arrays.stream(statsResponse.getShards()).allMatch(ShardStats::isSearchIdle)); | ||
| assertTrue(Arrays.stream(statsResponse.getShards()).allMatch(x -> x.getSearchIdleTime() >= searchIdleAfter)); | ||
| } | ||
| | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add a yaml test to
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.statsdir?Just to verify that the new fields are included in the stats response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about that even if the stats api sued at shard level returns a lot of data that I can't actually check with
match. Also for search idle I can't check the values in the test...just that the fields exist.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and that is what I think we should test for. We can't assert what actual values are there, just the existence of the new fields.