Skip to content

Commit fc9ae93

Browse files
authored
[Backport] Remove ppl tool execution setting (#383)
* Remove ppl tool execution setting Signed-off-by: zane-neo <[email protected]> * fix failure UTs Signed-off-by: zane-neo <[email protected]> * backport 381 to 2.x Signed-off-by: zane-neo <[email protected]> --------- Signed-off-by: zane-neo <[email protected]>
1 parent c52dbea commit fc9ae93

File tree

7 files changed

+5
-131
lines changed

7 files changed

+5
-131
lines changed

src/main/java/org/opensearch/agent/ToolPlugin.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.List;
1111
import java.util.function.Supplier;
1212

13-
import org.opensearch.agent.common.SkillSettings;
1413
import org.opensearch.agent.tools.CreateAnomalyDetectorTool;
1514
import org.opensearch.agent.tools.NeuralSparseSearchTool;
1615
import org.opensearch.agent.tools.PPLTool;
@@ -20,12 +19,9 @@
2019
import org.opensearch.agent.tools.SearchAnomalyResultsTool;
2120
import org.opensearch.agent.tools.SearchMonitorsTool;
2221
import org.opensearch.agent.tools.VectorDBTool;
23-
import org.opensearch.agent.tools.utils.ClusterSettingHelper;
2422
import org.opensearch.client.Client;
2523
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
2624
import org.opensearch.cluster.service.ClusterService;
27-
import org.opensearch.common.settings.Setting;
28-
import org.opensearch.common.settings.Settings;
2925
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
3026
import org.opensearch.core.xcontent.NamedXContentRegistry;
3127
import org.opensearch.env.Environment;
@@ -64,9 +60,7 @@ public Collection<Object> createComponents(
6460
this.client = client;
6561
this.clusterService = clusterService;
6662
this.xContentRegistry = xContentRegistry;
67-
Settings settings = environment.settings();
68-
ClusterSettingHelper clusterSettingHelper = new ClusterSettingHelper(settings, clusterService);
69-
PPLTool.Factory.getInstance().init(client, clusterSettingHelper);
63+
PPLTool.Factory.getInstance().init(client);
7064
NeuralSparseSearchTool.Factory.getInstance().init(client, xContentRegistry);
7165
VectorDBTool.Factory.getInstance().init(client, xContentRegistry);
7266
RAGTool.Factory.getInstance().init(client, xContentRegistry);
@@ -94,8 +88,4 @@ public List<Tool.Factory<? extends Tool>> getToolFactories() {
9488
);
9589
}
9690

97-
@Override
98-
public List<Setting<?>> getSettings() {
99-
return List.of(SkillSettings.PPL_EXECUTION_ENABLED);
100-
}
10191
}

