Skip to content

Commit 328a7a5

Browse files
authored
Removing unused projectId from random sampling RawDocument (#135864)
1 parent 1521291 commit 328a7a5

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ && evaluateCondition(ingestDocumentSupplier, sampleInfo.script, sampleInfo.facto
191191
stats.samplesRejectedForCondition.increment();
192192
return;
193193
}
194-
RawDocument sample = getRawDocumentForIndexRequest(projectId, indexName, indexRequest);
194+
RawDocument sample = getRawDocumentForIndexRequest(indexName, indexRequest);
195195
if (sampleInfo.offer(sample)) {
196196
stats.samples.increment();
197197
logger.trace("Sampling " + indexRequest);
@@ -287,15 +287,14 @@ private static Script getScript(String conditional) throws IOException {
287287
* This represents a raw document as the user sent it to us in an IndexRequest. It only holds onto the information needed for the
288288
* sampling API, rather than holding all of the fields a user might send in an IndexRequest.
289289
*/
290-
public record RawDocument(ProjectId projectId, String indexName, byte[] source, XContentType contentType) implements Writeable {
290+
public record RawDocument(String indexName, byte[] source, XContentType contentType) implements Writeable {
291291

292292
public RawDocument(StreamInput in) throws IOException {
293-
this(ProjectId.readFrom(in), in.readString(), in.readByteArray(), in.readEnum(XContentType.class));
293+
this(in.readString(), in.readByteArray(), in.readEnum(XContentType.class));
294294
}
295295

296296
@Override
297297
public void writeTo(StreamOutput out) throws IOException {
298-
projectId.writeTo(out);
299298
out.writeString(indexName);
300299
out.writeByteArray(source);
301300
XContentHelper.writeTo(out, contentType);
@@ -306,15 +305,14 @@ public boolean equals(Object o) {
306305
if (this == o) return true;
307306
if (o == null || getClass() != o.getClass()) return false;
308307
RawDocument rawDocument = (RawDocument) o;
309-
return Objects.equals(projectId, rawDocument.projectId)
310-
&& Objects.equals(indexName, rawDocument.indexName)
308+
return Objects.equals(indexName, rawDocument.indexName)
311309
&& Arrays.equals(source, rawDocument.source)
312310
&& contentType == rawDocument.contentType;
313311
}
314312

315313
@Override
316314
public int hashCode() {
317-
int result = Objects.hash(projectId, indexName, contentType);
315+
int result = Objects.hash(indexName, contentType);
318316
result = 31 * result + Arrays.hashCode(source);
319317
return result;
320318
}
@@ -325,13 +323,13 @@ public int hashCode() {
325323
* RawDocument might be a relatively expensive object memory-wise. Since the bytes are copied, subsequent changes to the indexRequest
326324
* are not reflected in the RawDocument
327325
*/
328-
private RawDocument getRawDocumentForIndexRequest(ProjectId projectId, String indexName, IndexRequest indexRequest) {
326+
private RawDocument getRawDocumentForIndexRequest(String indexName, IndexRequest indexRequest) {
329327
BytesReference sourceReference = indexRequest.source();
330328
assert sourceReference != null : "Cannot sample an IndexRequest with no source";
331329
byte[] source = sourceReference.array();
332330
final byte[] sourceCopy = new byte[sourceReference.length()];
333331
System.arraycopy(source, sourceReference.arrayOffset(), sourceCopy, 0, sourceReference.length());
334-
return new RawDocument(projectId, indexName, sourceCopy, indexRequest.getContentType());
332+
return new RawDocument(indexName, sourceCopy, indexRequest.getContentType());
335333
}
336334

337335
public static final class SampleStats implements Writeable, ToXContent {

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package org.elasticsearch.ingest;
1111

12-
import org.elasticsearch.cluster.metadata.ProjectId;
1312
import org.elasticsearch.common.io.stream.Writeable;
1413
import org.elasticsearch.ingest.SamplingService.RawDocument;
1514
import org.elasticsearch.test.AbstractWireSerializingTestCase;
@@ -26,28 +25,21 @@ protected Writeable.Reader<RawDocument> instanceReader() {
2625

2726
@Override
2827
protected RawDocument createTestInstance() {
29-
return new RawDocument(
30-
randomProjectIdOrDefault(),
31-
randomIdentifier(),
32-
randomByteArrayOfLength(randomIntBetween(10, 1000)),
33-
randomFrom(XContentType.values())
34-
);
28+
return new RawDocument(randomIdentifier(), randomByteArrayOfLength(randomIntBetween(10, 1000)), randomFrom(XContentType.values()));
3529
}
3630

3731
@Override
3832
protected RawDocument mutateInstance(RawDocument instance) throws IOException {
39-
ProjectId projectId = instance.projectId();
4033
String indexName = instance.indexName();
4134
byte[] source = instance.source();
4235
XContentType xContentType = instance.contentType();
4336

44-
switch (between(0, 3)) {
45-
case 0 -> projectId = randomValueOtherThan(projectId, ESTestCase::randomProjectIdOrDefault);
46-
case 1 -> indexName = randomValueOtherThan(indexName, ESTestCase::randomIdentifier);
47-
case 2 -> source = randomByteArrayOfLength(randomIntBetween(100, 1000));
48-
case 3 -> xContentType = randomValueOtherThan(xContentType, () -> randomFrom(XContentType.values()));
37+
switch (between(0, 2)) {
38+
case 0 -> indexName = randomValueOtherThan(indexName, ESTestCase::randomIdentifier);
39+
case 1 -> source = randomByteArrayOfLength(randomIntBetween(100, 1000));
40+
case 2 -> xContentType = randomValueOtherThan(xContentType, () -> randomFrom(XContentType.values()));
4941
default -> throw new IllegalArgumentException("Should never get here");
5042
}
51-
return new RawDocument(projectId, indexName, source, xContentType);
43+
return new RawDocument(indexName, source, xContentType);
5244
}
5345
}

0 commit comments

Comments
 (0)