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

Migrate query api to rust #45

Merged
merged 11 commits into from
Sep 25, 2024
Merged

Migrate query api to rust #45

merged 11 commits into from
Sep 25, 2024

Conversation

ruokun-niu
Copy link
Contributor

Description

Migrate Query API to Rust

Type of change

  • This pull request adds or changes features of Drasi and has an approved issue (issue link required).

Fixes: #issue_number

@ruokun-niu ruokun-niu marked this pull request as draft September 6, 2024 21:18
sources/shared/query-api/src/main.rs Dismissed Show dismissed Hide dismissed
sources/shared/query-api/src/main.rs Dismissed Show dismissed Hide dismissed
@ruokun-niu ruokun-niu marked this pull request as ready for review September 9, 2024 21:52
.await
{
Ok(response) => {
response
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if the DAPR SDK throws an error for a non 200 response... you may need to also check the response status code, and pass the error message back to the calling app.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is correct. You need something like this using the is_success function:

    match response {
        Ok(res) => {
            if res.status().is_success() {
                Ok(())
            } else {
                ...
            }
        },
        Err(e) => ...
    }

All of our calls like this need to be fixed. There are some in the comms abstractions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm currently debating whether we should handle this status check in the actual dapr invoker or in the code after we executed the invoke() function. I'm leaning towards handling this in the dapr invoker (in comms abstractions)

}
Err(e) => {
println!("Error invoking the acquire method on the proxy: {:?}", e);
return StatusCode::INTERNAL_SERVER_ERROR.into_response();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could add an error message to the body of these INTERNAL_SERVER_ERROR responses

debug!("Published the subscription event");
}
Err(e) => {
println!("Error publishing the subscription event: {:?}", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of println, lets use log::error or log::info

}

#[derive(Serialize)]
pub struct AfterData {
Copy link
Contributor

Choose a reason for hiding this comment

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

The AfterData name is really throwing me. Could we think of a name that better describes this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about SubscriptionData? Since this is solely used for sending the controlevent in a subscription?

@@ -36,5 +36,5 @@ pub trait Publisher {
&self,
data: Value,
headers: Headers,
) -> Result<(), Box<dyn std::error::Error>>;
) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should include reqwest::Response as part of the API of drasi comms. It tightly couples us to a specific library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about a custom struct that contains the status code and/or the response body? Something like:

pub struct HttpResponse {
    pub status_code: u16,
    pub body: String,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That way we can still pass the status code and the ebody

Copy link
Contributor

Choose a reason for hiding this comment

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

That might make sense for the Invoker, but the publisher implementation could be one that does not use Http, if we choose to not use Dapr in the future, many messages brokers have their own protocols.
I think if a non success code comes from the Dapr sidecar, the publish was unsuccessful, and we just return an error, and if the body contains details, we include that in the error result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that makes sense. for a successful service invocation, maybe we can just return the body as Bytes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh actually this is the publisher, we don't really need to return anything if the publish is successful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I was think about the wrong thing

}
Err(e) => {} //
},
None => {}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could log a warning if the trace headers are missing.

@@ -26,7 +26,7 @@ pub trait Invoker {
app_id: String,
method: String,
headers: Headers,
) -> Result<(), Box<dyn std::error::Error>>;
) -> Result<serde_json::Value, Box<dyn std::error::Error>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't assume the response will always be json

@danielgerlag danielgerlag merged commit 82a506a into main Sep 25, 2024
32 checks passed
@danielgerlag danielgerlag deleted the migrate-query-api-to-rust branch September 26, 2024 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants