Skip to content

Commit 800f136

Browse files
Merge branch 'main' into esql/fix_telemetry_fork
2 parents ede51f2 + 98a6354 commit 800f136

File tree

24 files changed

+324
-125
lines changed

24 files changed

+324
-125
lines changed

docs/changelog/129738.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 129738
2+
summary: Watch SSL files instead of directories
3+
area: TLS
4+
type: bug
5+
issues: []

muted-tests.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,23 +551,18 @@ tests:
551551
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT
552552
method: test
553553
issue: https://github.com/elastic/elasticsearch/issues/129819
554-
- class: org.elasticsearch.index.engine.ThreadPoolMergeExecutorServiceDiskSpaceTests
555-
method: testAbortingOrRunningMergeTaskHoldsUpBudget
556-
issue: https://github.com/elastic/elasticsearch/issues/129823
557554
- class: org.elasticsearch.index.store.FsDirectoryFactoryTests
558555
method: testPreload
559556
issue: https://github.com/elastic/elasticsearch/issues/129852
560557
- class: org.elasticsearch.xpack.rank.rrf.RRFRankClientYamlTestSuiteIT
561558
method: test {yaml=rrf/950_pinned_interaction/rrf with pinned retriever as a sub-retriever}
562559
issue: https://github.com/elastic/elasticsearch/issues/129845
563-
- class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapperTests
564-
method: testExistsQueryMinimalMapping
565-
issue: https://github.com/elastic/elasticsearch/issues/129911
566560
- class: org.elasticsearch.gradle.internal.InternalDistributionBwcSetupPluginFuncTest
567561
method: "builds distribution from branches via archives extractedAssemble [bwcDistVersion: 8.2.1, bwcProject: bugfix, expectedAssembleTaskName:
568562
extractedAssemble, #2]"
569563
issue: https://github.com/elastic/elasticsearch/issues/119871
570564

565+
571566
# Examples:
572567
#
573568
# Mute a single test case in a YAML test suite:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ static TransportVersion def(int id) {
322322
public static final TransportVersion CLUSTER_STATE_PROJECTS_SETTINGS = def(9_108_0_00);
323323
public static final TransportVersion ML_INFERENCE_ELASTIC_DENSE_TEXT_EMBEDDINGS_ADDED = def(9_109_00_0);
324324
public static final TransportVersion ML_INFERENCE_COHERE_API_VERSION = def(9_110_0_00);
325+
public static final TransportVersion ESQL_PROFILE_INCLUDE_PLAN = def(9_111_0_00);
325326

326327
/*
327328
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/watcher/FileWatcher.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public FileWatcher(Path path, boolean checkFileContents) {
5757
rootFileObserver = new FileObserver(path);
5858
}
5959

60+
// For testing
61+
public Path getPath() {
62+
return path;
63+
}
64+
6065
/**
6166
* Clears any state with the FileWatcher, making all files show up as new
6267
*/

