-
Notifications
You must be signed in to change notification settings - Fork 58
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
[BUG] [Extensions] Not able to register Routes with similar semantics from RestActions #654
Comments
(Update: Nope, this doesn't fix anything. |
Facing the same issue for Search Detectors: Exception in thread "main" java.lang.IllegalArgumentException: Path [POST /detectors/_search] already has a value [org.opensearch.ad.rest.RestSearchAnomalyDetectorAction@5f8f1712]
at org.opensearch.common.path.PathTrie$TrieNode.insert(PathTrie.java:168)
at org.opensearch.common.path.PathTrie$TrieNode.insert(PathTrie.java:176)
at org.opensearch.common.path.PathTrie$TrieNode.insert(PathTrie.java:176)
at org.opensearch.common.path.PathTrie.insert(PathTrie.java:329)
at org.opensearch.sdk.ExtensionRestPathRegistry.registerHandler(ExtensionRestPathRegistry.java:38)
at org.opensearch.sdk.ExtensionsRunner.<init>(ExtensionsRunner.java:247)
at org.opensearch.sdk.ExtensionsRunner.run(ExtensionsRunner.java:744)
at org.opensearch.ad.AnomalyDetectorExtension.main(AnomalyDetectorExtension.java:612) |
Working on a fix and replicated the same way Temporary workaround: change your rest paths to detectors1 and detectors2 etc. while I sort this out. I don't see how this isn't already failing for plugins with those paths.... |
Is it because plugin is using |
Possibly. I just found |
Nope, the plugins are registering handlers via this code in public void registerHandler(final RestHandler restHandler) {
restHandler.routes().forEach(route -> registerHandler(route.getMethod(), route.getPath(), restHandler));
restHandler.deprecatedRoutes()
.forEach(route -> registerAsDeprecatedHandler(route.getMethod(), route.getPath(), restHandler, route.getDeprecationMessage()));
restHandler.replacedRoutes()
.forEach(
route -> registerWithDeprecatedHandler(
route.getMethod(),
route.getPath(),
restHandler,
route.getDeprecatedMethod(),
route.getDeprecatedPath()
)
);
} That first line protected void registerHandler(RestRequest.Method method, String path, RestHandler handler) {
if (handler instanceof BaseRestHandler) {
usageService.addRestHandler((BaseRestHandler) handler);
}
registerHandlerNoWrap(method, path, handlerWrapper.apply(handler));
} Which then calls:
I have exactly replicated this last method and it fails, and looks like it is expected to fail. |
I see. For Search, there are 3 RestActions extending the same AbstractSearchAction and registering the routes like this and this. |
The issue you're facing in Search (already has a value) is different than the wildcard issue (conflicting wildcards). |
OK, so this does have to do with ReplacedRoutes. The path indicated for Get Detector in the initial post here doesn't match the plugin.
But plugin has: @Override
public List<Route> routes() {
return ImmutableList
.of(
// Opensearch-only API. Considering users may provide entity in the search body, support POST as well.
new Route(
RestRequest.Method.POST,
String.format(Locale.ROOT, "%s/{%s}/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID, PROFILE)
),
new Route(
RestRequest.Method.POST,
String.format(Locale.ROOT, "%s/{%s}/%s/{%s}", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID, PROFILE, TYPE)
)
);
} The shorter URL is the replaced routes "alias" for it. |
So, wrapping this up:
|
So deprecated and replaced routes just register additional routes and don't fix this (perceived) problem. It's good to add them but they aren't a bug fix. Because there's no bug. :)
Stats does not use The route is not |
Hardcoded paths ( |
What is the bug?
The get detector has the following route.
The detector stats API requires following route to be registered.
However, the routes for stats API cannot be registered due to the error mentioned below
How can one reproduce the bug?
We can reproduce the bug by trying to register any path which has
/detectors/{anyValue}
What is the expected behavior?
The extensions framework should allow registering the impacted routes
Do you have any additional context?
I think the problem is with using Trie data structure in registering paths. Boiling down it is not able to differentiate between the key of two paths.
The text was updated successfully, but these errors were encountered: