Skip to content

Commit 219b91c

Browse files
Enable conversation memory feature flags (#2095) (#2099)
* Enable conversation memory feature flags Signed-off-by: HenryL27 <[email protected]> * amend feature flag tests Signed-off-by: HenryL27 <[email protected]> * remove accidentally committed files Signed-off-by: HenryL27 <[email protected]> * apply spotless Signed-off-by: HenryL27 <[email protected]> * fix final feature disablement test. whoops Signed-off-by: HenryL27 <[email protected]> * move common feature disablement code to util class Signed-off-by: HenryL27 <[email protected]> --------- Signed-off-by: HenryL27 <[email protected]> (cherry picked from commit 850c748) Co-authored-by: HenryL27 <[email protected]>
1 parent 65ef97e commit 219b91c

File tree

13 files changed

+61
-29
lines changed

13 files changed

+61
-29
lines changed

common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,5 @@ public class ConversationalIndexConstants {
121121

122122
/** Feature Flag setting for conversational memory */
123123
public static final Setting<Boolean> ML_COMMONS_MEMORY_FEATURE_ENABLED = Setting
124-
.boolSetting("plugins.ml_commons.memory_feature_enabled", false, Setting.Property.NodeScope, Setting.Property.Dynamic);
124+
.boolSetting("plugins.ml_commons.memory_feature_enabled", true, Setting.Property.NodeScope, Setting.Property.Dynamic);
125125
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 Aryn
3+
* Copyright OpenSearch Contributors
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.opensearch.ml.memory;
19+
20+
import static org.mockito.Mockito.mock;
21+
import static org.mockito.Mockito.when;
22+
23+
import java.util.Set;
24+
25+
import org.opensearch.cluster.service.ClusterService;
26+
import org.opensearch.common.settings.ClusterSettings;
27+
import org.opensearch.common.settings.Settings;
28+
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
29+
30+
public class MemoryTestUtil {
31+
32+
public static ClusterService clusterServiceWithMemoryFeatureDisabled() {
33+
ClusterService mockClusterService = mock(ClusterService.class);
34+
Settings settings = Settings.builder().put(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey(), false).build();
35+
when(mockClusterService.getSettings()).thenReturn(settings);
36+
when(mockClusterService.getClusterSettings())
37+
.thenReturn(new ClusterSettings(settings, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
38+
return mockClusterService;
39+
}
40+
41+
}

memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.opensearch.core.action.ActionListener;
4242
import org.opensearch.core.xcontent.NamedXContentRegistry;
4343
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
44+
import org.opensearch.ml.memory.MemoryTestUtil;
4445
import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler;
4546
import org.opensearch.test.OpenSearchTestCase;
4647
import org.opensearch.threadpool.ThreadPool;
@@ -154,8 +155,7 @@ public void testDoExecuteFails_thenFail() {
154155
}
155156

156157
public void testFeatureDisabled_ThenFail() {
157-
when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY);
158-
when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
158+
clusterService = MemoryTestUtil.clusterServiceWithMemoryFeatureDisabled();
159159
this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService));
160160

161161
action.doExecute(null, request, actionListener);

memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.opensearch.core.index.shard.ShardId;
4646
import org.opensearch.core.xcontent.NamedXContentRegistry;
4747
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
48+
import org.opensearch.ml.memory.MemoryTestUtil;
4849
import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler;
4950
import org.opensearch.test.OpenSearchTestCase;
5051
import org.opensearch.threadpool.ThreadPool;
@@ -227,8 +228,7 @@ public void testDoExecuteFails_thenFail() {
227228
}
228229

229230
public void testFeatureDisabled_ThenFail() {
230-
when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY);
231-
when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
231+
clusterService = MemoryTestUtil.clusterServiceWithMemoryFeatureDisabled();
232232
this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService));
233233

234234
action.doExecute(null, request, actionListener);

memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.opensearch.core.action.ActionListener;
4141
import org.opensearch.core.xcontent.NamedXContentRegistry;
4242
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
43+
import org.opensearch.ml.memory.MemoryTestUtil;
4344
import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler;
4445
import org.opensearch.test.OpenSearchTestCase;
4546
import org.opensearch.threadpool.ThreadPool;
@@ -138,8 +139,7 @@ public void testdoExecuteFails_thenFail() {
138139
}
139140

