Skip to content

Commit 200750a

Browse files
authored
Merge branch 'main' into failure-store-sql-support
2 parents 10251b8 + 7dfede2 commit 200750a

File tree

47 files changed

+596
-606
lines changed

Some content is hidden

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

47 files changed

+596
-606
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/MrjarPlugin.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,19 @@ public void apply(Project project) {
7272
var javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
7373
var isIdeaSync = System.getProperty("idea.sync.active", "false").equals("true");
7474
var ideaSourceSetsEnabled = project.hasProperty(MRJAR_IDEA_ENABLED) && project.property(MRJAR_IDEA_ENABLED).equals("true");
75+
int minJavaVersion = Integer.parseInt(buildParams.getMinimumCompilerVersion().getMajorVersion());
7576

7677
// Ignore version-specific source sets if we are importing into IntelliJ and have not explicitly enabled this.
7778
// Avoids an IntelliJ bug:
7879
// https://youtrack.jetbrains.com/issue/IDEA-285640/Compiler-Options-Settings-language-level-is-set-incorrectly-with-JDK-19ea
7980
if (isIdeaSync == false || ideaSourceSetsEnabled) {
80-
List<Integer> mainVersions = findSourceVersions(project);
81+
List<Integer> mainVersions = findSourceVersions(project, minJavaVersion);
8182
List<String> mainSourceSets = new ArrayList<>();
8283
mainSourceSets.add(SourceSet.MAIN_SOURCE_SET_NAME);
83-
configurePreviewFeatures(project, javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME), 21);
84+
configurePreviewFeatures(project, javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME), minJavaVersion);
8485
List<String> testSourceSets = new ArrayList<>(mainSourceSets);
8586
testSourceSets.add(SourceSet.TEST_SOURCE_SET_NAME);
86-
configurePreviewFeatures(project, javaExtension.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME), 21);
87+
configurePreviewFeatures(project, javaExtension.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME), minJavaVersion);
8788
for (int javaVersion : mainVersions) {
8889
String mainSourceSetName = SourceSet.MAIN_SOURCE_SET_NAME + javaVersion;
8990
SourceSet mainSourceSet = addSourceSet(project, javaExtension, mainSourceSetName, mainSourceSets, javaVersion, true);
@@ -103,6 +104,7 @@ public void apply(Project project) {
103104
}
104105

105106
private void configureMrjar(Project project) {
107+
106108
var jarTask = project.getTasks().withType(Jar.class).named(JavaPlugin.JAR_TASK_NAME);
107109
jarTask.configure(task -> { task.manifest(manifest -> { manifest.attributes(Map.of("Multi-Release", "true")); }); });
108110

@@ -222,7 +224,7 @@ private void createTestTask(
222224
project.getTasks().named("check").configure(checkTask -> checkTask.dependsOn(testTaskProvider));
223225
}
224226

225-
private static List<Integer> findSourceVersions(Project project) {
227+
private static List<Integer> findSourceVersions(Project project, int minJavaVersion) {
226228
var srcDir = project.getProjectDir().toPath().resolve("src");
227229
List<Integer> versions = new ArrayList<>();
228230
try (var subdirStream = Files.list(srcDir)) {
@@ -231,7 +233,23 @@ private static List<Integer> findSourceVersions(Project project) {
231233
String sourcesetName = sourceSetPath.getFileName().toString();
232234
Matcher sourcesetMatcher = MRJAR_SOURCESET_PATTERN.matcher(sourcesetName);
233235
if (sourcesetMatcher.matches()) {
234-
versions.add(Integer.parseInt(sourcesetMatcher.group(1)));
236+
int version = Integer.parseInt(sourcesetMatcher.group(1));
237+
if (version < minJavaVersion) {
238+
// NOTE: We allow mainNN for the min java version so that incubating modules can be used without warnings.
239+
// It is a workaround for https://bugs.openjdk.org/browse/JDK-8187591. Once min java is 22, we
240+
// can use the SuppressWarnings("preview") in the code using incubating modules and this check
241+
// can change to <=
242+
throw new IllegalArgumentException(
243+
"Found src dir '"
244+
+ sourcesetName
245+
+ "' for Java "
246+
+ version
247+
+ " but multi-release jar sourceset should have version "
248+
+ minJavaVersion
249+
+ " or greater"
250+
);
251+
}
252+
versions.add(version);
235253
}
236254
}
237255
} catch (IOException e) {

docs/changelog/120487.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 120487
2+
summary: Fix cat_component_templates documentation
3+
area: CAT APIs
4+
type: bug
5+
issues: []

docs/reference/indices/index-templates.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ template with the highest priority is used.
4040
following index patterns:
4141
4242
// tag::built-in-index-template-patterns[]
43+
- `.kibana-reporting*`
4344
- `logs-*-*`
4445
- `metrics-*-*`
4546
- `synthetics-*-*`

docs/reference/indices/put-component-template.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Name of the component template to create.
9797
{es} includes the following built-in component templates:
9898
9999
// tag::built-in-component-templates[]
100+
- `kibana-reporting@settings`
100101
- `logs@mappings`
101102
- `logs@settings`
102103
- `metrics@mappings`

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/VersionSpecificNetworkChecks.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,51 @@
1414
import java.net.http.HttpClient;
1515
import java.net.http.HttpRequest;
1616
import java.net.http.HttpResponse;
17+
import java.net.spi.InetAddressResolver;
18+
import java.net.spi.InetAddressResolverProvider;
1719

1820
class VersionSpecificNetworkChecks {
19-
static void createInetAddressResolverProvider() {}
21+
static void createInetAddressResolverProvider() {
22+
var x = new InetAddressResolverProvider() {
23+
@Override
24+
public InetAddressResolver get(Configuration configuration) {
25+
return null;
26+
}
27+
28+
@Override
29+
public String name() {
30+
return "TEST";
31+
}
32+
};
33+
}
2034

2135
static void httpClientSend() throws InterruptedException {
22-
HttpClient httpClient = HttpClient.newBuilder().build();
23-
try {
24-
httpClient.send(HttpRequest.newBuilder(URI.create("http://localhost")).build(), HttpResponse.BodyHandlers.discarding());
25-
} catch (IOException e) {
26-
// Expected, the send action may fail with these parameters (but after it run the entitlement check in the prologue)
36+
try (HttpClient httpClient = HttpClient.newBuilder().build()) {
37+
// Shutdown the client, so the send action will shortcut before actually executing any network operation
38+
// (but after it run our check in the prologue)
39+
httpClient.shutdown();
40+
try {
41+
httpClient.send(HttpRequest.newBuilder(URI.create("http://localhost")).build(), HttpResponse.BodyHandlers.discarding());
42+
} catch (IOException e) {
43+
// Expected, since we shut down the client
44+
}
2745
}
2846
}
2947

3048
static void httpClientSendAsync() {
31-
HttpClient httpClient = HttpClient.newBuilder().build();
32-
httpClient.sendAsync(HttpRequest.newBuilder(URI.create("http://localhost")).build(), HttpResponse.BodyHandlers.discarding());
49+
try (HttpClient httpClient = HttpClient.newBuilder().build()) {
50+
// Shutdown the client, so the send action will return before actually executing any network operation
51+
// (but after it run our check in the prologue)
52+
httpClient.shutdown();
53+
var future = httpClient.sendAsync(
54+
HttpRequest.newBuilder(URI.create("http://localhost")).build(),
55+
HttpResponse.BodyHandlers.discarding()
56+
);
57+
assert future.isCompletedExceptionally();
58+
future.exceptionally(ex -> {
59+
assert ex instanceof IOException;
60+
return null;
61+
});
62+
}
3363
}
3464
}

libs/entitlement/qa/entitlement-test-plugin/src/main18/java/org/elasticsearch/entitlement/qa/test/VersionSpecificNetworkChecks.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

libs/entitlement/qa/entitlement-test-plugin/src/main21/java/org/elasticsearch/entitlement/qa/test/VersionSpecificNetworkChecks.java

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.entitlement.qa;
11+
12+
import org.elasticsearch.client.Request;
13+
import org.elasticsearch.client.Response;
14+
import org.elasticsearch.test.rest.ESRestTestCase;
15+
16+
import java.io.IOException;
17+
import java.util.List;
18+
import java.util.Map;
19+
20+
import static org.hamcrest.Matchers.containsString;
21+
import static org.hamcrest.Matchers.equalTo;
22+
23+
public abstract class AbstractEntitlementsIT extends ESRestTestCase {
24+
25+
static final EntitlementsTestRule.PolicyBuilder ALLOWED_TEST_ENTITLEMENTS = (builder, tempDir) -> {
26+
builder.value("create_class_loader");
27+
builder.value("set_https_connection_properties");
28+
builder.value("inbound_network");
29+
builder.value("outbound_network");
30+
builder.value("load_native_libraries");
31+
builder.value(
32+
Map.of(
33+
"write_system_properties",
34+
Map.of("properties", List.of("es.entitlements.checkSetSystemProperty", "es.entitlements.checkClearSystemProperty"))
35+
)
36+
);
37+
};
38+
39+
private final String actionName;
40+
private final boolean expectAllowed;
41+
42+
AbstractEntitlementsIT(String actionName, boolean expectAllowed) {
43+
this.actionName = actionName;
44+
this.expectAllowed = expectAllowed;
45+
}
46+
47+
private Response executeCheck() throws IOException {
48+
var request = new Request("GET", "/_entitlement_check");
49+
request.addParameter("action", actionName);
50+
return client().performRequest(request);
51+
}
52+
53+
public void testAction() throws IOException {
54+
logger.info("Executing Entitlement test for [{}]", actionName);
55+
if (expectAllowed) {
56+
Response result = executeCheck();
57+
assertThat(result.getStatusLine().getStatusCode(), equalTo(200));
58+
} else {
59+
var exception = expectThrows(IOException.class, this::executeCheck);
60+
assertThat(exception.getMessage(), containsString("not_entitled_exception"));
61+
}
62+
}
63+
}

libs/entitlement/qa/src/javaRestTest/java/org/elasticsearch/entitlement/qa/EntitlementsAllowedIT.java

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,16 @@
1212
import com.carrotsearch.randomizedtesting.annotations.Name;
1313
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1414

15-
import org.elasticsearch.client.Request;
16-
import org.elasticsearch.client.Response;
1715
import org.elasticsearch.entitlement.qa.test.RestEntitlementsCheckAction;
18-
import org.elasticsearch.test.cluster.ElasticsearchCluster;
19-
import org.elasticsearch.test.rest.ESRestTestCase;
2016
import org.junit.ClassRule;
2117

22-
import java.io.IOException;
23-
24-
import static org.elasticsearch.entitlement.qa.EntitlementsUtil.ALLOWED_ENTITLEMENTS;
25-
import static org.hamcrest.Matchers.equalTo;
26-
27-
public class EntitlementsAllowedIT extends ESRestTestCase {
18+
public class EntitlementsAllowedIT extends AbstractEntitlementsIT {
2819

2920
@ClassRule
30-
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
31-
.module("entitlement-test-plugin", spec -> EntitlementsUtil.setupEntitlements(spec, true, ALLOWED_ENTITLEMENTS))
32-
.systemProperty("es.entitlements.enabled", "true")
33-
.setting("xpack.security.enabled", "false")
34-
.build();
35-
36-
private final String actionName;
21+
public static EntitlementsTestRule testRule = new EntitlementsTestRule(true, ALLOWED_TEST_ENTITLEMENTS);
3722

3823
public EntitlementsAllowedIT(@Name("actionName") String actionName) {
39-
this.actionName = actionName;
24+
super(actionName, true);
4025
}
4126

4227
@ParametersFactory
@@ -46,14 +31,6 @@ public static Iterable<Object[]> data() {
4631

4732
@Override
4833
protected String getTestRestCluster() {
49-
return cluster.getHttpAddresses();
50-
}
51-
52-
public void testCheckActionWithPolicyPass() throws IOException {
53-
logger.info("Executing Entitlement test for [{}]", actionName);
54-
var request = new Request("GET", "/_entitlement_check");
55-
request.addParameter("action", actionName);
56-
Response result = client().performRequest(request);
57-
assertThat(result.getStatusLine().getStatusCode(), equalTo(200));
34+
return testRule.cluster.getHttpAddresses();
5835
}
5936
}

0 commit comments

Comments
 (0)