|
| 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.action.admin.cluster.stats; |
| 11 | + |
| 12 | +import org.elasticsearch.common.settings.Setting; |
| 13 | +import org.elasticsearch.common.settings.Settings; |
| 14 | +import org.elasticsearch.common.util.CollectionUtils; |
| 15 | +import org.elasticsearch.plugins.ClusterPlugin; |
| 16 | +import org.elasticsearch.plugins.Plugin; |
| 17 | +import org.elasticsearch.test.AbstractMultiClustersTestCase; |
| 18 | +import org.hamcrest.Matchers; |
| 19 | + |
| 20 | +import java.util.Collection; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.Optional; |
| 24 | + |
| 25 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse; |
| 26 | + |
| 27 | +// TODO: Move this test to the Serverless repo once the IT framework is ready there. |
| 28 | +public class CpsClusterStatsShouldNotExposeSkipUnavailableIT extends AbstractMultiClustersTestCase { |
| 29 | + private static final String LINKED_CLUSTER_1 = "cluster-a"; |
| 30 | + |
| 31 | + public static class CpsPlugin extends Plugin implements ClusterPlugin { |
| 32 | + @Override |
| 33 | + public List<Setting<?>> getSettings() { |
| 34 | + return List.of(CpsEnableSetting); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + private static final Setting<String> CpsEnableSetting = Setting.simpleString( |
| 39 | + "serverless.cross_project.enabled", |
| 40 | + Setting.Property.NodeScope |
| 41 | + ); |
| 42 | + |
| 43 | + @Override |
| 44 | + protected List<String> remoteClusterAlias() { |
| 45 | + return List.of(LINKED_CLUSTER_1); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + protected Collection<Class<? extends Plugin>> nodePlugins(String clusterAlias) { |
| 50 | + return CollectionUtils.appendToCopy(super.nodePlugins(clusterAlias), CpsPlugin.class); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + protected Settings nodeSettings() { |
| 55 | + return Settings.builder().put(super.nodeSettings()).put("serverless.cross_project.enabled", "true").build(); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + protected Map<String, Boolean> skipUnavailableForRemoteClusters() { |
| 60 | + return Map.of(LINKED_CLUSTER_1, randomBoolean()); |
| 61 | + } |
| 62 | + |
| 63 | + public void testSkipUnavailableShouldNotBeExposed() throws Exception { |
| 64 | + assertResponse( |
| 65 | + client().execute(TransportClusterStatsAction.TYPE, new ClusterStatsRequest(/* Do include remotes */ true)), |
| 66 | + result -> { |
| 67 | + // In CPS environment, skip_unavailable should map to `Optional.empty()`. |
| 68 | + assertThat(result.getRemoteClustersStats().get(LINKED_CLUSTER_1).skipUnavailable(), Matchers.is(Optional.empty())); |
| 69 | + // When this result is serialised to JSON, it should not mention `skip_unavailable`. |
| 70 | + assertThat(result.toString().contains("skip_unavailable"), Matchers.is(false)); |
| 71 | + } |
| 72 | + ); |
| 73 | + } |
| 74 | +} |
0 commit comments