140141
public void testFeatureDisabled_ThenFail() {
141-
when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY);
142-
when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
142+
clusterService = MemoryTestUtil.clusterServiceWithMemoryFeatureDisabled();
143143
this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService));
144144

145145
action.doExecute(null, request, actionListener);

memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.opensearch.core.xcontent.NamedXContentRegistry;
4444
import org.opensearch.ml.common.conversation.ConversationMeta;
4545
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
46+
import org.opensearch.ml.memory.MemoryTestUtil;
4647
import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler;
4748
import org.opensearch.test.OpenSearchTestCase;
4849
import org.opensearch.threadpool.ThreadPool;
@@ -138,8 +139,7 @@ public void testHandlerThrows_ThenFail() {
138139
}
139140

140141
public void testFeatureDisabled_ThenFail() {
141-
when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY);
142-
when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
142+
clusterService = MemoryTestUtil.clusterServiceWithMemoryFeatureDisabled();
143143
this.action = spy(new GetConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService));
144144

145145
action.doExecute(null, request, actionListener);

memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.core.xcontent.NamedXContentRegistry;
4545
import org.opensearch.ml.common.conversation.ConversationMeta;
4646
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
47+
import org.opensearch.ml.memory.MemoryTestUtil;
4748
import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler;
4849
import org.opensearch.test.OpenSearchTestCase;
4950
import org.opensearch.threadpool.ThreadPool;
@@ -193,8 +194,7 @@ public void testdoExecuteFails_thenFail() {
193194
}
194195

195196
public void testFeatureDisabled_ThenFail() {
196-
when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY);
197-
when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
197+
clusterService = MemoryTestUtil.clusterServiceWithMemoryFeatureDisabled();
198198
this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService));
199199

200200
action.doExecute(null, request, actionListener);

memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.core.xcontent.NamedXContentRegistry;
4545
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
4646
import org.opensearch.ml.common.conversation.Interaction;
47+
import org.opensearch.ml.memory.MemoryTestUtil;
4748
import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler;
4849
import org.opensearch.test.OpenSearchTestCase;
4950
import org.opensearch.threadpool.ThreadPool;
@@ -147,8 +148,7 @@ public void testHandlerThrows_ThenFail() {
147148
}
148149

149150
public void testFeatureDisabled_ThenFail() {
150-
when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY);
151-
when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
151+
clusterService = MemoryTestUtil.clusterServiceWithMemoryFeatureDisabled();
152152
this.action = spy(new GetInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService));
153153

154154
action.doExecute(null, request, actionListener);

memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.opensearch.core.xcontent.NamedXContentRegistry;
4646
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
4747
import org.opensearch.ml.common.conversation.Interaction;
48+
import org.opensearch.ml.memory.MemoryTestUtil;
4849
import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler;
4950
import org.opensearch.test.OpenSearchTestCase;
5051
import org.opensearch.threadpool.ThreadPool;
@@ -185,8 +186,7 @@ public void testDoExecuteFails_thenFail() {
185186
}
186187

187188
public void testFeatureDisabled_ThenFail() {
188-
when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY);
189-
when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
189+
clusterService = MemoryTestUtil.clusterServiceWithMemoryFeatureDisabled();
190190
this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client, clusterService));
191191

192192
action.doExecute(null, request, actionListener);

memory/src/test/java/org/opensearch/ml/memory/action/conversation/SearchConversationsTransportActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.opensearch.core.action.ActionListener;
4444
import org.opensearch.core.xcontent.NamedXContentRegistry;
4545
import org.opensearch.ml.common.conversation.ConversationalIndexConstants;
46+
import org.opensearch.ml.memory.MemoryTestUtil;
4647
import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler;
4748
import org.opensearch.test.OpenSearchTestCase;
4849
import org.opensearch.threadpool.ThreadPool;
@@ -109,8 +110,7 @@ public void testEnabled_ThenSucceed() {
109110
}
110111

111112
public void testDisabled_ThenFail() {
112-
when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY);
113-
when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED)));
113+
clusterService = MemoryTestUtil.clusterServiceWithMemoryFeatureDisabled();
114114
this.action = spy(new SearchConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService));
115115

116116
action.doExecute(null, request, actionListener);

0 commit comments

Comments
 (0)