-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat: Add request plugin capability #25864
Conversation
Adds the request plugin type. Triggers can be bound to an API endpoint at /api/v3/engine/<path>. Requests will get yielded to the plugin with the query parameters, request parameters, and request body. I didn't implement the test endpoint for this plugin type as it seems much more natural for users to save the file and make a new request. Once #25863 is done it'll make it very easy. Closes #25862
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are inconsistencies around the python return type that I presume came up as you iterated. The example in test_request_plugin_and_trigger()
returns
return 200, {"Content-Type": "application/json"}, json.dumps({"status": "ok", "line": line_str})
While the error message in MissingProcessRequestFunction
says it should be
Tuple[str, Optional[Dict[str, str]]]
. And then in execute_request_trigger
it'll fail if the result does not have 3 items, addressable via get_item()
.
Additionally, I think it might be clean to follow some of Flask's semantics in terms of what we support. The quickstart docs specify it at https://flask.palletsprojects.com/en/stable/quickstart/#about-responses. For our purpose, I'm not sure we should try and support (1) a full Response being returned or (3) a streaming response, but our tuples should be similar to what is described in (5). How hard would it be on the Rust side to convert a PyDict to JSON? It might be nice to allow that, but if it is a pain, fine to require the user to call json.dumps()
.
influxdb3_py_api/src/system_py.rs
Outdated
let py_headers_dict = headers_binding | ||
.downcast::<PyDict>() | ||
.map_err(|e| anyhow::anyhow!("Failed to downcast to PyDict: {}", e))?; | ||
let body_binding = result.get_item(2).context("Python reqeust function didn't return a tuple of (status_code, response_headers, body)")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let body_binding = result.get_item(2).context("Python reqeust function didn't return a tuple of (status_code, response_headers, body)")?; | |
let body_binding = result.get_item(2).context("Python request function didn't return a tuple of (status_code, response_headers, body)")?; |
It's easy enough for us to automatically do the JSON conversion, but not every response is going to be JSON. So I left it to the user to have the response body be whatever they want it to be. I can clean up the other smaller things in a bit. |
Fixed the spelling error and logged #25894 to fix in a follow on PR. For now I'd like to get this one in so you can do the refactor with it in place. |
Adds the request plugin type. Triggers can be bound to an API endpoint at /api/v3/engine/. Requests will get yielded to the plugin with the query parameters, request parameters, and request body.
I didn't implement the test endpoint for this plugin type as it seems much more natural for users to save the file and make a new request. Once #25863 is done it'll make it very easy.
Closes #25862