|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.esql.action; |
9 | 9 |
|
10 | | -import org.apache.logging.log4j.LogManager; |
11 | | -import org.apache.logging.log4j.Logger; |
12 | | -import org.elasticsearch.action.admin.cluster.stats.CCSTelemetrySnapshot; |
13 | | -import org.elasticsearch.client.internal.Client; |
14 | | -import org.elasticsearch.common.settings.Settings; |
15 | 10 | import org.elasticsearch.plugins.Plugin; |
16 | | -import org.elasticsearch.tasks.Task; |
17 | | -import org.elasticsearch.test.AbstractMultiClustersTestCase; |
18 | | -import org.elasticsearch.test.SkipUnavailableRule; |
19 | | -import org.elasticsearch.usage.UsageService; |
20 | | -import org.junit.Assert; |
21 | | -import org.junit.Rule; |
22 | 11 |
|
23 | 12 | import java.util.ArrayList; |
24 | 13 | import java.util.Collection; |
25 | | -import java.util.HashMap; |
26 | 14 | import java.util.List; |
27 | | -import java.util.Map; |
28 | | -import java.util.concurrent.ExecutionException; |
29 | 15 |
|
30 | 16 | import static org.elasticsearch.action.admin.cluster.stats.CCSUsageTelemetry.ASYNC_FEATURE; |
31 | | -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
32 | | -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse; |
33 | 17 | import static org.hamcrest.Matchers.equalTo; |
34 | 18 |
|
35 | | -public class CrossClustersUsageTelemetryIT extends AbstractMultiClustersTestCase { |
36 | | - private static final Logger LOGGER = LogManager.getLogger(CrossClustersUsageTelemetryIT.class); |
37 | | - private static final String REMOTE1 = "cluster-a"; |
38 | | - private static final String REMOTE2 = "cluster-b"; |
39 | | - private static final String LOCAL_INDEX = "logs-1"; |
40 | | - private static final String REMOTE_INDEX = "logs-2"; |
| 19 | +public class CrossClustersUsageTelemetryIT extends AbstractCrossClustersUsageTelemetryIT { |
| 20 | + |
| 21 | + @Override |
| 22 | + protected Collection<Class<? extends Plugin>> nodePlugins(String clusterAlias) { |
| 23 | + List<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins(clusterAlias)); |
| 24 | + plugins.add(EsqlPluginWithEnterpriseOrTrialLicense.class); |
| 25 | + plugins.add(CrossClustersQueryIT.InternalExchangePlugin.class); |
| 26 | + return plugins; |
| 27 | + } |
41 | 28 |
|
42 | 29 | public void testLocalRemote() throws Exception { |
43 | 30 | setupClusters(); |
@@ -66,137 +53,4 @@ public void testLocalRemote() throws Exception { |
66 | 53 | } |
67 | 54 |
|
68 | 55 | } |
69 | | - |
70 | | - protected CCSTelemetrySnapshot getTelemetryFromQuery(String query, String client) throws ExecutionException, InterruptedException { |
71 | | - EsqlQueryRequest request = EsqlQueryRequest.syncEsqlQueryRequest(); |
72 | | - request.query(query); |
73 | | - request.pragmas(AbstractEsqlIntegTestCase.randomPragmas()); |
74 | | - request.columnar(randomBoolean()); |
75 | | - request.includeCCSMetadata(randomBoolean()); |
76 | | - return getTelemetryFromQuery(request, client); |
77 | | - } |
78 | | - |
79 | | - protected CCSTelemetrySnapshot getTelemetryFromQuery(EsqlQueryRequest request, String client) throws ExecutionException, |
80 | | - InterruptedException { |
81 | | - // We want to send search to a specific node (we don't care which one) so that we could |
82 | | - // collect the CCS telemetry from it later |
83 | | - String nodeName = cluster(LOCAL_CLUSTER).getRandomNodeName(); |
84 | | - // We don't care here too much about the response, we just want to trigger the telemetry collection. |
85 | | - // So we check it's not null and leave the rest to other tests. |
86 | | - if (client != null) { |
87 | | - assertResponse( |
88 | | - cluster(LOCAL_CLUSTER).client(nodeName) |
89 | | - .filterWithHeader(Map.of(Task.X_ELASTIC_PRODUCT_ORIGIN_HTTP_HEADER, client)) |
90 | | - .execute(EsqlQueryAction.INSTANCE, request), |
91 | | - Assert::assertNotNull |
92 | | - ); |
93 | | - |
94 | | - } else { |
95 | | - assertResponse(cluster(LOCAL_CLUSTER).client(nodeName).execute(EsqlQueryAction.INSTANCE, request), Assert::assertNotNull); |
96 | | - } |
97 | | - return getTelemetrySnapshot(nodeName); |
98 | | - } |
99 | | - |
100 | | - protected CCSTelemetrySnapshot getTelemetryFromFailedQuery(String query) throws Exception { |
101 | | - // We want to send search to a specific node (we don't care which one) so that we could |
102 | | - // collect the CCS telemetry from it later |
103 | | - String nodeName = cluster(LOCAL_CLUSTER).getRandomNodeName(); |
104 | | - EsqlQueryRequest request = EsqlQueryRequest.syncEsqlQueryRequest(); |
105 | | - request.query(query); |
106 | | - request.pragmas(AbstractEsqlIntegTestCase.randomPragmas()); |
107 | | - request.columnar(randomBoolean()); |
108 | | - request.includeCCSMetadata(randomBoolean()); |
109 | | - |
110 | | - ExecutionException ee = expectThrows( |
111 | | - ExecutionException.class, |
112 | | - cluster(LOCAL_CLUSTER).client(nodeName).execute(EsqlQueryAction.INSTANCE, request)::get |
113 | | - ); |
114 | | - assertNotNull(ee.getCause()); |
115 | | - |
116 | | - return getTelemetrySnapshot(nodeName); |
117 | | - } |
118 | | - |
119 | | - private CCSTelemetrySnapshot getTelemetrySnapshot(String nodeName) { |
120 | | - var usage = cluster(LOCAL_CLUSTER).getInstance(UsageService.class, nodeName); |
121 | | - return usage.getEsqlUsageHolder().getCCSTelemetrySnapshot(); |
122 | | - } |
123 | | - |
124 | | - @Override |
125 | | - protected boolean reuseClusters() { |
126 | | - return false; |
127 | | - } |
128 | | - |
129 | | - @Override |
130 | | - protected List<String> remoteClusterAlias() { |
131 | | - return List.of(REMOTE1, REMOTE2); |
132 | | - } |
133 | | - |
134 | | - @Rule |
135 | | - public SkipUnavailableRule skipOverride = new SkipUnavailableRule(REMOTE1, REMOTE2); |
136 | | - |
137 | | - protected Map<String, Object> setupClusters() { |
138 | | - int numShardsLocal = randomIntBetween(1, 5); |
139 | | - populateLocalIndices(LOCAL_INDEX, numShardsLocal); |
140 | | - |
141 | | - int numShardsRemote = randomIntBetween(1, 5); |
142 | | - populateRemoteIndices(REMOTE1, REMOTE_INDEX, numShardsRemote); |
143 | | - |
144 | | - Map<String, Object> clusterInfo = new HashMap<>(); |
145 | | - clusterInfo.put("local.num_shards", numShardsLocal); |
146 | | - clusterInfo.put("local.index", LOCAL_INDEX); |
147 | | - clusterInfo.put("remote.num_shards", numShardsRemote); |
148 | | - clusterInfo.put("remote.index", REMOTE_INDEX); |
149 | | - |
150 | | - int numShardsRemote2 = randomIntBetween(1, 5); |
151 | | - populateRemoteIndices(REMOTE2, REMOTE_INDEX, numShardsRemote2); |
152 | | - clusterInfo.put("remote2.index", REMOTE_INDEX); |
153 | | - clusterInfo.put("remote2.num_shards", numShardsRemote2); |
154 | | - |
155 | | - return clusterInfo; |
156 | | - } |
157 | | - |
158 | | - void populateLocalIndices(String indexName, int numShards) { |
159 | | - Client localClient = client(LOCAL_CLUSTER); |
160 | | - assertAcked( |
161 | | - localClient.admin() |
162 | | - .indices() |
163 | | - .prepareCreate(indexName) |
164 | | - .setSettings(Settings.builder().put("index.number_of_shards", numShards)) |
165 | | - .setMapping("id", "type=keyword", "tag", "type=keyword", "v", "type=long") |
166 | | - ); |
167 | | - for (int i = 0; i < 10; i++) { |
168 | | - localClient.prepareIndex(indexName).setSource("id", "local-" + i, "tag", "local", "v", i).get(); |
169 | | - } |
170 | | - localClient.admin().indices().prepareRefresh(indexName).get(); |
171 | | - } |
172 | | - |
173 | | - void populateRemoteIndices(String clusterAlias, String indexName, int numShards) { |
174 | | - Client remoteClient = client(clusterAlias); |
175 | | - assertAcked( |
176 | | - remoteClient.admin() |
177 | | - .indices() |
178 | | - .prepareCreate(indexName) |
179 | | - .setSettings(Settings.builder().put("index.number_of_shards", numShards)) |
180 | | - .setMapping("id", "type=keyword", "tag", "type=keyword", "v", "type=long") |
181 | | - ); |
182 | | - for (int i = 0; i < 10; i++) { |
183 | | - remoteClient.prepareIndex(indexName).setSource("id", "remote-" + i, "tag", "remote", "v", i * i).get(); |
184 | | - } |
185 | | - remoteClient.admin().indices().prepareRefresh(indexName).get(); |
186 | | - } |
187 | | - |
188 | | - @Override |
189 | | - protected Collection<Class<? extends Plugin>> nodePlugins(String clusterAlias) { |
190 | | - List<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins(clusterAlias)); |
191 | | - plugins.add(EsqlPluginWithEnterpriseOrTrialLicense.class); |
192 | | - plugins.add(CrossClustersQueryIT.InternalExchangePlugin.class); |
193 | | - return plugins; |
194 | | - } |
195 | | - |
196 | | - @Override |
197 | | - protected Map<String, Boolean> skipUnavailableForRemoteClusters() { |
198 | | - var map = skipOverride.getMap(); |
199 | | - LOGGER.info("Using skip_unavailable map: [{}]", map); |
200 | | - return map; |
201 | | - } |
202 | 56 | } |
0 commit comments