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

Add feature flag for QueryPhaseSearcher #214

Conversation

martin-gaievski
Copy link
Member

@martin-gaievski martin-gaievski commented Jul 12, 2023

Description

Added feature flag neural_search_hybrid_search_enabled for query phase searcher. This is required as a safeguard in case concurrent search feature is enabled and another implementation of query phase searcher is registered.
This new flag can be set as system property or in opensearch.yml (with use of transport.features), by default flag is false (feature is disabled). Enable flag for integ tests.

Issues Resolved

#194

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has javadoc added
  • Commits are signed as per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
* and false otherwise.
* Checks alternative flag names as they may be different for plugins
*/
public static boolean isEnabled(String featureFlagName) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to try "transport" feature prefix, as this is the way core adding features that are set in plugins.

Copy link
Collaborator

@heemin32 heemin32 Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why both? Shouldn't we only check with "transport" feature prefix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to encapsulate that logic so client can do only one call. Otherwise on a client we need to do two calls:
featureFlags.isEnabled(flag) || customFeatureFlags.isEnabled(flag). Depending on scenario one feature flag can be set in one form or another (with or without prefix)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it is client's responsibility to pass correct key. In this case transport.features.neural_search_hybrid_search_enabled.

There is no such case that neural_search_hybrid_search_enabled can be enabled by setting neural_search_hybrid_search_enabled as true but only by setting transport.features.neural_search_hybrid_search_enabled as true I believe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, it can be that flag is set in two places and as we read it with OR and one that set in plugin is always TRUE then we cannot set it to FALSE ever. I'll rework to only use one name or another, in fact it should be always with the prefix except the definition.

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
@martin-gaievski martin-gaievski marked this pull request as ready for review July 12, 2023 18:44
@martin-gaievski martin-gaievski changed the title Add feature flag Add feature flag for QueryPhaseSearcher Jul 12, 2023
* and false otherwise.
* Checks alternative flag names as they may be different for plugins
*/
public static boolean isEnabled(String featureFlagName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static boolean isEnabled(String featureFlagName) {
public static boolean isEnabled(final String featureFlagName) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

* and false otherwise.
* Checks alternative flag names as they may be different for plugins
*/
public static boolean isEnabled(String featureFlagName) {
Copy link
Collaborator

@heemin32 heemin32 Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why both? Shouldn't we only check with "transport" feature prefix?

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #214 (86b51f5) into feature/normalization (7dda0c5) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@                     Coverage Diff                     @@
##             feature/normalization     #214      +/-   ##
===========================================================
+ Coverage                    84.91%   84.95%   +0.04%     
- Complexity                     215      216       +1     
===========================================================
  Files                           15       15              
  Lines                          676      678       +2     
  Branches                       109      109              
===========================================================
+ Hits                           574      576       +2     
  Misses                          60       60              
  Partials                        42       42              
Impacted Files Coverage Δ
...nsearch/neuralsearch/query/HybridQueryBuilder.java 72.64% <ø> (ø)
...nsearch/neuralsearch/query/NeuralQueryBuilder.java 89.01% <ø> (ø)
...g/opensearch/neuralsearch/plugin/NeuralSearch.java 77.77% <100.00%> (+6.34%) ⬆️

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
@martin-gaievski martin-gaievski requested a review from heemin32 July 12, 2023 22:37
@@ -50,9 +52,14 @@ public class NeuralSearch extends Plugin implements ActionPlugin, SearchPlugin,
* Gates the functionality of hybrid search
* Currently query phase searcher added with hybrid search will conflict with concurrent search in core.
* Once that problem is resolved this feature flag can be removed.
* Key is the name string, value is key + transport feature specific prefix, prefix is added by core when we register feature
* We need to write and read by the value, key is only for definition
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this previous comment having a code link to core was good and would be nice to have it here.
https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/plugins/PluginsService.java#L277

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
@navneet1v
Copy link
Collaborator

This new flag can be set as system property or in opensearch.yml (with use of transport.features), by default flag is true (or enabled).

Why we want to make it by default true? This is strange? Can we make this false for now. and then take a decision what needs to be done.

@martin-gaievski
Copy link
Member Author

This new flag can be set as system property or in opensearch.yml (with use of transport.features), by default flag is true (or enabled).

Why we want to make it by default true? This is strange? Can we make this false for now. and then take a decision what needs to be done.

We can only make the feature "true" with this approach, but I think you mean it's not about the exact value, but we need to interpret that default "true" as feature is disabled, is that what you mean? In other words user need to opt-in explicitly, rather that opt-out with current approach

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Comment on lines 54 to 55
@VisibleForTesting
public static final Pair<String, String> NEURAL_SEARCH_HYBRID_SEARCH_DISABLED = Pair.of(
"neural_search_hybrid_search_disabled",
String.join(".", TransportSettings.FEATURE_PREFIX, "neural_search_hybrid_search_disabled")
);
public static final String NEURAL_SEARCH_HYBRID_SEARCH_ENABLED = "neural_search_hybrid_search_enabled";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is already public we can remove @VisbleForTesting

Copy link
Member Author

@martin-gaievski martin-gaievski Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it public only because it's required for tests otherwise private will be enough, my understanding is that @VisbleForTesting is required in this case to mark that it's intentional.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh.. sorry my bad. I read it wrong then

@@ -42,15 +42,15 @@ public void testQueryPhaseSearcher() {
assertNotNull(queryPhaseSearcher);
assertTrue(queryPhaseSearcher.isEmpty());

System.setProperty(NEURAL_SEARCH_HYBRID_SEARCH_DISABLED.getValue(), "true");
System.setProperty(NEURAL_SEARCH_HYBRID_SEARCH_ENABLED, "true");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we set this property in base class?

and why test are extending OpenSearchTestCase, there is should be a base Neural Search test class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that for some unit tests we may want to disable it, that would be complex if it's set in base class.

I'll make setting in a method and will call it in a setup phase for this test class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@navneet1v
Copy link
Collaborator

happy to see all checks succeeding. This is happening after a long time

@navneet1v
Copy link
Collaborator

@martin-gaievski tests are failing.

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
@martin-gaievski martin-gaievski merged commit c4d0a0c into opensearch-project:feature/normalization Jul 14, 2023
martin-gaievski added a commit that referenced this pull request Aug 3, 2023
* Adding hybrid_search_enabled settings

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants