Skip to content

Commit 8622f57

Browse files
Merge branch 'main' into double-question-marks
2 parents b03b553 + 3149640 commit 8622f57

File tree

6 files changed

+47
-92
lines changed

6 files changed

+47
-92
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,13 @@ static void fileCreateTempFile() throws IOException {
9393

9494
@EntitlementTest(expectedAccess = PLUGINS)
9595
static void fileDelete() throws IOException {
96-
Path toDelete = readWriteDir().resolve("to_delete");
97-
EntitledActions.createFile(toDelete);
96+
var toDelete = EntitledActions.createTempFileForWrite();
9897
toDelete.toFile().delete();
9998
}
10099

101100
@EntitlementTest(expectedAccess = PLUGINS)
102101
static void fileDeleteOnExit() throws IOException {
103-
Path toDelete = readWriteDir().resolve("to_delete_on_exit");
104-
EntitledActions.createFile(toDelete);
102+
var toDelete = EntitledActions.createTempFileForWrite();
105103
toDelete.toFile().deleteOnExit();
106104
}
107105

@@ -174,9 +172,10 @@ static void fileMkdirs() {
174172

175173
@EntitlementTest(expectedAccess = PLUGINS)
176174
static void fileRenameTo() throws IOException {
177-
Path toRename = readWriteDir().resolve("to_rename");
175+
var dir = EntitledActions.createTempDirectoryForWrite();
176+
Path toRename = dir.resolve("to_rename");
178177
EntitledActions.createFile(toRename);
179-
toRename.toFile().renameTo(readWriteDir().resolve("renamed").toFile());
178+
toRename.toFile().renameTo(dir.resolve("renamed").toFile());
180179
}
181180

182181
@EntitlementTest(expectedAccess = PLUGINS)
@@ -206,8 +205,7 @@ static void fileSetReadableOwner() {
206205

207206
@EntitlementTest(expectedAccess = PLUGINS)
208207
static void fileSetReadOnly() throws IOException {
209-
Path readOnly = readWriteDir().resolve("read_only");
210-
EntitledActions.createFile(readOnly);
208+
Path readOnly = EntitledActions.createTempFileForWrite();
211209
readOnly.toFile().setReadOnly();
212210
}
213211

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/FileAccessTree.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import java.nio.file.Paths;
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
26+
import java.util.HashMap;
2627
import java.util.HashSet;
27-
import java.util.LinkedHashMap;
2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.Objects;
@@ -55,7 +55,7 @@ public String toString() {
5555
}
5656

5757
static List<ExclusivePath> buildExclusivePathList(List<ExclusiveFileEntitlement> exclusiveFileEntitlements, PathLookup pathLookup) {
58-
Map<String, ExclusivePath> exclusivePaths = new LinkedHashMap<>();
58+
Map<String, ExclusivePath> exclusivePaths = new HashMap<>();
5959
for (ExclusiveFileEntitlement efe : exclusiveFileEntitlements) {
6060
for (FilesEntitlement.FileData fd : efe.filesEntitlement().filesData()) {
6161
if (fd.exclusive()) {

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,17 @@ public void testDuplicatePrunedPaths() {
365365

366366
public void testDuplicateExclusivePaths() {
367367
// Bunch o' handy definitions
368-
var originalFileData = FileData.ofPath(path("/a/b"), READ).withExclusive(true);
369-
var fileDataWithWriteMode = FileData.ofPath(path("/a/b"), READ_WRITE).withExclusive(true);
368+
var pathAB = path("/a/b");
369+
var pathCD = path("/c/d");
370+
var originalFileData = FileData.ofPath(pathAB, READ).withExclusive(true);
371+
var fileDataWithWriteMode = FileData.ofPath(pathAB, READ_WRITE).withExclusive(true);
370372
var original = new ExclusiveFileEntitlement("component1", "module1", new FilesEntitlement(List.of(originalFileData)));
371373
var differentComponent = new ExclusiveFileEntitlement("component2", original.moduleName(), original.filesEntitlement());
372374
var differentModule = new ExclusiveFileEntitlement(original.componentName(), "module2", original.filesEntitlement());
373375
var differentPath = new ExclusiveFileEntitlement(
374376
original.componentName(),
375377
original.moduleName(),
376-
new FilesEntitlement(
377-
List.of(FileData.ofPath(path("/c/d"), originalFileData.mode()).withExclusive(originalFileData.exclusive()))
378-
)
378+
new FilesEntitlement(List.of(FileData.ofPath(pathCD, originalFileData.mode()).withExclusive(originalFileData.exclusive())))
379379
);
380380
var differentMode = new ExclusiveFileEntitlement(
381381
original.componentName(),
@@ -387,7 +387,7 @@ public void testDuplicateExclusivePaths() {
387387
original.moduleName(),
388388
new FilesEntitlement(List.of(originalFileData.withPlatform(WINDOWS)))
389389
);
390-
var originalExclusivePath = new ExclusivePath("component1", Set.of("module1"), normalizePath(path("/a/b")));
390+
var originalExclusivePath = new ExclusivePath("component1", Set.of("module1"), normalizePath(pathAB));
391391

392392
// Some basic tests
393393

@@ -409,12 +409,17 @@ public void testDuplicateExclusivePaths() {
409409
originalExclusivePath,
410410
new ExclusivePath("component2", Set.of(original.moduleName()), originalExclusivePath.path()),
411411
new ExclusivePath(original.componentName(), Set.of("module2"), originalExclusivePath.path()),
412-
new ExclusivePath(original.componentName(), Set.of(original.moduleName()), normalizePath(path("/c/d")))
412+
new ExclusivePath(original.componentName(), Set.of(original.moduleName()), normalizePath(pathCD))
413413
);
414414
var iae = expectThrows(IllegalArgumentException.class, () -> buildExclusivePathList(distinctEntitlements, TEST_PATH_LOOKUP));
415+
var pathABString = pathAB.toAbsolutePath().toString();
415416
assertThat(
416417
iae.getMessage(),
417-
equalTo("Path [/a/b] is already exclusive to [component1][module1], cannot add exclusive access for [component2][module1]")
418+
equalTo(
419+
"Path ["
420+
+ pathABString
421+
+ "] is already exclusive to [component1][module1], cannot add exclusive access for [component2][module1]"
422+
)
418423
);
419424

420425
var equivalentEntitlements = List.of(original, differentMode, differentPlatform);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.ALL_UNNAMED;
3939
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.SERVER_COMPONENT_NAME;
4040
import static org.hamcrest.Matchers.aMapWithSize;
41-
import static org.hamcrest.Matchers.equalTo;
41+
import static org.hamcrest.Matchers.allOf;
42+
import static org.hamcrest.Matchers.containsString;
4243
import static org.hamcrest.Matchers.is;
4344
import static org.hamcrest.Matchers.sameInstance;
4445

@@ -493,9 +494,11 @@ public void testFilesEntitlementsWithExclusive() {
493494
);
494495
assertThat(
495496
iae.getMessage(),
496-
equalTo(
497-
"Path [/base/test] is already exclusive to [plugin1][test.module1],"
498-
+ " cannot add exclusive access for [plugin2][test.module2]"
497+
allOf(
498+
containsString("Path [/base/test] is already exclusive"),
499+
containsString("[plugin1][test.module1]"),
500+
containsString("[plugin2][test.module2]"),
501+
containsString("cannot add exclusive access")
499502
)
500503
);
501504

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,6 @@ tests:
360360
- class: org.elasticsearch.entitlement.runtime.policy.PolicyManagerTests
361361
method: testFilesEntitlementsWithExclusive
362362
issue: https://github.com/elastic/elasticsearch/issues/124420
363-
- class: org.elasticsearch.entitlement.runtime.policy.FileAccessTreeTests
364-
method: testDuplicateExclusivePaths
365-
issue: https://github.com/elastic/elasticsearch/issues/124437
366363
- class: org.elasticsearch.xpack.restart.FullClusterRestartIT
367364
method: testWatcherWithApiKey {cluster=UPGRADED}
368365
issue: https://github.com/elastic/elasticsearch/issues/124159

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/IndexingIT.java

Lines changed: 19 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.common.Strings;
1919
import org.elasticsearch.common.time.DateUtils;
2020
import org.elasticsearch.common.xcontent.support.XContentMapValues;
21-
import org.elasticsearch.core.UpdateForV9;
2221
import org.elasticsearch.index.mapper.DateFieldMapper;
2322
import org.elasticsearch.index.mapper.SourceFieldMapper;
2423
import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper;
@@ -258,90 +257,47 @@ private void bulk(String index, String valueSuffix, int count) throws IOExceptio
258257
}
259258

260259
public void testTsdb() throws IOException {
261-
final Version oldClusterVersion = Version.fromString(getOldClusterVersion());
262-
263260
StringBuilder bulk = new StringBuilder();
264261
if (isOldCluster()) {
265262
createTsdbIndex();
266263
tsdbBulk(bulk, TSDB_DIMS.get(0), TSDB_TIMES[0], TSDB_TIMES[1], 0.1);
267264
tsdbBulk(bulk, TSDB_DIMS.get(1), TSDB_TIMES[0], TSDB_TIMES[1], -0.1);
268265
bulk("tsdb", bulk.toString());
269-
assertTsdbAgg(oldClusterVersion, EXPECTED_TSDB_TSIDS_NODES_0, closeTo(215.95, 0.005), closeTo(-215.95, 0.005));
266+
assertTsdbAgg(EXPECTED_TSDB_TSIDS_NODES_0, closeTo(215.95, 0.005), closeTo(-215.95, 0.005));
270267
} else if (isFirstMixedCluster()) {
271268
tsdbBulk(bulk, TSDB_DIMS.get(0), TSDB_TIMES[1], TSDB_TIMES[2], 0.1);
272269
tsdbBulk(bulk, TSDB_DIMS.get(1), TSDB_TIMES[1], TSDB_TIMES[2], -0.1);
273270
tsdbBulk(bulk, TSDB_DIMS.get(2), TSDB_TIMES[0], TSDB_TIMES[2], 1.1);
274271
bulk("tsdb", bulk.toString());
275-
if (oldClusterVersion.onOrAfter(Version.V_8_13_0)) {
276-
assertTsdbAgg(
277-
oldClusterVersion,
278-
EXPECTED_TSDB_TSIDS_NODES_1,
279-
closeTo(217.45, 0.005),
280-
closeTo(2391.95, 0.005),
281-
closeTo(-217.45, 0.005)
282-
);
283-
} else {
284-
assertTsdbAgg(
285-
oldClusterVersion,
286-
EXPECTED_TSDB_TSIDS_NODES_1,
287-
closeTo(217.45, 0.005),
288-
closeTo(-217.45, 0.005),
289-
closeTo(2391.95, 0.005)
290-
);
291-
}
272+
assertTsdbAgg(EXPECTED_TSDB_TSIDS_NODES_1, closeTo(217.45, 0.005), closeTo(2391.95, 0.005), closeTo(-217.45, 0.005));
292273
} else if (isMixedCluster()) {
293274
tsdbBulk(bulk, TSDB_DIMS.get(0), TSDB_TIMES[2], TSDB_TIMES[3], 0.1);
294275
tsdbBulk(bulk, TSDB_DIMS.get(1), TSDB_TIMES[2], TSDB_TIMES[3], -0.1);
295276
tsdbBulk(bulk, TSDB_DIMS.get(2), TSDB_TIMES[2], TSDB_TIMES[3], 1.1);
296277
tsdbBulk(bulk, TSDB_DIMS.get(3), TSDB_TIMES[0], TSDB_TIMES[3], 10);
297278
bulk("tsdb", bulk.toString());
298-
if (oldClusterVersion.onOrAfter(Version.V_8_13_0)) {
299-
assertTsdbAgg(
300-
oldClusterVersion,
301-
EXPECTED_TSDB_TSIDS_NODES_2,
302-
closeTo(218.95, 0.5),
303-
closeTo(21895.0, 0.005),
304-
closeTo(2408.45, 0.005),
305-
closeTo(-218.95, 0.005)
306-
);
307-
} else {
308-
assertTsdbAgg(
309-
oldClusterVersion,
310-
EXPECTED_TSDB_TSIDS_NODES_2,
311-
closeTo(218.95, 0.005),
312-
closeTo(-218.95, 0.005),
313-
closeTo(2408.45, 0.005),
314-
closeTo(21895, 0.5)
315-
);
316-
}
279+
assertTsdbAgg(
280+
EXPECTED_TSDB_TSIDS_NODES_2,
281+
closeTo(218.95, 0.5),
282+
closeTo(21895.0, 0.005),
283+
closeTo(2408.45, 0.005),
284+
closeTo(-218.95, 0.005)
285+
);
317286
} else {
318287
tsdbBulk(bulk, TSDB_DIMS.get(0), TSDB_TIMES[3], TSDB_TIMES[4], 0.1);
319288
tsdbBulk(bulk, TSDB_DIMS.get(1), TSDB_TIMES[3], TSDB_TIMES[4], -0.1);
320289
tsdbBulk(bulk, TSDB_DIMS.get(2), TSDB_TIMES[3], TSDB_TIMES[4], 1.1);
321290
tsdbBulk(bulk, TSDB_DIMS.get(3), TSDB_TIMES[3], TSDB_TIMES[4], 10);
322291
tsdbBulk(bulk, TSDB_DIMS.get(4), TSDB_TIMES[0], TSDB_TIMES[4], -5);
323292
bulk("tsdb", bulk.toString());
324-
if (oldClusterVersion.onOrAfter(Version.V_8_13_0)) {
325-
assertTsdbAgg(
326-
oldClusterVersion,
327-
EXPECTED_TSDB_TSIDS_NODES_3,
328-
closeTo(220.45, 0.005),
329-
closeTo(-11022.5, 0.5),
330-
closeTo(22045, 0.5),
331-
closeTo(2424.95, 0.005),
332-
closeTo(-220.45, 0.005)
333-
);
334-
} else {
335-
assertTsdbAgg(
336-
oldClusterVersion,
337-
EXPECTED_TSDB_TSIDS_NODES_3,
338-
closeTo(220.45, 0.005),
339-
closeTo(-220.45, 0.005),
340-
closeTo(2424.95, 0.005),
341-
closeTo(22045, 0.5),
342-
closeTo(-11022.5, 0.5)
343-
);
344-
}
293+
assertTsdbAgg(
294+
EXPECTED_TSDB_TSIDS_NODES_3,
295+
closeTo(220.45, 0.005),
296+
closeTo(-11022.5, 0.5),
297+
closeTo(22045, 0.5),
298+
closeTo(2424.95, 0.005),
299+
closeTo(-220.45, 0.005)
300+
);
345301
}
346302
}
347303

@@ -383,10 +339,7 @@ private void tsdbBulk(StringBuilder bulk, String dim, long timeStart, long timeE
383339
}
384340
}
385341

386-
private void assertTsdbAgg(final Version oldClusterVersion, final List<String> expectedTsids, final Matcher<?>... expected)
387-
throws IOException {
388-
@UpdateForV9(owner = UpdateForV9.Owner.SEARCH_ANALYTICS)
389-
boolean onOrAfterTsidHashingVersion = oldClusterVersion.onOrAfter(Version.V_8_13_0);
342+
private void assertTsdbAgg(final List<String> expectedTsids, final Matcher<?>... expected) throws IOException {
390343
Request request = new Request("POST", "/tsdb/_search");
391344
request.addParameter("size", "0");
392345
XContentBuilder body = JsonXContent.contentBuilder().startObject();
@@ -403,8 +356,7 @@ private void assertTsdbAgg(final Version oldClusterVersion, final List<String> e
403356
request.setJsonEntity(Strings.toString(body.endObject()));
404357
ListMatcher tsidsExpected = matchesList();
405358
for (int d = 0; d < expected.length; d++) {
406-
// NOTE: from Version 8.12.0 on we use tsid hashing for the _tsid field
407-
Object key = onOrAfterTsidHashingVersion ? expectedTsids.get(d) : Map.of("dim", IndexingIT.TSDB_DIMS.get(d));
359+
Object key = expectedTsids.get(d);
408360
tsidsExpected = tsidsExpected.item(matchesMap().extraOk().entry("key", key).entry("avg", Map.of("value", expected[d])));
409361
}
410362
assertMap(

0 commit comments

Comments
 (0)