Skip to content

Commit 80d6bd4

Browse files
authored
Merge branch 'main' into ps250227-capDeletionSuppressedErrors
2 parents 9b3dac4 + 36660f2 commit 80d6bd4

File tree

65 files changed

+243
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+243
-161
lines changed

docs/changelog/122933.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122933
2+
summary: Run XPack usage actions on local node
3+
area: Stats
4+
type: enhancement
5+
issues: []

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyManagerTests.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.entitlement.runtime.policy;
1111

1212
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.core.Strings;
1314
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.ModuleEntitlements;
1415
import org.elasticsearch.entitlement.runtime.policy.agent.TestAgent;
1516
import org.elasticsearch.entitlement.runtime.policy.agent.inner.TestInnerAgent;
@@ -411,6 +412,9 @@ public void testDuplicateEntitlements() {
411412
}
412413

413414
public void testFilesEntitlementsWithExclusive() {
415+
var baseTestPath = Path.of("/tmp").toAbsolutePath();
416+
var testPath1 = Path.of("/tmp/test").toAbsolutePath();
417+
var testPath2 = Path.of("/tmp/test/foo").toAbsolutePath();
414418
var iae = expectThrows(
415419
IllegalArgumentException.class,
416420
() -> new PolicyManager(
@@ -425,10 +429,7 @@ public void testFilesEntitlementsWithExclusive() {
425429
"test",
426430
List.of(
427431
new FilesEntitlement(
428-
List.of(
429-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/test"), FilesEntitlement.Mode.READ)
430-
.withExclusive(true)
431-
)
432+
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
432433
)
433434
)
434435
)
@@ -442,10 +443,7 @@ public void testFilesEntitlementsWithExclusive() {
442443
"test",
443444
List.of(
444445
new FilesEntitlement(
445-
List.of(
446-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/test"), FilesEntitlement.Mode.READ)
447-
.withExclusive(true)
448-
)
446+
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
449447
)
450448
)
451449
)
@@ -460,7 +458,7 @@ public void testFilesEntitlementsWithExclusive() {
460458
)
461459
);
462460
assertTrue(iae.getMessage().contains("duplicate/overlapping exclusive paths found in files entitlements:"));
463-
assertTrue(iae.getMessage().contains("[test] [/tmp/test]]"));
461+
assertTrue(iae.getMessage().contains(Strings.format("[test] [%s]]", testPath1.toString())));
464462

465463
iae = expectThrows(
466464
IllegalArgumentException.class,
@@ -473,9 +471,8 @@ public void testFilesEntitlementsWithExclusive() {
473471
List.of(
474472
new FilesEntitlement(
475473
List.of(
476-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/test/foo"), FilesEntitlement.Mode.READ)
477-
.withExclusive(true),
478-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/"), FilesEntitlement.Mode.READ)
474+
FilesEntitlement.FileData.ofPath(testPath2, FilesEntitlement.Mode.READ).withExclusive(true),
475+
FilesEntitlement.FileData.ofPath(baseTestPath, FilesEntitlement.Mode.READ)
479476
)
480477
)
481478
)
@@ -492,10 +489,7 @@ public void testFilesEntitlementsWithExclusive() {
492489
"test",
493490
List.of(
494491
new FilesEntitlement(
495-
List.of(
496-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/test"), FilesEntitlement.Mode.READ)
497-
.withExclusive(true)
498-
)
492+
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
499493
)
500494
)
501495
)
@@ -510,8 +504,12 @@ public void testFilesEntitlementsWithExclusive() {
510504
)
511505
);
512506
assertEquals(
513-
"duplicate/overlapping exclusive paths found in files entitlements: "
514-
+ "[[plugin1] [test] [/tmp/test]] and [[(server)] [test] [/tmp/test/foo]]",
507+
Strings.format(
508+
"duplicate/overlapping exclusive paths found in files entitlements: "
509+
+ "[[plugin1] [test] [%s]] and [[(server)] [test] [%s]]",
510+
testPath1,
511+
testPath2
512+
),
515513
iae.getMessage()
516514
);
517515
}

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,6 @@ tests:
329329
- class: org.elasticsearch.action.admin.cluster.node.tasks.CancellableTasksIT
330330
method: testChildrenTasksCancelledOnTimeout
331331
issue: https://github.com/elastic/elasticsearch/issues/123568
332-
- class: org.elasticsearch.entitlement.runtime.policy.PolicyManagerTests
333-
method: testFilesEntitlementsWithExclusive
334-
issue: https://github.com/elastic/elasticsearch/issues/123657
335332
- class: org.elasticsearch.test.rest.yaml.RcsCcsCommonYamlTestSuiteIT
336333
method: test {p0=search.vectors/41_knn_search_bbq_hnsw/Test knn search}
337334
issue: https://github.com/elastic/elasticsearch/issues/123727

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static TransportVersion def(int id) {
206206
public static final TransportVersion ESQL_SERIALIZE_SOURCE_FUNCTIONS_WARNINGS = def(9_016_0_00);
207207
public static final TransportVersion ESQL_DRIVER_NODE_DESCRIPTION = def(9_017_0_00);
208208
public static final TransportVersion MULTI_PROJECT = def(9_018_0_00);
209+
public static final TransportVersion STORED_SCRIPT_CONTENT_LENGTH = def(9_019_0_00);
209210

210211
/*
211212
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99

1010
package org.elasticsearch.action.admin.cluster.storedscripts;
1111

12+
import org.elasticsearch.TransportVersions;
1213
import org.elasticsearch.action.ActionRequestValidationException;
1314
import org.elasticsearch.action.support.master.AcknowledgedRequest;
1415
import org.elasticsearch.common.Strings;
16+
import org.elasticsearch.common.bytes.BytesArray;
1517
import org.elasticsearch.common.bytes.BytesReference;
1618
import org.elasticsearch.common.io.stream.StreamInput;
1719
import org.elasticsearch.common.io.stream.StreamOutput;
1820
import org.elasticsearch.common.xcontent.XContentHelper;
1921
import org.elasticsearch.core.Nullable;
2022
import org.elasticsearch.core.TimeValue;
21-
import org.elasticsearch.core.UpdateForV9;
2223
import org.elasticsearch.script.StoredScriptSource;
2324
import org.elasticsearch.xcontent.ToXContentFragment;
2425
import org.elasticsearch.xcontent.XContentBuilder;
@@ -37,27 +38,21 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
3738
@Nullable
3839
private final String context;
3940

40-
/*
41-
* [NOTE: unused fields #117566]
42-
* As of #117566 (8.18) the content and xContentType fields are basically unused, except that we use content().length() for some
43-
* validation. However, in earlier 8.x versions they did at least influence the output of toString(). That means in 9.x we can replace
44-
* these fields with an int representing the original content length once the 9.x transport protocol can diverge from the 8.x one. For
45-
* BwC with 8.18 we can simply send any BytesReference of the appropriate length.
46-
*/
47-
48-
@UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA) // see [NOTE: unused fields #117566]
49-
private final BytesReference content;
50-
51-
@UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA) // see [NOTE: unused fields #117566]
52-
private final XContentType xContentType;
41+
private final int contentLength;
5342

5443
private final StoredScriptSource source;
5544

5645
public PutStoredScriptRequest(StreamInput in) throws IOException {
5746
super(in);
5847
id = in.readOptionalString();
59-
content = in.readBytesReference();
60-
xContentType = in.readEnum(XContentType.class);
48+
if (in.getTransportVersion().onOrAfter(TransportVersions.STORED_SCRIPT_CONTENT_LENGTH)) {
49+
contentLength = in.readVInt();
50+
} else {
51+
BytesReference content = in.readBytesReference();
52+
contentLength = content.length();
53+
54+
in.readEnum(XContentType.class); // and drop
55+
}
6156
context = in.readOptionalString();
6257
source = new StoredScriptSource(in);
6358
}
@@ -67,15 +62,13 @@ public PutStoredScriptRequest(
6762
TimeValue ackTimeout,
6863
@Nullable String id,
6964
@Nullable String context,
70-
BytesReference content,
71-
XContentType xContentType,
65+
int contentLength,
7266
StoredScriptSource source
7367
) {
7468
super(masterNodeTimeout, ackTimeout);
7569
this.id = id;
7670
this.context = context;
77-
this.content = Objects.requireNonNull(content);
78-
this.xContentType = Objects.requireNonNull(xContentType);
71+
this.contentLength = contentLength;
7972
this.source = Objects.requireNonNull(source);
8073
}
8174

@@ -100,12 +93,8 @@ public String context() {
10093
return context;
10194
}
10295

103-
public BytesReference content() {
104-
return content;
105-
}
106-
107-
public XContentType xContentType() {
108-
return xContentType;
96+
public int contentLength() {
97+
return contentLength;
10998
}
11099

111100
public StoredScriptSource source() {
@@ -116,8 +105,13 @@ public StoredScriptSource source() {
116105
public void writeTo(StreamOutput out) throws IOException {
117106
super.writeTo(out);
118107
out.writeOptionalString(id);
119-
out.writeBytesReference(content);
120-
XContentHelper.writeTo(out, xContentType);
108+
if (out.getTransportVersion().onOrAfter(TransportVersions.STORED_SCRIPT_CONTENT_LENGTH)) {
109+
out.writeVInt(contentLength);
110+
} else {
111+
// generate a bytes reference of the correct size (the content isn't actually used in 8.18)
112+
out.writeBytesReference(new BytesArray(new byte[contentLength]));
113+
XContentHelper.writeTo(out, XContentType.JSON); // value not actually used by 8.18
114+
}
121115
out.writeOptionalString(context);
122116
source.writeTo(out);
123117
}

server/src/main/java/org/elasticsearch/action/support/local/TransportLocalClusterStateAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ protected abstract void localClusterStateOperation(Task task, Request request, C
6666

6767
@Override
6868
protected final void doExecute(Task task, Request request, ActionListener<Response> listener) {
69+
if (task != null) {
70+
request.setParentTask(clusterService.localNode().getId(), task.getId());
71+
}
6972
final var state = clusterService.state();
7073
final var clusterBlockException = checkBlock(request, state);
7174
if (clusterBlockException != null) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ void postIngestBytes(long bytesProduced) {
5252
* Creates a serializable representation for these metrics.
5353
*/
5454
IngestStats.ByteStats createByteStats() {
55-
return new IngestStats.ByteStats(this.bytesIngested.count(), this.bytesProduced.count());
55+
long bytesIngested = this.bytesIngested.count();
56+
long bytesProduced = this.bytesProduced.count();
57+
if (bytesIngested == 0L && bytesProduced == 0L) {
58+
return IngestStats.ByteStats.IDENTITY;
59+
}
60+
return new IngestStats.ByteStats(bytesIngested, bytesProduced);
5661
}
5762

5863
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static IngestStats read(StreamInput in) throws IOException {
7474
for (var i = 0; i < size; i++) {
7575
var pipelineId = in.readString();
7676
var pipelineStat = readStats(in);
77-
var byteStat = in.getTransportVersion().onOrAfter(TransportVersions.V_8_15_0) ? new ByteStats(in) : new ByteStats(0, 0);
77+
var byteStat = in.getTransportVersion().onOrAfter(TransportVersions.V_8_15_0) ? readByteStats(in) : ByteStats.IDENTITY;
7878
pipelineStats.add(new PipelineStat(pipelineId, pipelineStat, byteStat));
7979
int processorsSize = in.readVInt();
8080
var processorStatsPerPipeline = new ArrayList<ProcessorStat>(processorsSize);
@@ -287,13 +287,21 @@ private static PipelineStat merge(PipelineStat first, PipelineStat second) {
287287
}
288288
}
289289

290+
static ByteStats readByteStats(StreamInput in) throws IOException {
291+
long bytesIngested = in.readVLong();
292+
long bytesProduced = in.readVLong();
293+
if (bytesProduced == 0L && bytesIngested == 0L) {
294+
return ByteStats.IDENTITY;
295+
}
296+
return new ByteStats(bytesIngested, bytesProduced);
297+
}
298+
290299
/**
291300
* Container for ingested byte stats
292301
*/
293302
public record ByteStats(long bytesIngested, long bytesProduced) implements Writeable, ToXContentFragment {
294-
public ByteStats(StreamInput in) throws IOException {
295-
this(in.readVLong(), in.readVLong());
296-
}
303+
304+
public static final ByteStats IDENTITY = new ByteStats(0L, 0L);
297305

298306
@Override
299307
public void writeTo(StreamOutput out) throws IOException {
@@ -317,6 +325,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
317325
}
318326

319327
static ByteStats merge(ByteStats first, ByteStats second) {
328+
if (first == IDENTITY) {
329+
return second;
330+
} else if (second == IDENTITY) {
331+
return first;
332+
}
320333
return new ByteStats((first.bytesIngested + second.bytesIngested), first.bytesProduced + second.bytesProduced);
321334
}
322335
}

server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
5454
getAckTimeout(request),
5555
request.param("id"),
5656
request.param("context"),
57-
content,
58-
request.getXContentType(),
57+
content.length(),
5958
StoredScriptSource.parse(content, xContentType)
6059
);
6160
return channel -> client.execute(

server/src/main/java/org/elasticsearch/script/ScriptService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,12 @@ public void putStoredScript(
687687
PutStoredScriptRequest request,
688688
ActionListener<AcknowledgedResponse> listener
689689
) {
690-
if (request.content().length() > maxSizeInBytes) {
690+
if (request.contentLength() > maxSizeInBytes) {
691691
throw new IllegalArgumentException(
692692
"exceeded max allowed stored script size in bytes ["
693693
+ maxSizeInBytes
694694
+ "] with size ["
695-
+ request.content().length()
695+
+ request.contentLength()
696696
+ "] for script ["
697697
+ request.id()
698698
+ "]"

0 commit comments

Comments
 (0)