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

Add cluster setting for TDigestExecutionHint #96914

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/96914.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 96914
summary: Add cluster setting for TDigestExecutionHint
area: Aggregations
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.SearchService;
import org.elasticsearch.search.aggregations.MultiBucketConsumerService;
import org.elasticsearch.search.aggregations.metrics.TDigestExecutionHint;
import org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter;
import org.elasticsearch.snapshots.InternalSnapshotsInfoService;
import org.elasticsearch.snapshots.RestoreService;
Expand Down Expand Up @@ -576,7 +577,8 @@ public void apply(Settings value, Settings current, Settings previous) {
IndicesClusterStateService.SHARD_LOCK_RETRY_INTERVAL_SETTING,
IndicesClusterStateService.SHARD_LOCK_RETRY_TIMEOUT_SETTING,
IngestSettings.GROK_WATCHDOG_INTERVAL,
IngestSettings.GROK_WATCHDOG_MAX_EXECUTION_TIME
IngestSettings.GROK_WATCHDOG_MAX_EXECUTION_TIME,
TDigestExecutionHint.SETTING
).filter(Objects::nonNull).collect(Collectors.toSet());

static List<SettingUpgrader<?>> BUILT_IN_SETTING_UPGRADERS = Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.MultiBucketConsumerService;
import org.elasticsearch.search.aggregations.SearchContextAggregations;
import org.elasticsearch.search.aggregations.metrics.TDigestExecutionHint;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.AggregationContext.ProductionAggregationContext;
import org.elasticsearch.search.builder.SearchSourceBuilder;
Expand Down Expand Up @@ -329,6 +330,9 @@ public SearchService(
enableRewriteAggsToFilterByFilter = ENABLE_REWRITE_AGGS_TO_FILTER_BY_FILTER.get(settings);
clusterService.getClusterSettings()
.addSettingsUpdateConsumer(ENABLE_REWRITE_AGGS_TO_FILTER_BY_FILTER, this::setEnableRewriteAggsToFilterByFilter);

TDigestExecutionHint.SETTING.get(settings);
clusterService.getClusterSettings().addSettingsUpdateConsumer(TDigestExecutionHint.SETTING, TDigestExecutionHint::setDefaultValue);
}

private static void validateKeepAlives(TimeValue defaultKeepAlive, TimeValue maxKeepAlive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Setting;

import java.io.IOException;

Expand All @@ -21,6 +22,24 @@ public enum TDigestExecutionHint implements Writeable {
DEFAULT(0), // Use a TDigest that is optimized for performance, with a small penalty in accuracy.
HIGH_ACCURACY(1); // Use a TDigest that is optimize for accuracy, at the expense of performance.

public static final Setting<String> SETTING = Setting.simpleString(
"search.aggs.tdigest_execution_hint",
"",
TDigestExecutionHint::parse,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

private static volatile TDigestExecutionHint defaultHint = DEFAULT;

public static TDigestExecutionHint getDefaultValue() {
return defaultHint;
}

public static void setDefaultValue(String value) {
defaultHint = parse(value);
}

TDigestExecutionHint(int id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public static TDigestState createOptimizedForAccuracy(double compression) {
* @return a TDigestState object
*/
public static TDigestState create(double compression, TDigestExecutionHint executionHint) {
if (executionHint == TDigestExecutionHint.DEFAULT) {
// Check for overrides through cluster settings.
executionHint = TDigestExecutionHint.getDefaultValue();
}
return switch (executionHint) {
case HIGH_ACCURACY -> createOptimizedForAccuracy(compression);
case DEFAULT -> create(compression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public void testParsing() {
expectThrows(IllegalArgumentException.class, () -> TDigestExecutionHint.parse("NO SUCH HINT"));
}

public void testDefaultValue() {
assertEquals(TDigestExecutionHint.DEFAULT, TDigestExecutionHint.getDefaultValue());

TDigestExecutionHint.setDefaultValue(TDigestExecutionHint.HIGH_ACCURACY.toString());
assertEquals(TDigestExecutionHint.HIGH_ACCURACY, TDigestExecutionHint.getDefaultValue());

TDigestExecutionHint hint = randomFrom(TDigestExecutionHint.values());
TDigestExecutionHint.setDefaultValue(hint.toString());
assertEquals(hint, TDigestExecutionHint.getDefaultValue());
}

private static TDigestExecutionHint writeToAndReadFrom(TDigestExecutionHint state) throws IOException {
try (BytesStreamOutput out = new BytesStreamOutput()) {
state.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,29 @@ public void testFactoryMethods() {
assertNotEquals(anotherFast, anotherAccurate);
}

public void testOverrideDefaultType() {
TDigestState fast = TDigestState.create(100);
TDigestState accurate = TDigestState.createOptimizedForAccuracy(100);

TDigestExecutionHint.setDefaultValue(TDigestExecutionHint.HIGH_ACCURACY.toString());
TDigestState anotherAccurate = TDigestState.create(100, TDigestExecutionHint.DEFAULT);

TDigestExecutionHint.setDefaultValue(TDigestExecutionHint.DEFAULT.toString());
TDigestState anotherFast = TDigestState.create(100, TDigestExecutionHint.DEFAULT);

for (int i = 0; i < 100; i++) {
fast.add(i);
anotherFast.add(i);
accurate.add(i);
anotherAccurate.add(i);
}

assertEquals(fast, anotherFast);
assertEquals(accurate, anotherAccurate);
assertNotEquals(fast, accurate);
assertNotEquals(anotherFast, anotherAccurate);
}

private static TDigestState writeToAndReadFrom(TDigestState state, TransportVersion version) throws IOException {
BytesRef serializedAggs = serialize(state, version);
try (
Expand Down