src/main/java/org/opensearch/agent/common/SkillSettings.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/main/java/org/opensearch/agent/tools/PPLTool.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import org.opensearch.action.ActionRequest;
3232
import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest;
3333
import org.opensearch.action.search.SearchRequest;
34-
import org.opensearch.agent.common.SkillSettings;
35-
import org.opensearch.agent.tools.utils.ClusterSettingHelper;
3634
import org.opensearch.agent.tools.utils.ToolHelper;
3735
import org.opensearch.client.Client;
3836
import org.opensearch.cluster.metadata.MappingMetadata;
@@ -98,9 +96,7 @@ public class PPLTool implements Tool {
9896

9997
private int head;
10098

101-
private ClusterSettingHelper clusterSettingHelper;
102-
103-
private static Gson gson = new Gson();
99+
private static Gson gson = org.opensearch.ml.common.utils.StringUtils.gson;
104100

105101
private static Map<String, String> DEFAULT_PROMPT_DICT;
106102

@@ -153,7 +149,6 @@ public static PPLModelType from(String value) {
153149

154150
public PPLTool(
155151
Client client,
156-
ClusterSettingHelper clusterSettingHelper,
157152
String modelId,
158153
String contextPrompt,
159154
String pplModelType,
@@ -172,7 +167,6 @@ public PPLTool(
172167
this.previousToolKey = previousToolKey;
173168
this.head = head;
174169
this.execute = execute;
175-
this.clusterSettingHelper = clusterSettingHelper;
176170
}
177171

178172
@SuppressWarnings("unchecked")
@@ -222,14 +216,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
222216
ModelTensor modelTensor = modelTensors.getMlModelTensors().get(0);
223217
Map<String, String> dataAsMap = (Map<String, String>) modelTensor.getDataAsMap();
224218
String ppl = parseOutput(dataAsMap.get("response"), indexName);
225-
boolean pplExecutedEnabled = clusterSettingHelper.getClusterSettings(SkillSettings.PPL_EXECUTION_ENABLED);
226-
if (!pplExecutedEnabled || !this.execute) {
227-
if (!pplExecutedEnabled) {
228-
log
229-
.debug(
230-
"PPL execution is disabled, the query will be returned directly, to enable this, please set plugins.skills.ppl_execution_enabled to true"
231-
);
232-
}
219+
if (!this.execute) {
233220
Map<String, String> ret = ImmutableMap.of("ppl", ppl);
234221
listener.onResponse((T) AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> gson.toJson(ret)));
235222
return;
@@ -298,8 +285,6 @@ public boolean validate(Map<String, String> parameters) {
298285
public static class Factory implements Tool.Factory<PPLTool> {
299286
private Client client;
300287

301-
private ClusterSettingHelper clusterSettingHelper;
302-
303288
private static Factory INSTANCE;
304289

305290
public static Factory getInstance() {
@@ -315,17 +300,15 @@ public static Factory getInstance() {
315300
}
316301
}
317302

318-
public void init(Client client, ClusterSettingHelper clusterSettingHelper) {
303+
public void init(Client client) {
319304
this.client = client;
320-
this.clusterSettingHelper = clusterSettingHelper;
321305
}
322306

323307
@Override
324308
public PPLTool create(Map<String, Object> map) {
325309
validatePPLToolParameters(map);
326310
return new PPLTool(
327311
client,
328-
clusterSettingHelper,
329312
(String) map.get("model_id"),
330313
(String) map.getOrDefault("prompt", ""),
331314
(String) map.getOrDefault("model_type", ""),

src/main/java/org/opensearch/agent/tools/utils/ClusterSettingHelper.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/test/java/org/opensearch/agent/tools/PPLToolTests.java

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
import static org.mockito.ArgumentMatchers.any;
1010
import static org.mockito.ArgumentMatchers.eq;
1111
import static org.mockito.Mockito.doAnswer;
12-
import static org.mockito.Mockito.mock;
1312
import static org.mockito.Mockito.when;
1413
import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX;
1514
import static org.opensearch.ml.common.utils.StringUtils.gson;
1615

1716
import java.util.Collections;
1817
import java.util.HashMap;
1918
import java.util.Map;
20-
import java.util.Set;
2119

2220
import org.apache.lucene.search.TotalHits;
2321
import org.junit.Before;
@@ -26,15 +24,10 @@
2624
import org.mockito.MockitoAnnotations;
2725
import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse;
2826
import org.opensearch.action.search.SearchResponse;
29-
import org.opensearch.agent.common.SkillSettings;
30-
import org.opensearch.agent.tools.utils.ClusterSettingHelper;
3127
import org.opensearch.client.AdminClient;
3228
import org.opensearch.client.Client;
3329
import org.opensearch.client.IndicesAdminClient;
3430
import org.opensearch.cluster.metadata.MappingMetadata;
35-
import org.opensearch.cluster.service.ClusterService;
36-
import org.opensearch.common.settings.ClusterSettings;
37-
import org.opensearch.common.settings.Settings;
3831
import org.opensearch.core.action.ActionListener;
3932
import org.opensearch.core.common.bytes.BytesArray;
4033
import org.opensearch.core.common.bytes.BytesReference;
@@ -128,13 +121,7 @@ public void setup() {
128121
listener.onResponse(transportPPLQueryResponse);
129122
return null;
130123
}).when(client).execute(eq(PPLQueryAction.INSTANCE), any(), any());
131-
132-
Settings settings = Settings.builder().put(SkillSettings.PPL_EXECUTION_ENABLED.getKey(), true).build();
133-
ClusterService clusterService = mock(ClusterService.class);
134-
when(clusterService.getSettings()).thenReturn(settings);
135-
when(clusterService.getClusterSettings()).thenReturn(new ClusterSettings(settings, Set.of(SkillSettings.PPL_EXECUTION_ENABLED)));
136-
ClusterSettingHelper clusterSettingHelper = new ClusterSettingHelper(settings, clusterService);
137-
PPLTool.Factory.getInstance().init(client, clusterSettingHelper);
124+
PPLTool.Factory.getInstance().init(client);
138125
}
139126

140127
@Test
@@ -413,26 +400,6 @@ public void testTool_executePPLFailure() {
413400
);
414401
}
415402

416-
@Test
417-
public void test_pplTool_whenPPLExecutionDisabled_returnOnlyContainsPPL() {
418-
Settings settings = Settings.builder().put(SkillSettings.PPL_EXECUTION_ENABLED.getKey(), false).build();
419-
ClusterService clusterService = mock(ClusterService.class);
420-
when(clusterService.getSettings()).thenReturn(settings);
421-
when(clusterService.getClusterSettings()).thenReturn(new ClusterSettings(settings, Set.of(SkillSettings.PPL_EXECUTION_ENABLED)));
422-
ClusterSettingHelper clusterSettingHelper = new ClusterSettingHelper(settings, clusterService);
423-
PPLTool.Factory.getInstance().init(client, clusterSettingHelper);
424-
PPLTool tool = PPLTool.Factory
425-
.getInstance()
426-
.create(ImmutableMap.of("model_id", "modelId", "prompt", "contextPrompt", "head", "100"));
427-
assertEquals(PPLTool.TYPE, tool.getName());
428-
429-
tool.run(ImmutableMap.of("index", "demo", "question", "demo"), ActionListener.<String>wrap(executePPLResult -> {
430-
Map<String, String> returnResults = gson.fromJson(executePPLResult, Map.class);
431-
assertNull(returnResults.get("executionResult"));
432-
assertEquals("source=demo| head 1", returnResults.get("ppl"));
433-
}, log::error));
434-
}
435-
436403
private void createMappings() {
437404
indexMappings = new HashMap<>();
438405
indexMappings

src/test/java/org/opensearch/integTest/BaseAgentToolsIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void updateClusterSettings() {
6363
updateClusterSettings("plugins.ml_commons.jvm_heap_memory_threshold", 100);
6464
updateClusterSettings("plugins.ml_commons.allow_registering_model_via_url", true);
6565
updateClusterSettings("plugins.ml_commons.agent_framework_enabled", true);
66-
updateClusterSettings("plugins.skills.ppl_execution_enabled", true);
6766
}
6867

6968
@SneakyThrows

src/test/java/org/opensearch/integTest/PPLToolIT.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ public void testPPLTool() {
5858
);
5959
}
6060

61-
public void test_PPLTool_whenPPLExecutionDisabled_ResultOnlyContainsPPL() {
62-
updateClusterSettings("plugins.skills.ppl_execution_enabled", false);
63-
prepareIndex();
64-
String agentId = registerAgent();
65-
String result = executeAgent(agentId, "{\"parameters\": {\"question\": \"correct\", \"index\": \"employee\"}}");
66-
assertEquals("{\"ppl\":\"source\\u003demployee| where age \\u003e 56 | stats COUNT() as cnt\"}", result);
67-
}
68-
6961
public void testPPLTool_withWrongPPLGenerated_thenThrowException() {
7062
prepareIndex();
7163
String agentId = registerAgent();

0 commit comments

Comments
 (0)