diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.delete_sample_configuration/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.delete_sample_configuration/10_basic.yml index a1179549546ff..4a3667b5c2e40 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.delete_sample_configuration/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.delete_sample_configuration/10_basic.yml @@ -28,7 +28,7 @@ teardown: body: rate: 0.5 max_samples: 100 - max_size: "10mb" + max_size: "100kb" time_to_live: "1h" - match: { acknowledged: true } @@ -186,7 +186,7 @@ teardown: body: rate: 0.9 max_samples: 90 - max_size: "20mb" + max_size: "100kb" - match: { acknowledged: true } diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_all_sample_configuration/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_all_sample_configuration/10_basic.yml index 97014cef22623..9cdfd5c371ec1 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_all_sample_configuration/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_all_sample_configuration/10_basic.yml @@ -40,7 +40,7 @@ teardown: body: rate: 0.5 max_samples: 100 - max_size: "10mb" + max_size: "100kb" time_to_live: "1h" - match: { acknowledged: true } @@ -53,7 +53,7 @@ teardown: - match: { configurations.0.index: "test-single-config-index" } - match: { configurations.0.configuration.rate: 0.5 } - match: { configurations.0.configuration.max_samples: 100 } - - match: { configurations.0.configuration.max_size: "10mb" } + - match: { configurations.0.configuration.max_size: "100kb" } - match: { configurations.0.configuration.time_to_live: "1h" } --- @@ -85,7 +85,7 @@ teardown: body: rate: 0.7 max_samples: 200 - max_size: "20mb" + max_size: "100kb" - match: { acknowledged: true } @@ -186,7 +186,7 @@ teardown: body: rate: 0.9 max_samples: 150 - max_size: "15mb" + max_size: "100kb" - match: { acknowledged: true } @@ -199,7 +199,7 @@ teardown: - match: { configurations.0.index: "test-update-all-index" } - match: { configurations.0.configuration.rate: 0.9 } - match: { configurations.0.configuration.max_samples: 150 } - - match: { configurations.0.configuration.max_size: "15mb" } + - match: { configurations.0.configuration.max_size: "100kb" } --- "Get all sampling configurations after deletion": diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_sample_configuration/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_sample_configuration/10_basic.yml index 490172d78d9b0..3e5631ee718ce 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_sample_configuration/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_sample_configuration/10_basic.yml @@ -27,7 +27,7 @@ teardown: body: rate: 0.5 max_samples: 100 - max_size: "10mb" + max_size: "100kb" time_to_live: "1h" - match: { acknowledged: true } @@ -39,7 +39,7 @@ teardown: - match: { configuration.rate: 0.5 } - match: { configuration.max_samples: 100 } - - match: { configuration.max_size: "10mb" } + - match: { configuration.max_size: "100kb" } - match: { configuration.time_to_live: "1h" } --- @@ -140,7 +140,7 @@ teardown: body: rate: 0.8 max_samples: 75 - max_size: "5mb" + max_size: "100kb" - match: { acknowledged: true } @@ -152,7 +152,7 @@ teardown: - match: { configuration.rate: 0.8 } - match: { configuration.max_samples: 75 } - - match: { configuration.max_size: "5mb" } + - match: { configuration.max_size: "100kb" } --- "Get sampling configuration with master timeout": diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.put_sample_configuration/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.put_sample_configuration/10_basic.yml index b8ea5106637cb..b3324e8e637f7 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.put_sample_configuration/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.put_sample_configuration/10_basic.yml @@ -27,7 +27,7 @@ teardown: body: rate: 0.5 max_samples: 100 - max_size: "10mb" + max_size: "100kb" time_to_live: "1h" - match: { acknowledged: true } @@ -85,7 +85,7 @@ teardown: body: rate: 0.8 max_samples: 75 - max_size: "5mb" + max_size: "100kb" - match: { acknowledged: true } @@ -155,7 +155,7 @@ teardown: body: rate: ".05" max_samples: 1000 - max_size: "10mb" + max_size: "100kb" time_to_live: "1d" - match: { acknowledged: true } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationActionIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationActionIT.java index 5cd3085e2eb60..ec0ba0a3b077c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationActionIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationActionIT.java @@ -215,7 +215,7 @@ private SamplingConfiguration randomSamplingConfiguration() { return new SamplingConfiguration( randomDoubleBetween(0.1, 1.0, true), randomBoolean() ? randomIntBetween(1, SamplingConfiguration.MAX_SAMPLES_LIMIT) : null, - randomBoolean() ? ByteSizeValue.ofGb(randomLongBetween(1, SamplingConfiguration.MAX_SIZE_LIMIT_GIGABYTES)) : null, + randomBoolean() ? ByteSizeValue.ofMb(randomLongBetween(1, 100)) : null, randomBoolean() ? randomValidTimeValue() : null, randomBoolean() ? randomAlphaOfLengthBetween(5, 30) : null ); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/sampling/SamplingConfiguration.java b/server/src/main/java/org/elasticsearch/action/admin/indices/sampling/SamplingConfiguration.java index 2acc016cab0be..025bc1f9e0c4e 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/sampling/SamplingConfiguration.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/sampling/SamplingConfiguration.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.xcontent.ConstructingObjectParser; import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.ParseField; @@ -57,10 +58,10 @@ public record SamplingConfiguration( // Constants for validation and defaults public static final int MAX_SAMPLES_LIMIT = 10_000; - public static final long MAX_SIZE_LIMIT_GIGABYTES = 5; + public static final double MAX_SIZE_HEAP_PERCENTAGE_LIMIT = 0.01; + public static final ByteSizeValue DEFAULT_MAX_SIZE_FLOOR = ByteSizeValue.ofKb(100); public static final long MAX_TIME_TO_LIVE_DAYS = 30; public static final int DEFAULT_MAX_SAMPLES = 100; - public static final long DEFAULT_MAX_SIZE_GIGABYTES = 1; public static final long DEFAULT_TIME_TO_LIVE_DAYS = 10; // Error messages @@ -68,7 +69,11 @@ public record SamplingConfiguration( public static final String INVALID_MAX_SAMPLES_MIN_MESSAGE = "maxSamples must be greater than 0"; public static final String INVALID_MAX_SAMPLES_MAX_MESSAGE = "maxSamples must be less than or equal to " + MAX_SAMPLES_LIMIT; public static final String INVALID_MAX_SIZE_MIN_MESSAGE = "maxSize must be greater than 0"; - public static final String INVALID_MAX_SIZE_MAX_MESSAGE = "maxSize must be less than or equal to " + MAX_SIZE_LIMIT_GIGABYTES + "GB"; + public static final String INVALID_MAX_SIZE_MAX_MESSAGE = "maxSize must be less than or equal to " + + (int) (MAX_SIZE_HEAP_PERCENTAGE_LIMIT * 100) + + "% of heap size (" + + calculateDefaultMaxSize().toString() + + ")"; public static final String INVALID_TIME_TO_LIVE_MIN_MESSAGE = "timeToLive must be greater than 0"; public static final String INVALID_TIME_TO_LIVE_MAX_MESSAGE = "timeToLive must be less than or equal to " + MAX_TIME_TO_LIVE_DAYS @@ -152,7 +157,7 @@ public record SamplingConfiguration( * * @param rate The fraction of documents to sample (must be between 0 and 1) * @param maxSamples The maximum number of documents to sample (optional, defaults to {@link #DEFAULT_MAX_SAMPLES}) - * @param maxSize The maximum total size of sampled documents (optional, defaults to {@link #DEFAULT_MAX_SIZE_GIGABYTES} GB) + * @param maxSize The maximum total size of sampled documents (optional, defaults to {@link #MAX_SIZE_HEAP_PERCENTAGE_LIMIT} of heap) * @param timeToLive The duration for which the sampled documents * should be retained (optional, defaults to {@link #DEFAULT_TIME_TO_LIVE_DAYS} days) * @param condition An optional condition script that sampled documents must satisfy (optional, can be null) @@ -168,12 +173,23 @@ public SamplingConfiguration( ) { this.rate = rate; this.maxSamples = maxSamples == null ? DEFAULT_MAX_SAMPLES : maxSamples; - this.maxSize = maxSize == null ? ByteSizeValue.ofGb(DEFAULT_MAX_SIZE_GIGABYTES) : maxSize; + this.maxSize = maxSize == null ? calculateDefaultMaxSize() : maxSize; this.timeToLive = timeToLive == null ? TimeValue.timeValueDays(DEFAULT_TIME_TO_LIVE_DAYS) : timeToLive; this.condition = condition; this.creationTime = creationTime == null ? Instant.now().toEpochMilli() : creationTime; } + /** + * Calculates the default max size as a percentage of the configured heap size, + * with a minimum floor value. + * + * @return The default max size value + */ + private static ByteSizeValue calculateDefaultMaxSize() { + long heapBasedSize = (long) (MAX_SIZE_HEAP_PERCENTAGE_LIMIT * JvmInfo.jvmInfo().getConfiguredMaxHeapSize()); + return ByteSizeValue.ofBytes(Math.max(heapBasedSize, DEFAULT_MAX_SIZE_FLOOR.getBytes())); + } + // Convenience constructor without creationTime public SamplingConfiguration(double rate, Integer maxSamples, ByteSizeValue maxSize, TimeValue timeToLive, String condition) { this(rate, maxSamples, maxSize, timeToLive, condition, null); @@ -266,7 +282,7 @@ private static void validateInputs(double rate, Integer maxSamples, ByteSizeValu if (maxSize.compareTo(ByteSizeValue.ZERO) <= 0) { throw new IllegalArgumentException(INVALID_MAX_SIZE_MIN_MESSAGE); } - ByteSizeValue maxLimit = ByteSizeValue.ofGb(MAX_SIZE_LIMIT_GIGABYTES); + ByteSizeValue maxLimit = calculateDefaultMaxSize(); if (maxSize.compareTo(maxLimit) > 0) { throw new IllegalArgumentException(INVALID_MAX_SIZE_MAX_MESSAGE); } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationActionResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationActionResponseTests.java index ce93824c6b6c7..0e11ad1c0123c 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationActionResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationActionResponseTests.java @@ -81,7 +81,7 @@ private SamplingConfiguration createRandomSamplingConfiguration() { return new SamplingConfiguration( randomDoubleBetween(0.1, 1.0, true), randomBoolean() ? randomIntBetween(1, 1000) : null, - randomBoolean() ? ByteSizeValue.ofMb(randomIntBetween(1, 100)) : null, + randomBoolean() ? null : ByteSizeValue.ofKb(randomIntBetween(50, 100)), randomBoolean() ? TimeValue.timeValueMinutes(randomIntBetween(1, 60)) : null, randomBoolean() ? "ctx?.field == 'test'" : null ); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/GetSampleConfigurationActionResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/GetSampleConfigurationActionResponseTests.java index 0455458af07c2..398cc60c0b3da 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/GetSampleConfigurationActionResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/GetSampleConfigurationActionResponseTests.java @@ -47,7 +47,7 @@ private SamplingConfiguration createRandomSamplingConfiguration() { return new SamplingConfiguration( randomDoubleBetween(0.1, 1.0, true), randomBoolean() ? randomIntBetween(1, 1000) : null, - randomBoolean() ? ByteSizeValue.ofMb(randomIntBetween(1, 100)) : null, + randomBoolean() ? null : ByteSizeValue.ofKb(randomIntBetween(50, 100)), randomBoolean() ? TimeValue.timeValueMinutes(randomIntBetween(1, 60)) : null, randomBoolean() ? "ctx?.field == 'test'" : null ); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/PutSampleConfigurationActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/PutSampleConfigurationActionTests.java index a4fc1b91e491c..eb0b8b99d8975 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/PutSampleConfigurationActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/PutSampleConfigurationActionTests.java @@ -114,7 +114,7 @@ private static SamplingConfiguration createRandomSampleConfig() { return new SamplingConfiguration( randomDoubleBetween(0.0, 1.0, true), randomBoolean() ? null : randomIntBetween(1, 1000), - randomBoolean() ? null : ByteSizeValue.ofGb(randomIntBetween(1, 5)), + randomBoolean() ? null : ByteSizeValue.ofKb(randomIntBetween(50, 100)), randomBoolean() ? null : new TimeValue(randomIntBetween(1, 30), TimeUnit.DAYS), randomBoolean() ? randomAlphaOfLength(10) : null ); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/SamplingConfigurationTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/SamplingConfigurationTests.java index f1be044f1c453..b9c404bb86b12 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/SamplingConfigurationTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/SamplingConfigurationTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.test.AbstractXContentSerializingTestCase; import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.XContentParser; @@ -40,10 +41,12 @@ protected Writeable.Reader instanceReader() { @Override protected SamplingConfiguration createTestInstance() { + long maxHeap = JvmInfo.jvmInfo().getConfiguredMaxHeapSize(); + long maxSizeLimit = (long) (SamplingConfiguration.MAX_SIZE_HEAP_PERCENTAGE_LIMIT * maxHeap); return new SamplingConfiguration( randomDoubleBetween(0.0, 1.0, true), randomBoolean() ? null : randomIntBetween(1, SamplingConfiguration.MAX_SAMPLES_LIMIT), - randomBoolean() ? null : ByteSizeValue.ofGb(randomLongBetween(1, SamplingConfiguration.MAX_SIZE_LIMIT_GIGABYTES)), + randomBoolean() ? null : ByteSizeValue.ofBytes(randomLongBetween(1, maxSizeLimit)), randomBoolean() ? null : TimeValue.timeValueDays(randomLongBetween(1, SamplingConfiguration.MAX_TIME_TO_LIVE_DAYS)), randomBoolean() ? null : randomAlphaOfLength(10) ); @@ -51,6 +54,8 @@ protected SamplingConfiguration createTestInstance() { @Override protected SamplingConfiguration mutateInstance(SamplingConfiguration instance) { + long maxHeap = JvmInfo.jvmInfo().getConfiguredMaxHeapSize(); + long maxSizeLimit = (long) (SamplingConfiguration.MAX_SIZE_HEAP_PERCENTAGE_LIMIT * maxHeap); return switch (randomIntBetween(0, 4)) { case 0 -> new SamplingConfiguration( randomValueOtherThan(instance.rate(), () -> randomDoubleBetween(0.0, 1.0, true)), @@ -69,10 +74,7 @@ protected SamplingConfiguration mutateInstance(SamplingConfiguration instance) { case 2 -> new SamplingConfiguration( instance.rate(), instance.maxSamples(), - randomValueOtherThan( - instance.maxSize(), - () -> ByteSizeValue.ofGb(randomLongBetween(1, SamplingConfiguration.MAX_SIZE_LIMIT_GIGABYTES)) - ), + randomValueOtherThan(instance.maxSize(), () -> ByteSizeValue.ofBytes(randomLongBetween(1, maxSizeLimit))), instance.timeToLive(), instance.condition() ); @@ -101,7 +103,11 @@ public void testDefaults() { SamplingConfiguration config = new SamplingConfiguration(0.5, null, null, null, null); assertThat(config.rate(), equalTo(0.5)); assertThat(config.maxSamples(), equalTo(SamplingConfiguration.DEFAULT_MAX_SAMPLES)); - assertThat(config.maxSize(), equalTo(ByteSizeValue.ofGb(SamplingConfiguration.DEFAULT_MAX_SIZE_GIGABYTES))); + long expectedDefaultMaxSize = Math.max( + (long) (SamplingConfiguration.MAX_SIZE_HEAP_PERCENTAGE_LIMIT * JvmInfo.jvmInfo().getConfiguredMaxHeapSize()), + SamplingConfiguration.DEFAULT_MAX_SIZE_FLOOR.getBytes() + ); + assertThat(config.maxSize(), equalTo(ByteSizeValue.ofBytes(expectedDefaultMaxSize))); assertThat(config.timeToLive(), equalTo(TimeValue.timeValueDays(SamplingConfiguration.DEFAULT_TIME_TO_LIVE_DAYS))); assertThat(config.condition(), nullValue()); } @@ -157,12 +163,15 @@ public void testValidation() throws IOException { } """, SamplingConfiguration.INVALID_MAX_SIZE_MIN_MESSAGE); + // Test max size exceeding heap-based limit + long maxHeap = JvmInfo.jvmInfo().getConfiguredMaxHeapSize(); + long maxSizeLimit = (long) (SamplingConfiguration.MAX_SIZE_HEAP_PERCENTAGE_LIMIT * maxHeap); assertValidationError(String.format(Locale.ROOT, """ { "rate": 0.5, - "max_size": "%dgb" + "max_size_in_bytes": %d } - """, SamplingConfiguration.MAX_SIZE_LIMIT_GIGABYTES + 1), SamplingConfiguration.INVALID_MAX_SIZE_MAX_MESSAGE); + """, maxSizeLimit + 1), SamplingConfiguration.INVALID_MAX_SIZE_MAX_MESSAGE); // Test invalid timeToLive assertValidationError(""" @@ -234,24 +243,17 @@ public void testValidInputs() throws IOException { assertThat(config.maxSamples(), equalTo(1)); // Test boundary conditions - maximum values - parser = createParser( - JsonXContent.jsonXContent, - String.format( - Locale.ROOT, - """ - { - "rate": 1.0, - "max_samples": %d, - "max_size": "%dgb", - "time_to_live": "%dd", - "if": "test_condition" - } - """, - SamplingConfiguration.MAX_SAMPLES_LIMIT, - SamplingConfiguration.MAX_SIZE_LIMIT_GIGABYTES, - SamplingConfiguration.MAX_TIME_TO_LIVE_DAYS - ) - ); + long maxHeap = JvmInfo.jvmInfo().getConfiguredMaxHeapSize(); + long maxSizeLimit = (long) (SamplingConfiguration.MAX_SIZE_HEAP_PERCENTAGE_LIMIT * maxHeap); + parser = createParser(JsonXContent.jsonXContent, String.format(Locale.ROOT, """ + { + "rate": 1.0, + "max_samples": %d, + "max_size_in_bytes": %d, + "time_to_live": "%dd", + "if": "test_condition" + } + """, SamplingConfiguration.MAX_SAMPLES_LIMIT, maxSizeLimit, SamplingConfiguration.MAX_TIME_TO_LIVE_DAYS)); config = SamplingConfiguration.fromXContent(parser); assertThat(config.rate(), equalTo(1.0)); assertThat(config.maxSamples(), equalTo(SamplingConfiguration.MAX_SAMPLES_LIMIT)); @@ -332,4 +334,20 @@ public void testCreationTimeUserDataRestrictionRaw() throws IOException { assertNotNull("Expected IllegalArgumentException with creation_time_in_millis message", cause); assertThat(cause.getMessage(), equalTo("Creation time cannot be set by user (field: creation_time_in_millis)")); } + + public void testMinimumDefaultMaxSize() { + // Test that the minimum default max size is enforced + SamplingConfiguration config = new SamplingConfiguration(0.5, null, null, null, null); + + // Calculate what the heap percentage would give us + long heapBasedSize = (long) (SamplingConfiguration.MAX_SIZE_HEAP_PERCENTAGE_LIMIT * JvmInfo.jvmInfo().getConfiguredMaxHeapSize()); + long minSize = SamplingConfiguration.DEFAULT_MAX_SIZE_FLOOR.getBytes(); + + // The actual default should be the larger of the two + long expectedSize = Math.max(heapBasedSize, minSize); + assertThat(config.maxSize().getBytes(), equalTo(expectedSize)); + + // Verify it's at least the minimum + assertThat(config.maxSize().getBytes(), greaterThanOrEqualTo(minSize)); + } } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/SamplingMetadataTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/SamplingMetadataTests.java index bbccbe315051c..cc49020a00cb2 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/SamplingMetadataTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/SamplingMetadataTests.java @@ -94,7 +94,7 @@ private static SamplingConfiguration createRandomSampleConfig() { return new SamplingConfiguration( randomDoubleBetween(0.0, 1.0, true), randomBoolean() ? null : randomIntBetween(1, 1000), - randomBoolean() ? null : ByteSizeValue.ofGb(randomIntBetween(1, 5)), + randomBoolean() ? null : ByteSizeValue.ofKb(randomIntBetween(50, 100)), randomBoolean() ? null : new TimeValue(randomIntBetween(1, 30), TimeUnit.DAYS), randomBoolean() ? randomAlphaOfLength(10) : null ); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/TransportDeleteSampleConfigurationActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/TransportDeleteSampleConfigurationActionTests.java index f18d59b2e241f..75d00b2606d3f 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/TransportDeleteSampleConfigurationActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/TransportDeleteSampleConfigurationActionTests.java @@ -352,7 +352,7 @@ private SamplingConfiguration createRandomSamplingConfiguration() { return new SamplingConfiguration( randomDoubleBetween(0.0, 1.0, true), randomBoolean() ? null : randomIntBetween(1, SamplingConfiguration.MAX_SAMPLES_LIMIT), - randomBoolean() ? null : ByteSizeValue.ofGb(randomLongBetween(1, SamplingConfiguration.MAX_SIZE_LIMIT_GIGABYTES)), + randomBoolean() ? null : ByteSizeValue.ofMb(randomLongBetween(1, 100)), randomBoolean() ? null : TimeValue.timeValueDays(randomLongBetween(1, SamplingConfiguration.MAX_TIME_TO_LIVE_DAYS)), randomBoolean() ? null : randomAlphaOfLength(10) ); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/TransportPutSampleConfigurationActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/TransportPutSampleConfigurationActionTests.java index b71ce2ff3f1d5..fdab82d49c00a 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/TransportPutSampleConfigurationActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/sampling/TransportPutSampleConfigurationActionTests.java @@ -205,7 +205,7 @@ private SamplingConfiguration createRandomSamplingConfiguration() { return new SamplingConfiguration( randomDoubleBetween(0.0, 1.0, true), randomBoolean() ? null : randomIntBetween(1, SamplingConfiguration.MAX_SAMPLES_LIMIT), - randomBoolean() ? null : ByteSizeValue.ofGb(randomLongBetween(1, SamplingConfiguration.MAX_SIZE_LIMIT_GIGABYTES)), + randomBoolean() ? null : ByteSizeValue.ofMb(randomLongBetween(1, 100)), randomBoolean() ? null : TimeValue.timeValueDays(randomLongBetween(1, SamplingConfiguration.MAX_TIME_TO_LIVE_DAYS)), randomBoolean() ? null : randomAlphaOfLength(10) ); diff --git a/server/src/test/java/org/elasticsearch/ingest/SamplingServiceTests.java b/server/src/test/java/org/elasticsearch/ingest/SamplingServiceTests.java index 1b812a446365b..d67acd8e7a262 100644 --- a/server/src/test/java/org/elasticsearch/ingest/SamplingServiceTests.java +++ b/server/src/test/java/org/elasticsearch/ingest/SamplingServiceTests.java @@ -71,7 +71,7 @@ public void testMaybeSample() { .putCustom( SamplingMetadata.TYPE, new SamplingMetadata( - Map.of(indexName, new SamplingConfiguration(1.0, maxSize, ByteSizeValue.ofMb(100), TimeValue.timeValueDays(3), null)) + Map.of(indexName, new SamplingConfiguration(1.0, maxSize, ByteSizeValue.ofKb(100), TimeValue.timeValueDays(3), null)) ) ); projectMetadata = projectBuilder.build(); @@ -138,7 +138,7 @@ public void testMaybeSampleWithCondition() { new SamplingMetadata( Map.of( indexName, - new SamplingConfiguration(1.0, 100, ByteSizeValue.ofMb(100), TimeValue.timeValueDays(3), TEST_CONDITIONAL_SCRIPT) + new SamplingConfiguration(1.0, 100, ByteSizeValue.ofMb(5), TimeValue.timeValueDays(3), TEST_CONDITIONAL_SCRIPT) ) ) ); @@ -183,7 +183,7 @@ public void testMaybeSampleWithLowRate() { .putCustom( SamplingMetadata.TYPE, new SamplingMetadata( - Map.of(indexName, new SamplingConfiguration(0.001, 100, ByteSizeValue.ofMb(100), TimeValue.timeValueDays(3), null)) + Map.of(indexName, new SamplingConfiguration(0.001, 100, ByteSizeValue.ofMb(5), TimeValue.timeValueDays(3), null)) ) ); final ProjectId projectId = projectBuilder.getId(); @@ -223,7 +223,7 @@ public void testMaybeSampleMaxSamples() { .putCustom( SamplingMetadata.TYPE, new SamplingMetadata( - Map.of(indexName, new SamplingConfiguration(1.0, maxSamples, ByteSizeValue.ofMb(100), TimeValue.timeValueDays(3), null)) + Map.of(indexName, new SamplingConfiguration(1.0, maxSamples, ByteSizeValue.ofMb(5), TimeValue.timeValueDays(3), null)) ) ); final ProjectId projectId = projectBuilder.getId(); diff --git a/server/src/test/java/org/elasticsearch/ingest/UpdateSamplingConfigurationExecutorTests.java b/server/src/test/java/org/elasticsearch/ingest/UpdateSamplingConfigurationExecutorTests.java index 68401dd54eb96..470cf24b41de3 100644 --- a/server/src/test/java/org/elasticsearch/ingest/UpdateSamplingConfigurationExecutorTests.java +++ b/server/src/test/java/org/elasticsearch/ingest/UpdateSamplingConfigurationExecutorTests.java @@ -83,7 +83,7 @@ public void testExecuteTaskWithUpperBoundLimit() { SamplingConfiguration defaultConfig = new SamplingConfiguration( 0.5d, 50, - ByteSizeValue.ofMb(10), + ByteSizeValue.ofKb(100), TimeValue.timeValueHours(1), null ); @@ -106,7 +106,7 @@ public void testExecuteTaskWithUpperBoundLimit() { // Try to add the 101st configuration - this should fail String newIndexName = "new-index-101"; - SamplingConfiguration newConfig = new SamplingConfiguration(0.8d, 80, ByteSizeValue.ofMb(20), TimeValue.timeValueHours(2), null); + SamplingConfiguration newConfig = new SamplingConfiguration(0.8d, 80, ByteSizeValue.ofKb(100), TimeValue.timeValueHours(2), null); SamplingService.UpdateSamplingConfigurationTask task = new SamplingService.UpdateSamplingConfigurationTask( ProjectId.DEFAULT,