Skip to content

Commit

Permalink
Convert to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Oct 1, 2024
1 parent 2469a9c commit 2dd80ba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.FeatureFlag;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
Expand All @@ -23,7 +22,6 @@
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.InternalTestCluster;
import org.junit.Assert;
import org.junit.BeforeClass;

import java.util.Collection;
import java.util.List;
Expand All @@ -46,7 +44,6 @@ public class ClusterStatsRemoteIT extends AbstractMultiClustersTestCase {
private static final String REMOTE2 = "cluster-b";

private static final String INDEX_NAME = "demo";
private static final FeatureFlag CCS_TELEMETRY_FEATURE_FLAG = new FeatureFlag("ccs_telemetry");

@Override
protected boolean reuseClusters() {
Expand All @@ -63,11 +60,6 @@ protected Map<String, Boolean> skipUnavailableForRemoteClusters() {
return Map.of(REMOTE1, false, REMOTE2, true);
}

@BeforeClass
protected static void skipIfTelemetryDisabled() {
assumeTrue("Skipping test as CCS_TELEMETRY_FEATURE_FLAG is disabled", CCS_TELEMETRY_FEATURE_FLAG.isEnabled());
}

public void testRemoteClusterStats() throws ExecutionException, InterruptedException {
setupClusters();
final Client client = client(LOCAL_CLUSTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CancellableSingleObjectCache;
import org.elasticsearch.common.util.concurrent.ThreadContext;
Expand Down Expand Up @@ -98,6 +99,13 @@ public class TransportClusterStatsAction extends TransportNodesAction<
);
private static final Logger logger = LogManager.getLogger(TransportClusterStatsAction.class);

public static final Setting<Boolean> REMOTE_STATS = Setting.boolSetting(
"stats.ccs.remote_stats",
true,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);

private final Settings settings;
private final NodeService nodeService;
private final IndicesService indicesService;
Expand Down Expand Up @@ -431,8 +439,8 @@ public Map<String, RemoteClusterStats> getRemoteStats() {
}
}

private static boolean doRemotes(ClusterStatsRequest request) {
return request.doRemotes();
private boolean doRemotes(ClusterStatsRequest request) {
return REMOTE_STATS.get(settings) && request.doRemotes();
}

private class RemoteStatsFanout extends CancellableFanOut<String, RemoteClusterStatsResponse, Map<String, RemoteClusterStats>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.ArrayUtils;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.util.Maps;
Expand Down Expand Up @@ -159,6 +160,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
private final SearchResponseMetrics searchResponseMetrics;
private final Client client;
private final UsageService usageService;
private final Settings settings;

@Inject
public TransportSearchAction(
Expand Down Expand Up @@ -191,8 +193,9 @@ public TransportSearchAction(
this.indexNameExpressionResolver = indexNameExpressionResolver;
this.namedWriteableRegistry = namedWriteableRegistry;
this.executorSelector = executorSelector;
this.defaultPreFilterShardSize = DEFAULT_PRE_FILTER_SHARD_SIZE.get(clusterService.getSettings());
this.ccsCheckCompatibility = SearchService.CCS_VERSION_CHECK_SETTING.get(clusterService.getSettings());
this.settings = clusterService.getSettings();
this.defaultPreFilterShardSize = DEFAULT_PRE_FILTER_SHARD_SIZE.get(settings);
this.ccsCheckCompatibility = SearchService.CCS_VERSION_CHECK_SETTING.get(settings);
this.searchResponseMetrics = searchResponseMetrics;
this.client = client;
this.usageService = usageService;
Expand Down Expand Up @@ -1863,7 +1866,7 @@ private class SearchResponseActionListener implements ActionListener<SearchRespo
* Should we collect telemetry for this search?
*/
private boolean collectTelemetry() {
return usageBuilder.getRemotesCount() > 0;
return SearchService.CCS_COLLECT_TELEMETRY.get(settings) && usageBuilder.getRemotesCount() > 0;
}

public void setRemotes(int count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class RestClusterStatsAction extends BaseRestHandler {

private static final Set<String> SUPPORTED_CAPABILITIES = Set.of(
"human-readable-total-docs-size",
"verbose-dense-vector-mapping-stats", "ccs-stats"
"verbose-dense-vector-mapping-stats",
"ccs-stats"
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
Property.NodeScope
);

public static final Setting<Boolean> CCS_COLLECT_TELEMETRY = Setting.boolSetting(
"search.ccs.collect_telemetry",
true,
Property.Dynamic,
Property.NodeScope
);

public static final int DEFAULT_SIZE = 10;
public static final int DEFAULT_FROM = 0;

Expand Down

0 comments on commit 2dd80ba

Please sign in to comment.