Skip to content

Commit fdac8bf

Browse files
authored
Merge branch 'main' into bump-netty-version
2 parents 6cdd432 + af6014e commit fdac8bf

File tree

11 files changed

+92
-13
lines changed

11 files changed

+92
-13
lines changed

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/SystemJvmOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class SystemJvmOptions {
2828
static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, String> sysprops) {
2929
String distroType = sysprops.get("es.distribution.type");
3030
boolean isHotspot = sysprops.getOrDefault("sun.management.compiler", "").contains("HotSpot");
31-
boolean entitlementsExplicitlyEnabled = Booleans.parseBoolean(sysprops.getOrDefault("es.entitlements.enabled", "false"));
31+
boolean entitlementsExplicitlyEnabled = Booleans.parseBoolean(sysprops.getOrDefault("es.entitlements.enabled", "true"));
3232
// java 24+ only supports entitlements, but it may be enabled on earlier versions explicitly
3333
boolean useEntitlements = RuntimeVersionFeature.isSecurityManagerAvailable() == false || entitlementsExplicitlyEnabled;
3434
return Stream.of(

docs/changelog/123384.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123384
2+
summary: Fixing serialization of `ScriptStats` `cache_evictions_history`
3+
area: Stats
4+
type: bug
5+
issues: []

docs/changelog/123403.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123403
2+
summary: Use ordered maps for `PipelineConfiguration` xcontent deserialization
3+
area: Ingest Node
4+
type: bug
5+
issues: []

libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ private static PolicyManager createPolicyManager() {
178178
if (bootstrapArgs.pidFile() != null) {
179179
serverModuleFileDatas.add(FileData.ofPath(bootstrapArgs.pidFile(), READ_WRITE));
180180
}
181+
181182
Collections.addAll(
182183
serverScopes,
183184
new Scope(
@@ -186,6 +187,7 @@ private static PolicyManager createPolicyManager() {
186187
new CreateClassLoaderEntitlement(),
187188
new FilesEntitlement(
188189
List.of(
190+
// TODO: what in es.base is accessing shared repo?
189191
FileData.ofRelativePath(Path.of(""), SHARED_REPO, READ_WRITE),
190192
FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE)
191193
)

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ private static Bootstrap initPhase1() {
120120
final PrintStream out = getStdout();
121121
final PrintStream err = getStderr();
122122
final ServerArgs args;
123-
final boolean entitlementsExplicitlyEnabled = Booleans.parseBoolean(System.getProperty("es.entitlements.enabled", "false"));
123+
final boolean entitlementsEnabled = Booleans.parseBoolean(System.getProperty("es.entitlements.enabled", "true"));
124124
// java 24+ only supports entitlements, but it may be enabled on earlier versions explicitly
125-
final boolean useEntitlements = RuntimeVersionFeature.isSecurityManagerAvailable() == false || entitlementsExplicitlyEnabled;
125+
final boolean useEntitlements = RuntimeVersionFeature.isSecurityManagerAvailable() == false || entitlementsEnabled;
126126
try {
127127
initSecurityProperties();
128128

server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplate.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.elasticsearch.common.io.stream.StreamOutput;
2020
import org.elasticsearch.common.io.stream.Writeable;
2121
import org.elasticsearch.core.Nullable;
22-
import org.elasticsearch.core.UpdateForV9;
2322
import org.elasticsearch.index.mapper.DataStreamTimestampFieldMapper;
2423
import org.elasticsearch.index.mapper.MapperService;
2524
import org.elasticsearch.xcontent.ConstructingObjectParser;
@@ -373,8 +372,6 @@ public static class DataStreamTemplate implements Writeable, ToXContentObject {
373372

374373
private static final ParseField HIDDEN = new ParseField("hidden");
375374
private static final ParseField ALLOW_CUSTOM_ROUTING = new ParseField("allow_custom_routing");
376-
// Remove this after this PR gets backported
377-
@UpdateForV9(owner = UpdateForV9.Owner.DATA_MANAGEMENT)
378375
private static final ParseField FAILURE_STORE = new ParseField("failure_store");
379376

380377
public static final ConstructingObjectParser<DataStreamTemplate, Void> PARSER = new ConstructingObjectParser<>(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final class PipelineConfiguration implements SimpleDiffable<PipelineConfi
4646
static {
4747
PARSER.declareString(Builder::setId, new ParseField("id"));
4848
PARSER.declareField(
49-
(parser, builder, aVoid) -> builder.setConfig(parser.map()),
49+
(parser, builder, aVoid) -> builder.setConfig(parser.mapOrdered()),
5050
new ParseField("config"),
5151
ObjectParser.ValueType.OBJECT
5252
);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Objects;
2929

3030
import static org.elasticsearch.common.collect.Iterators.single;
31+
import static org.elasticsearch.script.ScriptContextStats.Fields.CACHE_EVICTIONS_HISTORY;
3132
import static org.elasticsearch.script.ScriptContextStats.Fields.COMPILATIONS_HISTORY;
3233
import static org.elasticsearch.script.ScriptStats.Fields.CACHE_EVICTIONS;
3334
import static org.elasticsearch.script.ScriptStats.Fields.COMPILATIONS;
@@ -205,7 +206,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
205206
builder.endObject();
206207
}
207208
if (cacheEvictionsHistory != null && cacheEvictionsHistory.areTimingsEmpty() == false) {
208-
builder.startObject(COMPILATIONS_HISTORY);
209+
builder.startObject(CACHE_EVICTIONS_HISTORY);
209210
cacheEvictionsHistory.toXContent(builder, params);
210211
builder.endObject();
211212
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
import java.nio.charset.StandardCharsets;
2929
import java.util.HashMap;
3030
import java.util.Map;
31+
import java.util.Set;
3132
import java.util.function.Predicate;
3233

3334
import static org.hamcrest.Matchers.anEmptyMap;
35+
import static org.hamcrest.Matchers.contains;
3436
import static org.hamcrest.Matchers.equalTo;
3537
import static org.hamcrest.Matchers.not;
3638
import static org.hamcrest.Matchers.sameInstance;
@@ -143,6 +145,41 @@ public void testGetVersion() {
143145
}
144146
}
145147

148+
@SuppressWarnings("unchecked")
149+
public void testMapKeyOrderingRoundTrip() throws IOException {
150+
// make up two random keys
151+
String key1 = randomAlphaOfLength(10);
152+
String key2 = randomValueOtherThan(key1, () -> randomAlphaOfLength(10));
153+
// stick them as mappings onto themselves in the _meta of a pipeline configuration
154+
// this happens to use the _meta as a convenient map to test that the ordering of the key sets is the same
155+
String configJson = Strings.format("""
156+
{"description": "blah", "_meta" : {"foo": "bar", "%s": "%s", "%s": "%s"}}""", key1, key1, key2, key2);
157+
PipelineConfiguration configuration = new PipelineConfiguration(
158+
"1",
159+
new BytesArray(configJson.getBytes(StandardCharsets.UTF_8)),
160+
XContentType.JSON
161+
);
162+
163+
// serialize it to bytes
164+
XContentType xContentType = randomFrom(XContentType.values());
165+
final BytesReference bytes;
166+
try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
167+
configuration.toXContent(builder, ToXContent.EMPTY_PARAMS);
168+
bytes = BytesReference.bytes(builder);
169+
}
170+
171+
// deserialize it back
172+
ContextParser<Void, PipelineConfiguration> parser = PipelineConfiguration.getParser();
173+
XContentParser xContentParser = xContentType.xContent()
174+
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput());
175+
PipelineConfiguration parsed = parser.parse(xContentParser, null);
176+
177+
// make sure the _meta key sets are in the same order
178+
Set<String> keys1 = ((Map<String, Object>) configuration.getConfig().get("_meta")).keySet();
179+
Set<String> keys2 = ((Map<String, Object>) parsed.getConfig().get("_meta")).keySet();
180+
assertThat(keys1, contains(keys2.toArray(new String[0])));
181+
}
182+
146183
@Override
147184
protected PipelineConfiguration createTestInstance() {
148185
BytesArray config;

server/src/test/java/org/elasticsearch/script/ScriptStatsTests.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,37 @@ public void testXContentChunked() throws IOException {
7878
assertThat(Strings.toString(builder), equalTo(expected));
7979
}
8080

81+
public void testXContentChunkedHistory() throws Exception {
82+
ScriptStats stats = new ScriptStats(5, 6, 7, new TimeSeries(10, 20, 30, 40), new TimeSeries(100, 200, 300, 400));
83+
final XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
84+
85+
builder.startObject();
86+
for (var it = stats.toXContentChunked(ToXContent.EMPTY_PARAMS); it.hasNext();) {
87+
it.next().toXContent(builder, ToXContent.EMPTY_PARAMS);
88+
}
89+
builder.endObject();
90+
String expected = """
91+
{
92+
"script" : {
93+
"compilations" : 5,
94+
"cache_evictions" : 6,
95+
"compilation_limit_triggered" : 7,
96+
"compilations_history" : {
97+
"5m" : 10,
98+
"15m" : 20,
99+
"24h" : 30
100+
},
101+
"cache_evictions_history" : {
102+
"5m" : 100,
103+
"15m" : 200,
104+
"24h" : 300
105+
},
106+
"contexts" : [ ]
107+
}
108+
}""";
109+
assertThat(Strings.toString(builder), equalTo(expected));
110+
}
111+
81112
public void testSerializeEmptyTimeSeries() throws IOException {
82113
ScriptContextStats stats = new ScriptContextStats("c", 3333, new TimeSeries(1111), new TimeSeries(2222));
83114

0 commit comments

Comments
 (0)