Skip to content

Commit cd4412b

Browse files
authored
Merge branch 'main' into kderusso/fix-search-usage-stat-test
2 parents 87695ee + 62b1c80 commit cd4412b

File tree

10 files changed

+89
-28
lines changed

10 files changed

+89
-28
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,18 +591,12 @@ tests:
591591
- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT
592592
method: test
593593
issue: https://github.com/elastic/elasticsearch/issues/134407
594-
- class: org.elasticsearch.search.ccs.SparseVectorQueryBuilderCrossClusterSearchIT
595-
method: testSparseVectorQueryWithCcsMinimizeRoundTripsFalse
596-
issue: https://github.com/elastic/elasticsearch/issues/135559
597594
- class: org.elasticsearch.cluster.routing.allocation.decider.RestoreInProgressAllocationDeciderTests
598595
method: testCanAllocatePrimaryExistingInRestoreInProgress
599596
issue: https://github.com/elastic/elasticsearch/issues/135566
600597
- class: org.elasticsearch.xpack.esql.inference.textembedding.TextEmbeddingOperatorTests
601598
method: testSimpleCircuitBreaking
602599
issue: https://github.com/elastic/elasticsearch/issues/135569
603-
- class: org.elasticsearch.search.ccs.KnnVectorQueryBuilderCrossClusterSearchIT
604-
method: testKnnQueryWithCcsMinimizeRoundTripsFalse
605-
issue: https://github.com/elastic/elasticsearch/issues/135573
606600
- class: org.elasticsearch.multiproject.test.XpackWithMultipleProjectsClientYamlTestSuiteIT
607601
method: test {yaml=esql/60_usage/Basic ESQL usage output (telemetry) snapshot version}
608602
issue: https://github.com/elastic/elasticsearch/issues/135579

test/framework/build.gradle

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@
1010
apply plugin: 'elasticsearch.build'
1111
apply plugin: 'elasticsearch.publish'
1212

