Skip to content

Commit 52249dd

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix-logsdb-settings-provider-mapping-filters
2 parents 36321f6 + f474779 commit 52249dd

File tree

19 files changed

+1061
-69
lines changed

19 files changed

+1061
-69
lines changed

docs/changelog/135966.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 135966
2+
summary: Ensure queued `AbstractRunnables` are notified when executor stops
3+
area: Machine Learning
4+
type: bug
5+
issues:
6+
- 134651
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"indices.get_sample_stats": {
3+
"documentation": {
4+
"url": "https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-sample",
5+
"description": "Get stats about a random sample of ingested data"
6+
},
7+
"stability": "experimental",
8+
"visibility": "public",
9+
"headers": {
10+
"accept": [
11+
"application/json"
12+
]
13+
},
14+
"url": {
15+
"paths": [
16+
{
17+
"path": "/{index}/_sample/stats",
18+
"methods": [
19+
"GET"
20+
],
21+
"parts": {
22+
"index": {
23+
"type": "string",
24+
"description": "The name of a data stream or index"
25+
}
26+
}
27+
}
28+
]
29+
}
30+
}
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
"Test get sample stats for index with no sample config":
3+
- requires:
4+
cluster_features: [ "random_sampling" ]
5+
reason: requires feature 'random_sampling' to get random samples
6+
7+
- do:
8+
indices.get_sample_stats:
9+
index: non_existent
10+
catch: missing
11+
12+
- do:
13+
indices.create:
14+
index: no_config
15+
16+
- do:
17+
indices.get_sample_stats:
18+
index: no_config
19+
catch: missing

server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/sampling/GetSampleActionIT.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1717
import org.elasticsearch.cluster.service.ClusterService;
1818
import org.elasticsearch.common.Priority;
19+
import org.elasticsearch.core.TimeValue;
1920
import org.elasticsearch.ingest.SamplingService;
2021
import org.elasticsearch.test.ESIntegTestCase;
2122

2223
import java.util.List;
2324
import java.util.Map;
2425

2526
import static org.hamcrest.Matchers.equalTo;
27+
import static org.hamcrest.Matchers.greaterThan;
2628

