Skip to content

Commit

Permalink
Move pplenabled to transport (#2451) (#2455)
Browse files Browse the repository at this point in the history
* move pplenabled to transportaction



* Fix IT failure and format code



* Fix failure IT



---------


(cherry picked from commit 797276d)

Signed-off-by: zane-neo <zaniu@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 636d323 commit 894639a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/user/ppl/admin/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ PPL query::

sh$ curl -sS -H 'Content-Type: application/json' \
... -X POST localhost:9200/_plugins/_ppl \
... -d '{"query": "source=my_prometheus"}'
{
"error": {
"reason": "Invalid Query",
Expand Down
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

0 comments on commit 894639a

Please sign in to comment.