13-
configurations {
14-
// we do not want to expose a version conflict in transitive dependencies by
15-
// bringing in different versions of hamcrest and hamcrest-core.
16-
// Therefore we exclude transitive deps on hamcrest-core here as we have a direct
17-
// dependency on a newer version.
18-
runtimeElements {
19-
exclude group: 'org.hamcrest', module: 'hamcrest-core'
20-
}
21-
}
2213
dependencies {
2314
api project(":client:rest")
2415
api project(':modules:transport-netty4')
2516
api project(':libs:ssl-config')
2617
api project(":server")
2718
api project(":libs:cli")
2819
api project(":libs:entitlement:bridge")
29-
api "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
30-
api("junit:junit:${versions.junit}") {
31-
// exclude group: 'org.hamcrest'
20+
api ("com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}") {
21+
exclude group: "junit", module: "junit"
3222
}
23+
24+
// we do not want to expose a version conflict in transitive dependencies by
25+
// bringing in different versions of dependencies.
26+
// Therefore we exclude mismatches in our transitive dependencies explicitly.
27+
// This also avoids jarHell issues with different hamcrest related dependencies
28+
// like hamcrest and hamcrest-core
3329
api "org.hamcrest:hamcrest:${versions.hamcrest}"
30+
api("junit:junit:${versions.junit}") {
31+
exclude group: 'org.hamcrest', module: 'hamcrest-core'
32+
}
3433
api("org.apache.lucene:lucene-test-framework:${versions.lucene}") {
35-
// exclude group: 'org.hamcrest'
34+
exclude group: "junit", module: "junit"
35+
exclude group: 'com.carrotsearch.randomizedtesting', module: 'randomizedtesting-runner'
3636
}
3737
api "org.apache.lucene:lucene-codecs:${versions.lucene}"
3838
api "commons-logging:commons-logging:${versions.commonslogging}"

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/DocumentSubsetBitsetCache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import java.io.Closeable;
4040
import java.io.IOException;
41-
import java.util.Collections;
4241
import java.util.LinkedHashMap;
4342
import java.util.List;
4443
import java.util.Map;
@@ -316,7 +315,7 @@ public Map<String, Object> usageStats() {
316315
stats.put("evictions", cacheStats.getEvictions());
317316
stats.put("hits_time_in_millis", TimeValue.nsecToMSec(hitsTimeInNanos.sum()));
318317
stats.put("misses_time_in_millis", TimeValue.nsecToMSec(missesTimeInNanos.sum()));
319-
return Collections.unmodifiableMap(stats);
318+
return stats;
320319
}
321320

322321
private static final class BitsetCacheKey {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/stats/GetSecurityStatsNodeResponseTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99

1010
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
1111
import org.elasticsearch.common.io.stream.Writeable;
12+
import org.elasticsearch.common.util.Maps;
1213
import org.elasticsearch.test.AbstractWireSerializingTestCase;
1314

1415
import java.io.IOException;
1516
import java.util.Map;
1617
import java.util.Objects;
1718

19+
import static org.hamcrest.Matchers.equalTo;
20+
1821
public class GetSecurityStatsNodeResponseTests extends AbstractWireSerializingTestCase<GetSecurityStatsNodeResponse> {
1922

2023
@Override
@@ -46,4 +49,20 @@ protected GetSecurityStatsNodeResponse mutateInstance(GetSecurityStatsNodeRespon
4649
default -> throw new IllegalStateException("Unexpected value");
4750
};
4851
}
52+
53+
public void testRolesStatsInOrderSerialization() throws IOException {
54+
final Map<String, Object> rolesStats = Maps.newLinkedHashMapWithExpectedSize(3);
55+
rolesStats.put("one", "value");
56+
rolesStats.put("two", "value");
57+
rolesStats.put("three", "value");
58+
final GetSecurityStatsNodeResponse in = new GetSecurityStatsNodeResponse(
59+
DiscoveryNodeUtils.create(randomAlphaOfLength(10)),
60+
rolesStats
61+
);
62+
63+
final GetSecurityStatsNodeResponse out = copyInstance(in);
64+
assertThat(in, equalTo(out));
65+
66+
assertThat(out.getRolesStoreStats().keySet().toArray(new String[0]), equalTo(new String[] { "one", "two", "three" }));
67+
}
4968
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/DocumentSubsetBitsetCacheTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
import static org.hamcrest.Matchers.equalTo;
6767
import static org.hamcrest.Matchers.greaterThan;
68+
import static org.hamcrest.Matchers.instanceOf;
6869
import static org.hamcrest.Matchers.is;
6970
import static org.hamcrest.Matchers.lessThan;
7071
import static org.hamcrest.Matchers.not;
@@ -529,6 +530,11 @@ public void testHitsMissesAndEvictionsStats() throws Exception {
529530
assertThat(cache.usageStats(), equalTo(finalStats));
530531
}
531532

533+
public void testUsageStatsAreOrdered() {
534+
final Map<String, Object> stats = newCache(Settings.EMPTY).usageStats();
535+
assertThat("needs to be LinkedHashMap for order in transport", stats, instanceOf(LinkedHashMap.class));
536+
}
537+
532538
private void runTestOnIndex(CheckedBiConsumer<SearchExecutionContext, LeafReaderContext, Exception> body) throws Exception {
533539
runTestOnIndices(1, ctx -> {
534540
final TestIndexContext indexContext = ctx.get(0);

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/search/ccs/AbstractSemanticCrossClusterSearchTestCase.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
package org.elasticsearch.search.ccs;
99

1010
import org.elasticsearch.action.DocWriteResponse;
11+
import org.elasticsearch.action.admin.cluster.remote.RemoteInfoRequest;
12+
import org.elasticsearch.action.admin.cluster.remote.RemoteInfoResponse;
13+
import org.elasticsearch.action.admin.cluster.remote.TransportRemoteInfoAction;
1114
import org.elasticsearch.action.search.OpenPointInTimeRequest;
1215
import org.elasticsearch.action.search.OpenPointInTimeResponse;
1316
import org.elasticsearch.action.search.SearchRequest;
@@ -35,6 +38,7 @@
3538
import org.elasticsearch.search.SearchHit;
3639
import org.elasticsearch.search.builder.SearchSourceBuilder;
3740
import org.elasticsearch.test.AbstractMultiClustersTestCase;
41+
import org.elasticsearch.transport.RemoteConnectionInfo;
3842
import org.elasticsearch.xcontent.XContentBuilder;
3943
import org.elasticsearch.xcontent.XContentFactory;
4044
import org.elasticsearch.xcontent.XContentType;
@@ -56,6 +60,7 @@
5660
import java.util.List;
5761
import java.util.Map;
5862
import java.util.Set;
63+
import java.util.concurrent.TimeUnit;
5964
import java.util.function.Consumer;
6065
import java.util.stream.Collectors;
6166

@@ -92,14 +97,16 @@ protected Collection<Class<? extends Plugin>> nodePlugins(String clusterAlias) {
9297
return List.of(LocalStateInferencePlugin.class, TestInferenceServicePlugin.class, FakeMlPlugin.class);
9398
}
9499

95-
protected void setupTwoClusters(TestIndexInfo localIndexInfo, TestIndexInfo remoteIndexInfo) throws IOException {
100+
protected void setupTwoClusters(TestIndexInfo localIndexInfo, TestIndexInfo remoteIndexInfo) throws Exception {
96101
setupCluster(LOCAL_CLUSTER, localIndexInfo);
97102
setupCluster(REMOTE_CLUSTER, remoteIndexInfo);
103+
waitUntilRemoteClusterConnected(REMOTE_CLUSTER);
98104
}
99105

100106
protected void setupCluster(String clusterAlias, TestIndexInfo indexInfo) throws IOException {
101107
final Client client = client(clusterAlias);
102108
final String indexName = indexInfo.name();
109+
final int dataNodeCount = cluster(clusterAlias).numDataNodes();
103110

104111
for (var entry : indexInfo.inferenceEndpoints().entrySet()) {
105112
String inferenceId = entry.getKey();
@@ -117,13 +124,13 @@ protected void setupCluster(String clusterAlias, TestIndexInfo indexInfo) throws
117124
createInferenceEndpoint(client, minimalServiceSettings.taskType(), inferenceId, serviceSettings);
118125
}
119126

120-
Settings indexSettings = indexSettings(randomIntBetween(2, 5), randomIntBetween(0, 1)).build();
127+
Settings indexSettings = indexSettings(randomIntBetween(1, dataNodeCount), 0).build();
121128
assertAcked(client.admin().indices().prepareCreate(indexName).setSettings(indexSettings).setMapping(indexInfo.mappings()));
122129
assertFalse(
123130
client.admin()
124131
.cluster()
125132
.prepareHealth(TEST_REQUEST_TIMEOUT, indexName)
126-
.setWaitForYellowStatus()
133+
.setWaitForGreenStatus()
127134
.setTimeout(TimeValue.timeValueSeconds(10))
128135
.get()
129136
.isTimedOut()
@@ -140,6 +147,18 @@ protected void setupCluster(String clusterAlias, TestIndexInfo indexInfo) throws
140147
assertThat(refreshResponse.getStatus(), is(RestStatus.OK));
141148
}
142149

150+
protected void waitUntilRemoteClusterConnected(String clusterAlias) throws Exception {
151+
RemoteInfoRequest request = new RemoteInfoRequest();
152+
assertBusy(() -> {
153+
RemoteInfoResponse response = client().execute(TransportRemoteInfoAction.TYPE, request).actionGet(TEST_REQUEST_TIMEOUT);
154+
boolean connected = response.getInfos()
155+
.stream()
156+
.filter(i -> i.getClusterAlias().equals(clusterAlias))
157+
.anyMatch(RemoteConnectionInfo::isConnected);
158+
assertThat(connected, is(true));
159+
}, 30, TimeUnit.SECONDS);
160+
}
161+
143162
protected BytesReference openPointInTime(String[] indices, TimeValue keepAlive) {
144163
OpenPointInTimeRequest request = new OpenPointInTimeRequest(indices).keepAlive(keepAlive);
145164
final OpenPointInTimeResponse response = client().execute(TransportOpenPointInTimeAction.TYPE, request).actionGet();

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/search/ccs/MatchQueryBuilderCrossClusterSearchIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.search.builder.SearchSourceBuilder;
1818
import org.junit.Before;
1919

20-
import java.io.IOException;
2120
import java.util.List;
2221
import java.util.Map;
2322
import java.util.Set;
@@ -151,7 +150,7 @@ public void testMatchQueryWithCcsMinimizeRoundTripsFalse() throws Exception {
151150
);
152151
}
153152

154-
private void configureClusters() throws IOException {
153+
private void configureClusters() throws Exception {
155154
final String commonInferenceId = "common-inference-id";
156155
final String localInferenceId = "local-inference-id";
157156
final String remoteInferenceId = "remote-inference-id";

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStore.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.common.settings.Setting;
2323
import org.elasticsearch.common.settings.Setting.Property;
2424
import org.elasticsearch.common.settings.Settings;
25+
import org.elasticsearch.common.util.Maps;
2526
import org.elasticsearch.common.util.concurrent.ReleasableLock;
2627
import org.elasticsearch.common.util.concurrent.ThreadContext;
2728
import org.elasticsearch.common.util.set.Sets;
@@ -670,7 +671,9 @@ Iterable<ProjectScoped<RoleKey>> cachedRoles() {
670671
}
671672

672673
public Map<String, Object> usageStatsWithJustDls() {
673-
return Map.of("dls", Map.of("bit_set_cache", dlsBitsetCache.usageStats()));
674+
final Map<String, Object> usageStats = Maps.newLinkedHashMapWithExpectedSize(1);
675+
usageStats.put("dls", Map.of("bit_set_cache", dlsBitsetCache.usageStats()));
676+
return usageStats; // return LinkedHashMap for deterministic order in transport
674677
}
675678

676679
public void usageStats(ActionListener<Map<String, Object>> listener) {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
import java.util.Collections;
142142
import java.util.HashMap;
143143
import java.util.HashSet;
144+
import java.util.LinkedHashMap;
144145
import java.util.LinkedHashSet;
145146
import java.util.List;
146147
import java.util.Map;
@@ -3754,6 +3755,27 @@ public void testGetRoleDescriptorsListUsesRoleStoreToResolveRoleWithInternalRole
37543755
assertThat(future.actionGet(), equalTo(Set.of(expectedRoleDescriptor)));
37553756
}
37563757

3758+
public void testOrderedUsageStatsWithJustDls() {
3759+
final CompositeRolesStore compositeRolesStore = buildCompositeRolesStore(
3760+
SECURITY_ENABLED_SETTINGS,
3761+
null,
3762+
null,
3763+
null,
3764+
null,
3765+
null,
3766+
null,
3767+
null,
3768+
null,
3769+
null
3770+
);
3771+
3772+
assertThat(
3773+
"needs LinkedHashMap to be ordered in transport",
3774+
compositeRolesStore.usageStatsWithJustDls(),
3775+
instanceOf(LinkedHashMap.class)
3776+
);
3777+
}
3778+
37573779
private Role getRoleForRoleNames(CompositeRolesStore store, String... roleNames) {
37583780
final PlainActionFuture<Role> future = new PlainActionFuture<>();
37593781
getRoleForRoleNames(store, Set.of(roleNames), future);

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ setup:
201201
- gt: { esql.queries._all.total: $all_total_counter }
202202
- match: { esql.queries._all.failed: $all_failed_counter }
203203
- gt: { esql.functions.min: $functions_min }
204-
- gt: { esql.functions.min: $functions_avg_over_time }
204+
- gt: { esql.functions.avg_over_time: $functions_avg_over_time }
205205

206206
# There's one of these per function but that's a ton of things to check. So we just spot check that a few exist.
207207
- exists: esql.functions.delay

0 commit comments

Comments
 (0)