Skip to content

Commit 1004196

Browse files
authored
Avoid running SamplingServiceTests if sampling feature flag is missing (#135858)
The SamplingServiceTests fail when running in non-snapshot mode. This is because we do not do any sampling if the sampling feature flag is not enabled. This adds an assumption to all of those tests that the feature flag is enabled. It also fixes a potential NullPointerException that happens if you attempt to get the sampling service stats with the sampling feature flag disabled. Closes #135808 Closes #135809 Closes #135810 Closes #135811
1 parent f75fb72 commit 1004196

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

muted-tests.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,18 +609,6 @@ tests:
609609
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT
610610
method: test
611611
issue: https://github.com/elastic/elasticsearch/issues/135787
612-
- class: org.elasticsearch.ingest.SamplingServiceTests
613-
method: testMaybeSampleWithLowRate
614-
issue: https://github.com/elastic/elasticsearch/issues/135808
615-
- class: org.elasticsearch.ingest.SamplingServiceTests
616-
method: testMaybeSample
617-
issue: https://github.com/elastic/elasticsearch/issues/135809
618-
- class: org.elasticsearch.ingest.SamplingServiceTests
619-
method: testMaybeSampleWithCondition
620-
issue: https://github.com/elastic/elasticsearch/issues/135810
621-
- class: org.elasticsearch.ingest.SamplingServiceTests
622-
method: testMaybeSampleMaxSamples
623-
issue: https://github.com/elastic/elasticsearch/issues/135811
624612
- class: org.elasticsearch.xpack.esql.expression.function.aggregate.IrateTests
625613
method: testGroupingAggregate {TestCase=<positive ints>}
626614
issue: https://github.com/elastic/elasticsearch/issues/135814

server/src/main/java/org/elasticsearch/ingest/SamplingService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ public List<RawDocument> getLocalSample(ProjectId projectId, String index) {
232232
*/
233233
public SampleStats getLocalSampleStats(ProjectId projectId, String index) {
234234
SoftReference<SampleInfo> sampleInfoReference = samples.get(new ProjectIndex(projectId, index));
235+
if (sampleInfoReference == null) {
236+
return new SampleStats();
237+
}
235238
SampleInfo sampleInfo = sampleInfoReference.get();
236239
return sampleInfo == null ? new SampleStats() : sampleInfo.stats;
237240
}

server/src/test/java/org/elasticsearch/ingest/SamplingServiceTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@
3434
import java.util.List;
3535
import java.util.Map;
3636

37+
import static org.elasticsearch.ingest.SamplingService.RANDOM_SAMPLING_FEATURE_FLAG;
3738
import static org.hamcrest.Matchers.empty;
3839
import static org.hamcrest.Matchers.equalTo;
3940
import static org.hamcrest.Matchers.greaterThan;
4041
import static org.hamcrest.Matchers.lessThan;
4142
import static org.hamcrest.Matchers.not;
4243
import static org.hamcrest.Matchers.nullValue;
44+
import static org.junit.Assume.assumeTrue;
4345

4446
public class SamplingServiceTests extends ESTestCase {
4547

4648
private static final String TEST_CONDITIONAL_SCRIPT = "ctx?.foo == 'bar'";
4749

4850
public void testMaybeSample() {
51+
assumeTrue("Requires sampling feature flag", RANDOM_SAMPLING_FEATURE_FLAG);
4952
SamplingService samplingService = getTestSamplingService();
5053

5154
// First, test with a project that has no sampling config:
@@ -101,6 +104,7 @@ public void testMaybeSample() {
101104
}
102105

103106
public void testMaybeSampleWithCondition() {
107+
assumeTrue("Requires sampling feature flag", RANDOM_SAMPLING_FEATURE_FLAG);
104108
SamplingService samplingService = getTestSamplingService();
105109
String indexName = randomIdentifier();
106110
ProjectMetadata.Builder projectBuilder = ProjectMetadata.builder(ProjectId.DEFAULT)
@@ -147,6 +151,7 @@ public void testMaybeSampleWithCondition() {
147151
}
148152

149153
public void testMaybeSampleWithLowRate() {
154+
assumeTrue("Requires sampling feature flag", RANDOM_SAMPLING_FEATURE_FLAG);
150155
SamplingService samplingService = getTestSamplingService();
151156
String indexName = randomIdentifier();
152157
ProjectMetadata.Builder projectBuilder = ProjectMetadata.builder(ProjectId.DEFAULT)
@@ -185,6 +190,7 @@ public void testMaybeSampleWithLowRate() {
185190
}
186191

187192
public void testMaybeSampleMaxSamples() {
193+
assumeTrue("Requires sampling feature flag", RANDOM_SAMPLING_FEATURE_FLAG);
188194
SamplingService samplingService = getTestSamplingService();
189195
String indexName = randomIdentifier();
190196
int maxSamples = randomIntBetween(1, 1000);

0 commit comments

Comments
 (0)