-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Enable Shard Search-load rate metrics for injection #127743
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
Closed
drempapis
wants to merge
130
commits into
elastic:main
from
drempapis:multiproject/lightweight_stats_action_rrc
Closed
Changes from all commits
Commits
Show all changes
130 commits
Select commit
Hold shift + click to select a range
9d9b6af
unmute tests
drempapis 02ddf82
revert
drempapis bf79ef3
Merge remote-tracking branch 'upstream/main'
drempapis f1c91bd
Merge remote-tracking branch 'upstream/main'
drempapis ba67bff
Merge remote-tracking branch 'upstream/main'
drempapis 2c3654a
Merge remote-tracking branch 'upstream/main'
drempapis 58d4762
Merge remote-tracking branch 'upstream/main'
drempapis bc38090
Merge remote-tracking branch 'upstream/main'
drempapis ef0447b
Merge remote-tracking branch 'upstream/main'
drempapis fe009d7
Merge remote-tracking branch 'upstream/main'
drempapis a747a40
Merge remote-tracking branch 'upstream/main'
drempapis f3e47ae
Merge remote-tracking branch 'upstream/main'
drempapis 2bc0107
Merge remote-tracking branch 'upstream/main'
drempapis f3b3d00
Merge remote-tracking branch 'upstream/main'
drempapis f52789e
Merge remote-tracking branch 'upstream/main'
drempapis ec243b7
Merge remote-tracking branch 'upstream/main'
drempapis f93eb9b
Merge remote-tracking branch 'upstream/main'
drempapis 2777916
Merge remote-tracking branch 'upstream/main'
drempapis 623bd7b
Merge remote-tracking branch 'upstream/main'
drempapis 3fee6af
Merge remote-tracking branch 'upstream/main'
drempapis af3fff9
Merge remote-tracking branch 'upstream/main'
drempapis a41bbad
Merge remote-tracking branch 'upstream/main'
drempapis 8115a61
Merge remote-tracking branch 'upstream/main'
drempapis 6b2361e
Merge remote-tracking branch 'upstream/main'
drempapis 41dcc1c
Merge remote-tracking branch 'upstream/main'
drempapis 2df7f62
Merge remote-tracking branch 'upstream/main'
drempapis 6b95b0c
Merge remote-tracking branch 'upstream/main'
drempapis eadf8cf
Merge remote-tracking branch 'upstream/main'
drempapis 41dc557
Merge remote-tracking branch 'upstream/main'
drempapis e0e1740
Merge remote-tracking branch 'upstream/main'
drempapis 1ba2eaa
Merge remote-tracking branch 'upstream/main'
drempapis 6820c35
Merge remote-tracking branch 'upstream/main'
drempapis 8280559
Merge remote-tracking branch 'upstream/main'
drempapis e82375e
Merge remote-tracking branch 'upstream/main'
drempapis ce4c1c9
Merge remote-tracking branch 'upstream/main'
drempapis ff92f92
Merge remote-tracking branch 'upstream/main'
drempapis c0f4d18
Merge remote-tracking branch 'upstream/main'
drempapis 02ac377
Merge remote-tracking branch 'upstream/main'
drempapis 42aa647
Merge remote-tracking branch 'upstream/main'
drempapis bd258ab
Merge remote-tracking branch 'upstream/main'
drempapis 0d5b0d3
Merge remote-tracking branch 'upstream/main'
drempapis a6f543a
Merge remote-tracking branch 'upstream/main'
drempapis 89a6aca
Merge remote-tracking branch 'upstream/main'
drempapis 19b0900
Merge remote-tracking branch 'upstream/main'
drempapis 9f1af25
Merge remote-tracking branch 'upstream/main'
drempapis 9cedf78
Merge remote-tracking branch 'upstream/main'
drempapis a23541b
Merge remote-tracking branch 'upstream/main'
drempapis 406af11
Merge remote-tracking branch 'upstream/main'
drempapis d324d5f
Merge remote-tracking branch 'upstream/main'
drempapis fc2b041
Merge remote-tracking branch 'upstream/main'
drempapis 206454b
Merge remote-tracking branch 'upstream/main'
drempapis f36ed2a
Merge remote-tracking branch 'upstream/main'
drempapis acc28b5
Merge remote-tracking branch 'upstream/main'
drempapis f8d3ce0
Merge remote-tracking branch 'upstream/main'
drempapis c34cc87
Merge remote-tracking branch 'upstream/main'
drempapis e2c36f8
Merge remote-tracking branch 'upstream/main'
drempapis 8398854
Merge remote-tracking branch 'upstream/main'
drempapis 037eedd
Merge remote-tracking branch 'upstream/main'
drempapis 2a8a7d3
Merge remote-tracking branch 'upstream/main'
drempapis 83b8fab
Merge remote-tracking branch 'upstream/main'
drempapis b6a0df7
Merge remote-tracking branch 'upstream/main'
drempapis c33891e
Merge remote-tracking branch 'upstream/main'
drempapis 0c64b54
Merge remote-tracking branch 'upstream/main'
drempapis e7ba6ee
Merge remote-tracking branch 'upstream/main'
drempapis 66453b4
Merge remote-tracking branch 'upstream/main'
drempapis a345f39
Merge remote-tracking branch 'upstream/main'
drempapis e9dac7a
Merge remote-tracking branch 'upstream/main'
drempapis 2cb1681
Merge remote-tracking branch 'upstream/main'
drempapis d90c490
Merge remote-tracking branch 'upstream/main'
drempapis 0a9a91d
Merge branch 'main' of github.com:drempapis/elasticsearch
drempapis 1e23708
Merge branch 'main' of github.com:drempapis/elasticsearch
drempapis 7639368
test
drempapis 98fe3cf
Add Internal call for multiproject pull method
drempapis 93a7ee7
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 75a5398
update
drempapis db45d45
update
drempapis c5a249d
update the base code
drempapis cce3194
update code
drempapis 01d1aa9
Add javadoc
drempapis dfed174
update naming
drempapis 6d4928d
Update code
drempapis 5210c25
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 44aced7
revert code
drempapis 6efbdba
update code
drempapis 7a60718
Add tests for certain classes:
drempapis 9839c83
Update naming
drempapis 2891849
update code
drempapis fa837fa
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis c395c50
update after review
drempapis da312f2
Add javadoc
drempapis cdbe6ff
udpate javadoc:
drempapis 3b692ae
spi implementation
drempapis 6ccf982
update
drempapis 2eadc7f
update
drempapis 9023b18
update
drempapis 7dccbe7
update code
drempapis 1e797fc
update code
drempapis c4353ae
update
drempapis 36a861d
update
drempapis c786d43
Create spi to load serverless classes
drempapis 5fea235
update after local review
drempapis 88635ca
Spi implementation for search load
drempapis a8b99c1
Move test to serverless
drempapis a3a050b
Move new Transport Action code to serverless repo
drempapis 7fa6707
Fix compilation errors
drempapis da34d84
Remove file
drempapis f072f3b
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis c1b8b13
move code to stateless
drempapis 1a5005c
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 62c4349
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 1f9d90e
Mock method for tests
drempapis 341d44d
[CI] Auto commit changes from spotless
2a8a7eb
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 984063f
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 04558d5
Minimize the scope of retuned dto on a per shard basis
drempapis 6e70bd6
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis f03a83b
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis d12c34d
Merge branch 'main' of github.com:drempapis/elasticsearch
drempapis 046faba
Merge branch 'elastic:main' into main
drempapis 6015323
Merge remote-tracking branch 'upstream/main'
drempapis 043cb6a
Merge remote-tracking branch 'upstream/main'
drempapis a488d9f
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 30e138b
Merge remote-tracking branch 'upstream/main'
drempapis 80e62e8
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 5545cfc
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 36e19da
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis e60add0
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis e551894
Merge branch 'main' into multiproject/lightweight_stats_action_rrc
drempapis 2f3017c
update after review
drempapis c55a725
[CI] Auto commit changes from spotless
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
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
50 changes: 50 additions & 0 deletions
50
server/src/main/java/org/elasticsearch/index/search/stats/SearchStatsSettings.java
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,50 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.search.stats; | ||
|
|
||
| import org.elasticsearch.common.settings.ClusterSettings; | ||
| import org.elasticsearch.common.settings.Setting; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.core.TimeValue; | ||
|
|
||
| /** | ||
| * Container for cluster settings | ||
| */ | ||
| public class SearchStatsSettings { | ||
|
|
||
| public static final TimeValue RECENT_READ_LOAD_HALF_LIFE_DEFAULT = TimeValue.timeValueMinutes(5); | ||
| static final TimeValue RECENT_READ_LOAD_HALF_LIFE_MIN = TimeValue.timeValueSeconds(1); // A sub-second half-life makes no sense | ||
| static final TimeValue RECENT_READ_LOAD_HALF_LIFE_MAX = TimeValue.timeValueDays(100_000); // Long.MAX_VALUE nanos, rounded down | ||
|
|
||
| /** | ||
| * A cluster setting giving the half-life, in seconds, to use for the Exponentially Weighted Moving Rate calculation used for the | ||
| * recency-weighted read load | ||
| * | ||
| * <p>This is dynamic, but changes only apply to newly-opened shards. | ||
| */ | ||
| public static final Setting<TimeValue> RECENT_READ_LOAD_HALF_LIFE_SETTING = Setting.timeSetting( | ||
| "indices.stats.recent_read_load.half_life", | ||
| RECENT_READ_LOAD_HALF_LIFE_DEFAULT, | ||
| RECENT_READ_LOAD_HALF_LIFE_MIN, | ||
| RECENT_READ_LOAD_HALF_LIFE_MAX, | ||
| Setting.Property.Dynamic, | ||
| Setting.Property.NodeScope | ||
| ); | ||
|
|
||
| private TimeValue recentReadLoadHalfLifeForNewShards = RECENT_READ_LOAD_HALF_LIFE_SETTING.getDefault(Settings.EMPTY); | ||
|
|
||
| public SearchStatsSettings(ClusterSettings clusterSettings) { | ||
| clusterSettings.initializeAndWatch(RECENT_READ_LOAD_HALF_LIFE_SETTING, value -> recentReadLoadHalfLifeForNewShards = value); | ||
| } | ||
|
|
||
| public TimeValue getRecentReadLoadHalfLifeForNewShards() { | ||
| return recentReadLoadHalfLifeForNewShards; | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchLoadRateProvider.java
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,38 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.search.stats; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * A factory interface for creating instances of {@link ShardSearchLoadRateService} using configurable settings | ||
| * and a time source. | ||
| * <p> | ||
| * This abstraction allows for flexible instantiation of load rate tracking services, potentially with | ||
| * different strategies based on provided settings or runtime context. | ||
| */ | ||
| public interface ShardSearchLoadRateProvider { | ||
|
|
||
| /** | ||
| * The default no-op implementation of the provider, which always returns {@link ShardSearchLoadRateService#NOOP}. | ||
| * <p> | ||
| * Useful as a fallback or when search load rate tracking is disabled or not required. | ||
| */ | ||
| ShardSearchLoadRateProvider DEFAULT = (settings, timeProvider) -> ShardSearchLoadRateService.NOOP; | ||
|
|
||
| /** | ||
| * Creates a new instance of {@link ShardSearchLoadRateService} using the given settings and time provider. | ||
| * | ||
| * @param settings the search statistics configuration settings that may influence the service behavior | ||
| * @param timeProvider a supplier of the current time, typically in milliseconds or nanoseconds | ||
| * @return a {@code ShardSearchLoadRateService} instance configured with the provided context | ||
| */ | ||
| ShardSearchLoadRateService create(SearchStatsSettings settings, Supplier<Long> timeProvider); | ||
| } |
33 changes: 33 additions & 0 deletions
33
server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchLoadRateService.java
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,33 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.search.stats; | ||
|
|
||
| /** | ||
| * Service interface for estimating the search load rate of a shard using provided search statistics. | ||
| * <p> | ||
| * Implementations may apply various heuristics or models, such as exponentially weighted moving rate, | ||
| * to track and estimate the current load on a shard based on its search activity. | ||
| */ | ||
| public interface ShardSearchLoadRateService { | ||
|
|
||
| /** | ||
| * A no-op implementation of {@code ShardSearchLoadRateService} that always returns {@code 0.0} | ||
| * This can be used as a fallback or default when no actual load tracking is required. | ||
| */ | ||
| ShardSearchLoadRateService NOOP = (stats) -> 0.0; | ||
|
|
||
| /** | ||
| * Computes the search load rate based on the provided shard-level search statistics. | ||
| * | ||
| * @param stats the search statistics for the shard, typically including metrics like query count, latency, etc. | ||
| * @return the {@code double} representing the calculated EWMR on the shard | ||
| */ | ||
| double getSearchLoadRate(SearchStats.Stats stats); | ||
| } |
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.
I'm not sure why we're injecting a service here. Could the index shard calculate the ewmr directly?
What's the reason for the SPI?
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.
That's a good question. The main reason for injecting the service via SPI rather than calculating the EWMR directly in IndexShard is to avoid unnecessary memory overhead when the functionality isn't needed. While lazy initialization behind a proxy is an option on the stateful side, it would add unnecessary complexity to the core codebase.
Additionally, this design helps separate concerns: the implementation is specific to the multi-project setup and doesn't belong in the core logic of IndexShard. Placing it behind an SPI keeps the core codebase clean and aligns the implementation more closely with the project that owns the logic, improving maintainability and modularity. So, keeping it behind an SPI ensures it's only enabled where applicable.