2729
public class GetSampleActionIT extends ESIntegTestCase {
2830

@@ -34,7 +36,8 @@ public void testGetSample() throws Exception {
3436
createIndex(indexName);
3537
// the index exists but there is no sampling configuration for it, so getting its sample will throw an exception:
3638
assertGetSampleThrowsResourceNotFoundException(indexName);
37-
addSamplingConfig(indexName);
39+
final int maxSamples = 30;
40+
addSamplingConfig(indexName, maxSamples);
3841
// There is now a sampling configuration, but no data has been ingested:
3942
assertEmptySample(indexName);
4043
int docsToIndex = randomIntBetween(1, 20);
@@ -49,6 +52,29 @@ public void testGetSample() throws Exception {
4952
for (int i = 0; i < docsToIndex; i++) {
5053
assertRawDocument(sample.get(i), indexName);
5154
}
55+
56+
GetSampleStatsAction.Request statsRequest = new GetSampleStatsAction.Request(indexName);
57+
GetSampleStatsAction.Response statsResponse = client().execute(GetSampleStatsAction.INSTANCE, statsRequest).actionGet();
58+
SamplingService.SampleStats stats = statsResponse.getSampleStats();
59+
assertThat(stats.getSamples(), equalTo((long) docsToIndex));
60+
assertThat(stats.getPotentialSamples(), equalTo((long) docsToIndex));
61+
assertThat(stats.getTimeSampling(), greaterThan(TimeValue.ZERO));
62+
assertThat(stats.getSamplesRejectedForMaxSamplesExceeded(), equalTo(0L));
63+
assertThat(stats.getSamplesRejectedForRate(), equalTo(0L));
64+
assertThat(stats.getSamplesRejectedForCondition(), equalTo(0L));
65+
assertThat(stats.getSamplesRejectedForCondition(), equalTo(0L));
66+
67+
final int samplesOverMax = randomIntBetween(1, 5);
68+
for (int i = docsToIndex; i < maxSamples + samplesOverMax; i++) {
69+
indexDoc(indexName, randomIdentifier(), randomAlphanumericOfLength(10), randomAlphanumericOfLength(10));
70+
}
71+
statsRequest = new GetSampleStatsAction.Request(indexName);
72+
statsResponse = client().execute(GetSampleStatsAction.INSTANCE, statsRequest).actionGet();
73+
stats = statsResponse.getSampleStats();
74+
assertThat(stats.getSamples(), equalTo((long) maxSamples));
75+
assertThat(stats.getPotentialSamples(), equalTo((long) maxSamples + samplesOverMax));
76+
assertThat(stats.getSamplesRejectedForMaxSamplesExceeded(), equalTo((long) samplesOverMax));
77+
5278
}
5379

5480
private void assertRawDocument(SamplingService.RawDocument rawDocument, String indexName) {
@@ -68,7 +94,7 @@ private void assertGetSampleThrowsResourceNotFoundException(String indexName) {
6894
}
6995

7096
@SuppressWarnings("deprecation")
71-
private void addSamplingConfig(String indexName) throws Exception {
97+
private void addSamplingConfig(String indexName, int maxSamples) throws Exception {
7298
/*
7399
* Note: The following code writes a sampling config directly to the cluster state. It can be replaced with a call to the action
74100
* that does this once that action exists.
@@ -81,7 +107,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
81107
currentState.metadata().getProject(ProjectId.DEFAULT)
82108
);
83109
SamplingMetadata samplingMetadata = new SamplingMetadata(
84-
Map.of(indexName, new SamplingConfiguration(1.0d, 100, null, null, null))
110+
Map.of(indexName, new SamplingConfiguration(1.0d, maxSamples, null, null, null))
85111
);
86112
projectMetadataBuilder.putCustom(SamplingMetadata.TYPE, samplingMetadata);
87113
ClusterState newState = new ClusterState.Builder(currentState).putProjectMetadata(projectMetadataBuilder).build();

server/src/main/java/org/elasticsearch/action/ActionModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@
130130
import org.elasticsearch.action.admin.indices.rollover.RolloverAction;
131131
import org.elasticsearch.action.admin.indices.rollover.TransportRolloverAction;
132132
import org.elasticsearch.action.admin.indices.sampling.GetSampleAction;
133+
import org.elasticsearch.action.admin.indices.sampling.GetSampleStatsAction;
133134
import org.elasticsearch.action.admin.indices.sampling.RestGetSampleAction;
135+
import org.elasticsearch.action.admin.indices.sampling.RestGetSampleStatsAction;
134136
import org.elasticsearch.action.admin.indices.sampling.TransportGetSampleAction;
137+
import org.elasticsearch.action.admin.indices.sampling.TransportGetSampleStatsAction;
135138
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction;
136139
import org.elasticsearch.action.admin.indices.segments.TransportIndicesSegmentsAction;
137140
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction;
@@ -821,6 +824,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
821824

822825
if (RANDOM_SAMPLING_FEATURE_FLAG) {
823826
actions.register(GetSampleAction.INSTANCE, TransportGetSampleAction.class);
827+
actions.register(GetSampleStatsAction.INSTANCE, TransportGetSampleStatsAction.class);
824828
}
825829

826830
return unmodifiableMap(actions.getRegistry());
@@ -1053,6 +1057,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster, Predicate<
10531057

10541058
if (RANDOM_SAMPLING_FEATURE_FLAG) {
10551059
registerHandler.accept(new RestGetSampleAction());
1060+
registerHandler.accept(new RestGetSampleStatsAction());
10561061
}
10571062
}
10581063

0 commit comments

Comments
 (0)