Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move pplenabled to transportaction #2444

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public List<RestHandler> getRestHandlers(
Metrics.getInstance().registerDefaultMetrics();

return Arrays.asList(
new RestPPLQueryAction(pluginSettings, settings),
new RestPPLQueryAction(),
new RestSqlAction(settings, injector),
new RestSqlStatsAction(settings, restController),
new RestPPLStatsAction(settings, restController),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchSecurityException;
Expand All @@ -28,7 +27,6 @@
import org.opensearch.rest.RestChannel;
import org.opensearch.rest.RestRequest;
import org.opensearch.sql.common.antlr.SyntaxCheckException;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.datasources.exceptions.DataSourceClientException;
import org.opensearch.sql.exception.ExpressionEvaluationException;
import org.opensearch.sql.exception.QueryEngineException;
Expand All @@ -49,16 +47,9 @@ public class RestPPLQueryAction extends BaseRestHandler {

private static final Logger LOG = LogManager.getLogger();

private final Supplier<Boolean> pplEnabled;

/** Constructor of RestPPLQueryAction. */
public RestPPLQueryAction(
Settings pluginSettings, org.opensearch.common.settings.Settings clusterSettings) {
public RestPPLQueryAction() {
super();
this.pplEnabled =
() ->
MULTI_ALLOW_EXPLICIT_INDEX.get(clusterSettings)
&& (Boolean) pluginSettings.getSettingValue(Settings.Key.PPL_ENABLED);
}

private static boolean isClientError(Exception e) {
Expand Down Expand Up @@ -104,17 +95,6 @@ protected Set<String> responseParams() {

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient nodeClient) {
// TODO: need move to transport Action
if (!pplEnabled.get()) {
return channel ->
reportError(
channel,
new IllegalAccessException(
"Either plugins.ppl.enabled or rest.action.multi.allow_explicit_index setting is"
+ " false"),
BAD_REQUEST);
}

TransportPPLQueryRequest transportPPLQueryRequest =
new TransportPPLQueryRequest(PPLQueryRequestFactory.getPPLRequest(request));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

package org.opensearch.sql.plugin.transport;

import static org.opensearch.rest.BaseRestHandler.MULTI_ALLOW_EXPLICIT_INDEX;
import static org.opensearch.sql.protocol.response.format.JsonResponseFormatter.Style.PRETTY;

import java.util.Locale;
import java.util.Optional;
import java.util.function.Supplier;
import org.opensearch.action.ActionRequest;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
Expand All @@ -19,6 +21,7 @@
import org.opensearch.common.inject.ModulesBuilder;
import org.opensearch.core.action.ActionListener;
import org.opensearch.sql.common.response.ResponseListener;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.common.utils.QueryContext;
import org.opensearch.sql.datasource.DataSourceService;
import org.opensearch.sql.datasources.service.DataSourceServiceImpl;
Expand Down Expand Up @@ -47,14 +50,17 @@ public class TransportPPLQueryAction

private final Injector injector;

private final Supplier<Boolean> pplEnabled;

/** Constructor of TransportPPLQueryAction. */
@Inject
public TransportPPLQueryAction(
TransportService transportService,
ActionFilters actionFilters,
NodeClient client,
ClusterService clusterService,
DataSourceServiceImpl dataSourceService) {
DataSourceServiceImpl dataSourceService,
org.opensearch.common.settings.Settings clusterSettings) {
super(PPLQueryAction.NAME, transportService, actionFilters, TransportPPLQueryRequest::new);

ModulesBuilder modules = new ModulesBuilder();
Expand All @@ -67,6 +73,13 @@ public TransportPPLQueryAction(
b.bind(DataSourceService.class).toInstance(dataSourceService);
});
this.injector = modules.createInjector();
this.pplEnabled =
() ->
MULTI_ALLOW_EXPLICIT_INDEX.get(clusterSettings)
&& (Boolean)
injector
.getInstance(org.opensearch.sql.common.setting.Settings.class)
.getSettingValue(Settings.Key.PPL_ENABLED);
}

/**
Expand All @@ -76,6 +89,13 @@ public TransportPPLQueryAction(
@Override
protected void doExecute(
Task task, ActionRequest request, ActionListener<TransportPPLQueryResponse> listener) {
if (!pplEnabled.get()) {
listener.onFailure(
new IllegalAccessException(
"Either plugins.ppl.enabled or rest.action.multi.allow_explicit_index setting is"
+ " false"));
return;
}
Metrics.getInstance().getNumericalMetric(MetricName.PPL_REQ_TOTAL).increment();
Metrics.getInstance().getNumericalMetric(MetricName.PPL_REQ_COUNT_TOTAL).increment();

Expand Down
Loading