server/src/test/java/org/elasticsearch/index/engine/ThreadPoolMergeExecutorServiceDiskSpaceTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public void testAbortingOrRunningMergeTaskHoldsUpBudget() throws Exception {
534534
aFileStore.totalSpace = randomLongBetween(1_000L, 10_000L);
535535
bFileStore.totalSpace = randomLongBetween(1_000L, 10_000L);
536536
aFileStore.usableSpace = randomLongBetween(900L, aFileStore.totalSpace);
537-
bFileStore.usableSpace = randomLongBetween(900L, bFileStore.totalSpace);
537+
bFileStore.usableSpace = randomValueOtherThan(aFileStore.usableSpace, () -> randomLongBetween(900L, bFileStore.totalSpace));
538538
boolean aHasMoreSpace = aFileStore.usableSpace > bFileStore.usableSpace;
539539
try (
540540
ThreadPoolMergeExecutorService threadPoolMergeExecutorService = ThreadPoolMergeExecutorService
@@ -613,7 +613,7 @@ public void testBackloggedMergeTasksDoNotHoldUpBudget() throws Exception {
613613
aFileStore.totalSpace = randomLongBetween(1_000L, 10_000L);
614614
bFileStore.totalSpace = randomLongBetween(1_000L, 10_000L);
615615
aFileStore.usableSpace = randomLongBetween(900L, aFileStore.totalSpace);
616-
bFileStore.usableSpace = randomLongBetween(900L, bFileStore.totalSpace);
616+
bFileStore.usableSpace = randomValueOtherThan(aFileStore.usableSpace, () -> randomLongBetween(900L, bFileStore.totalSpace));
617617
boolean aHasMoreSpace = aFileStore.usableSpace > bFileStore.usableSpace;
618618
try (
619619
ThreadPoolMergeExecutorService threadPoolMergeExecutorService = ThreadPoolMergeExecutorService
@@ -900,7 +900,7 @@ public void testEnqueuedMergeTasksAreUnblockedWhenEstimatedMergeSizeChanges() th
900900
long diskSpaceLimitBytes = randomLongBetween(10L, 100L);
901901
aFileStore.usableSpace = diskSpaceLimitBytes + randomLongBetween(1L, 100L);
902902
aFileStore.totalSpace = aFileStore.usableSpace + randomLongBetween(1L, 10L);
903-
bFileStore.usableSpace = diskSpaceLimitBytes + randomLongBetween(1L, 100L);
903+
bFileStore.usableSpace = randomValueOtherThan(aFileStore.usableSpace, () -> diskSpaceLimitBytes + randomLongBetween(1L, 100L));
904904
bFileStore.totalSpace = bFileStore.usableSpace + randomLongBetween(1L, 10L);
905905
boolean aHasMoreSpace = aFileStore.usableSpace > bFileStore.usableSpace;
906906
Settings.Builder settingsBuilder = Settings.builder().put(settings);
@@ -1001,7 +1001,10 @@ public void testMergeTasksAreUnblockedWhenMoreDiskSpaceBecomesAvailable() throws
10011001
bFileStore.totalSpace = randomLongBetween(300L, 1_000L);
10021002
long grantedUsableSpaceBuffer = randomLongBetween(10L, 50L);
10031003
aFileStore.usableSpace = randomLongBetween(200L, aFileStore.totalSpace - grantedUsableSpaceBuffer);
1004-
bFileStore.usableSpace = randomLongBetween(200L, bFileStore.totalSpace - grantedUsableSpaceBuffer);
1004+
bFileStore.usableSpace = randomValueOtherThan(
1005+
aFileStore.usableSpace,
1006+
() -> randomLongBetween(200L, bFileStore.totalSpace - grantedUsableSpaceBuffer)
1007+
);
10051008
boolean aHasMoreSpace = aFileStore.usableSpace > bFileStore.usableSpace;
10061009
Settings.Builder settingsBuilder = Settings.builder().put(settings);
10071010
// change the watermark level, just for coverage and it's easier with the calculations

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapperTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
6767
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN;
68+
import static org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase.randomNormalizedVector;
6869
import static org.elasticsearch.index.codec.vectors.IVFVectorsFormat.DYNAMIC_NPROBE;
6970
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.DEFAULT_OVERSAMPLE;
7071
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.IVF_FORMAT;
@@ -147,7 +148,17 @@ private void indexMapping(XContentBuilder b, IndexVersion indexVersion) throws I
147148

148149
@Override
149150
protected Object getSampleValueForDocument() {
150-
return elementType == ElementType.FLOAT ? List.of(0.5, 0.5, 0.5, 0.5) : List.of((byte) 1, (byte) 1, (byte) 1, (byte) 1);
151+
return elementType == ElementType.FLOAT
152+
? convertToList(randomNormalizedVector(this.dims))
153+
: List.of((byte) 1, (byte) 1, (byte) 1, (byte) 1);
154+
}
155+
156+
private static List<Float> convertToList(float[] vector) {
157+
List<Float> list = new ArrayList<>(vector.length);
158+
for (float v : vector) {
159+
list.add(v);
160+
}
161+
return list;
151162
}
152163

153164
@Override

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,9 +2713,11 @@ public static Request newXContentRequest(HttpMethod method, String endpoint, ToX
27132713
}
27142714

27152715
protected static MapMatcher getProfileMatcher() {
2716-
return matchesMap().entry("query", instanceOf(Map.class))
2716+
return matchesMap() //
2717+
.entry("query", instanceOf(Map.class))
27172718
.entry("planning", instanceOf(Map.class))
2718-
.entry("drivers", instanceOf(List.class));
2719+
.entry("drivers", instanceOf(List.class))
2720+
.entry("plans", instanceOf(List.class));
27192721
}
27202722

27212723
protected static MapMatcher getResultMatcher(boolean includeMetadata, boolean includePartial, boolean includeDocumentsFound) {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationReloader.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
import java.util.ArrayList;
2323
import java.util.Collection;
2424
import java.util.HashMap;
25-
import java.util.HashSet;
2625
import java.util.List;
2726
import java.util.Map;
28-
import java.util.Set;
2927
import java.util.concurrent.ExecutionException;
3028
import java.util.concurrent.Future;
3129
import java.util.function.Consumer;
@@ -80,7 +78,7 @@ private static Consumer<SslConfiguration> reloadConsumer(Future<SSLService> futu
8078
}
8179

8280
/**
83-
* Collects all of the directories that need to be monitored for the provided {@link SslConfiguration} instances and ensures that
81+
* Collects all of the files that need to be monitored for the provided {@link SslConfiguration} instances and ensures that
8482
* they are being watched for changes
8583
*/
8684
private static void startWatching(
@@ -91,8 +89,8 @@ private static void startWatching(
9189
Map<Path, List<SslConfiguration>> pathToConfigurationsMap = new HashMap<>();
9290
for (SslConfiguration sslConfiguration : sslConfigurations) {
9391
final Collection<Path> filesToMonitor = sslConfiguration.getDependentFiles();
94-
for (Path directory : directoriesToMonitor(filesToMonitor)) {
95-
pathToConfigurationsMap.compute(directory, (path, list) -> {
92+
for (Path file : filesToMonitor) {
93+
pathToConfigurationsMap.compute(file, (path, list) -> {
9694
if (list == null) {
9795
list = new ArrayList<>();
9896
}
@@ -109,22 +107,11 @@ private static void startWatching(
109107
try {
110108
resourceWatcherService.add(fileWatcher, Frequency.HIGH);
111109
} catch (IOException | SecurityException e) {
112-
logger.error("failed to start watching directory [{}] for ssl configurations [{}] - {}", path, configurations, e);
110+
logger.error("failed to start watching file [{}] for ssl configurations [{}] - {}", path, configurations, e);
113111
}
114112
});
115113
}
116114

117-
/**
118-
* Returns a unique set of directories that need to be monitored based on the provided file paths
119-
*/
120-
private static Set<Path> directoriesToMonitor(Iterable<Path> filePaths) {
121-
Set<Path> paths = new HashSet<>();
122-
for (Path path : filePaths) {
123-
paths.add(path.getParent());
124-
}
125-
return paths;
126-
}
127-
128115
private static class ChangeListener implements FileChangesListener {
129116

130117
private final List<SslConfiguration> sslConfigurations;

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationReloaderTests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.elasticsearch.test.http.MockWebServer;
3838
import org.elasticsearch.threadpool.TestThreadPool;
3939
import org.elasticsearch.threadpool.ThreadPool;
40+
import org.elasticsearch.watcher.FileWatcher;
41+
import org.elasticsearch.watcher.ResourceWatcher;
4042
import org.elasticsearch.watcher.ResourceWatcherService;
4143
import org.junit.After;
4244
import org.junit.Before;
@@ -66,7 +68,9 @@
6668
import java.security.cert.CertificateException;
6769
import java.util.Collection;
6870
import java.util.Collections;
71+
import java.util.HashSet;
6972
import java.util.List;
73+
import java.util.Set;
7074
import java.util.concurrent.CountDownLatch;
7175
import java.util.concurrent.CyclicBarrier;
7276
import java.util.concurrent.TimeUnit;
@@ -79,6 +83,7 @@
7983
import javax.net.ssl.SSLSocket;
8084

8185
import static org.elasticsearch.test.TestMatchers.throwableWithMessage;
86+
import static org.hamcrest.Matchers.containsInAnyOrder;
8287
import static org.hamcrest.Matchers.containsString;
8388
import static org.hamcrest.Matchers.sameInstance;
8489

@@ -559,6 +564,38 @@ public void testFailureToReadFileDoesntFail() throws Exception {
559564
}
560565
}
561566

567+
/**
568+
* Due to exclusive access entitlements
569+
* (see {@link org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.FileData#exclusive}),
570+
* it is not safe to monitor a directory or any files that are not an explicit part of this SSL configuration.
571+
*/
572+
public void testReloaderOnlyWatchesSpecifiedFiles() throws Exception {
573+
final Set<Path> watchedPaths = new HashSet<>();
574+
final ResourceWatcherService mockResourceWatcher = Mockito.mock(ResourceWatcherService.class);
575+
Mockito.when(mockResourceWatcher.add(Mockito.any(ResourceWatcher.class), Mockito.any(ResourceWatcherService.Frequency.class)))
576+
.then(inv -> {
577+
final FileWatcher fileWatcher = asInstanceOf(FileWatcher.class, inv.getArguments()[0]);
578+
watchedPaths.add(fileWatcher.getPath());
579+
return null;
580+
});
581+
582+
final Path tempDir = createTempDir();
583+
final Path clientCertPath = tempDir.resolve("testclient.crt");
584+
Settings settings = baseKeystoreSettings(tempDir, null).putList(
585+
"xpack.security.transport.ssl.certificate_authorities",
586+
clientCertPath.toString()
587+
).put("path.home", createTempDir()).build();
588+
589+
final Environment env = newEnvironment(settings);
590+
final Collection<SslConfiguration> configurations = SSLService.getSSLConfigurations(env).values();
591+
new SSLConfigurationReloader(ignore -> {}, mockResourceWatcher, configurations);
592+
593+
assertThat(
594+
watchedPaths,
595+
containsInAnyOrder(tempDir.resolve("testclient.pem"), tempDir.resolve("testclient.crt"), tempDir.resolve("testclientcert.crt"))
596+
);
597+
}
598+
562599
private Settings.Builder baseKeystoreSettings(Path tempDir, MockSecureSettings secureSettings) throws IOException {
563600
final Path keyPath = tempDir.resolve("testclient.pem");
564601
final Path certPath = tempDir.resolve("testclientcert.crt"); // testclient.crt filename already used in #testPEMTrustReloadException

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/DriverCompletionInfo.java

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

88
package org.elasticsearch.compute.operator;
99

10+
import org.elasticsearch.TransportVersions;
1011
import org.elasticsearch.common.io.stream.StreamInput;
1112
import org.elasticsearch.common.io.stream.StreamOutput;
1213
import org.elasticsearch.common.io.stream.Writeable;
@@ -24,23 +25,34 @@
2425
* <strong>roughly</strong> the number of documents times the number of
2526
* fields per document. Except {@code null} values don't count.
2627
* And multivalued fields count as many times as there are values.
27-
* @param collectedProfiles {@link DriverProfile}s from each driver. These are fairly cheap to build but
28+
* @param driverProfiles {@link DriverProfile}s from each driver. These are fairly cheap to build but
2829
* not free so this will be empty if the {@code profile} option was not set in
2930
* the request.
3031
*/
31-
public record DriverCompletionInfo(long documentsFound, long valuesLoaded, List<DriverProfile> collectedProfiles) implements Writeable {
32+
public record DriverCompletionInfo(
33+
long documentsFound,
34+
long valuesLoaded,
35+
List<DriverProfile> driverProfiles,
36+
List<PlanProfile> planProfiles
37+
) implements Writeable {
3238

3339
/**
3440
* Completion info we use when we didn't properly complete any drivers.
3541
* Usually this is returned with an error, but it's also used when receiving
3642
* responses from very old nodes.
3743
*/
38-
public static final DriverCompletionInfo EMPTY = new DriverCompletionInfo(0, 0, List.of());
44+
public static final DriverCompletionInfo EMPTY = new DriverCompletionInfo(0, 0, List.of(), List.of());
3945

4046
/**
4147
* Build a {@link DriverCompletionInfo} for many drivers including their profile output.
4248
*/
43-
public static DriverCompletionInfo includingProfiles(List<Driver> drivers) {
49+
public static DriverCompletionInfo includingProfiles(
50+
List<Driver> drivers,
51+
String description,
52+
String clusterName,
53+
String nodeName,
54+
String planTree
55+
) {
4456
long documentsFound = 0;
4557
long valuesLoaded = 0;
4658
List<DriverProfile> collectedProfiles = new ArrayList<>(drivers.size());
@@ -52,7 +64,12 @@ public static DriverCompletionInfo includingProfiles(List<Driver> drivers) {
5264
}
5365
collectedProfiles.add(p);
5466
}
55-
return new DriverCompletionInfo(documentsFound, valuesLoaded, collectedProfiles);
67+
return new DriverCompletionInfo(
68+
documentsFound,
69+
valuesLoaded,
70+
collectedProfiles,
71+
List.of(new PlanProfile(description, clusterName, nodeName, planTree))
72+
);
5673
}
5774

5875
/**
@@ -69,49 +86,63 @@ public static DriverCompletionInfo excludingProfiles(List<Driver> drivers) {
6986
valuesLoaded += o.valuesLoaded();
7087
}
7188
}
72-
return new DriverCompletionInfo(documentsFound, valuesLoaded, List.of());
89+
return new DriverCompletionInfo(documentsFound, valuesLoaded, List.of(), List.of());
7390
}
7491

75-
public DriverCompletionInfo(StreamInput in) throws IOException {
76-
this(in.readVLong(), in.readVLong(), in.readCollectionAsImmutableList(DriverProfile::readFrom));
92+
public static DriverCompletionInfo readFrom(StreamInput in) throws IOException {
93+
return new DriverCompletionInfo(
94+
in.readVLong(),
95+
in.readVLong(),
96+
in.readCollectionAsImmutableList(DriverProfile::readFrom),
97+
in.getTransportVersion().onOrAfter(TransportVersions.ESQL_PROFILE_INCLUDE_PLAN)
98+
? in.readCollectionAsImmutableList(PlanProfile::readFrom)
99+
: List.of()
100+
);
77101
}
78102

79103
@Override
80104
public void writeTo(StreamOutput out) throws IOException {
81105
out.writeVLong(documentsFound);
82106
out.writeVLong(valuesLoaded);
83-
out.writeCollection(collectedProfiles, (o, v) -> v.writeTo(o));
107+
out.writeCollection(driverProfiles);
108+
if (out.getTransportVersion().onOrAfter(TransportVersions.ESQL_PROFILE_INCLUDE_PLAN)) {
109+
out.writeCollection(planProfiles);
110+
}
84111
}
85112

86113
public static class Accumulator {
87114
private long documentsFound;
88115
private long valuesLoaded;
89-
private final List<DriverProfile> collectedProfiles = new ArrayList<>();
116+
private final List<DriverProfile> driverProfiles = new ArrayList<>();
117+
private final List<PlanProfile> planProfiles = new ArrayList<>();
90118

91119
public void accumulate(DriverCompletionInfo info) {
92120
this.documentsFound += info.documentsFound;
93121
this.valuesLoaded += info.valuesLoaded;
94-
this.collectedProfiles.addAll(info.collectedProfiles);
122+
this.driverProfiles.addAll(info.driverProfiles);
123+
this.planProfiles.addAll(info.planProfiles);
95124
}
96125

97126
public DriverCompletionInfo finish() {
98-
return new DriverCompletionInfo(documentsFound, valuesLoaded, collectedProfiles);
127+
return new DriverCompletionInfo(documentsFound, valuesLoaded, driverProfiles, planProfiles);
99128
}
100129
}
101130

102131
public static class AtomicAccumulator {
103132
private final AtomicLong documentsFound = new AtomicLong();
104133
private final AtomicLong valuesLoaded = new AtomicLong();
105134
private final List<DriverProfile> collectedProfiles = Collections.synchronizedList(new ArrayList<>());
135+
private final List<PlanProfile> planProfiles = Collections.synchronizedList(new ArrayList<>());
106136

107137
public void accumulate(DriverCompletionInfo info) {
108138
this.documentsFound.addAndGet(info.documentsFound);
109139
this.valuesLoaded.addAndGet(info.valuesLoaded);
110-
this.collectedProfiles.addAll(info.collectedProfiles);
140+
this.collectedProfiles.addAll(info.driverProfiles);
141+
this.planProfiles.addAll(info.planProfiles);
111142
}
112143

113144
public DriverCompletionInfo finish() {
114-
return new DriverCompletionInfo(documentsFound.get(), valuesLoaded.get(), collectedProfiles);
145+
return new DriverCompletionInfo(documentsFound.get(), valuesLoaded.get(), collectedProfiles, planProfiles);
115146
}
116147
}
117148
}

0 commit comments

Comments
 (0)