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

Updated change router to retain subscription after a pod restart #94

Merged
merged 9 commits into from
Oct 24, 2024

Conversation

ruokun-niu
Copy link
Contributor

Description

  • The change router was unable to retrieve the subscription info from the state store because the subscription values were not properly saved in the state store. This PR created a custom struct called StateManager that is responsible for saving state values to the dapr state store. The save_state function from the Dapr Rust SDK will save the state as a serialized string, which prohibits the query_state_alpha1 function to fetch the state result.
    • For the save_state function in the StateManager, the state value should be an array of json object, where each object needs to have a key field and a value field

Type of change

  • This pull request fixes a bug in Drasi and has an approved issue (issue link required).

Fixes: #issue_number

}
}
}
None => return Err(Box::from("State entry must be a JSON array")),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we just make the state_entry parameter a Vec<Value>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Also I checked Dapr's documentation and their version of save_state accepts the state_entry as Vec<u8>. Should we be consistent with them?
I guess the downside of using Vec is that we still need to deserialize the data into Value to check if the required fields are missing. Maybe it is better to use Vec for this

for entry in entry {
match entry {
Value::Object(obj) => {
if !obj.contains_key("key") || !obj.contains_key("value") {
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 a strongly type object would be better here


pub async fn save_state(
&self,
state_entry: Vec<Value>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the API for the state manager take the strongly typed object, so that there is no need to validate for specific fields in an untyped object?

let response = match dapr_client
.query_state_alpha1(config.clone().subscriber_store, query_condition, None)
.query_state_alpha1(
Copy link
Contributor

Choose a reason for hiding this comment

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

should we encapsulate both the reading and writing of state in the state_manager?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that makes sense. Also we will have a deprovision function in the future for deleting the subscription from the state so it should also go into the same place

}
};
let publisher = DaprHttpPublisher::new(
"127.0.0.1".to_string(),

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
config.pubsub_name.clone(),
topic,
);
let state_manager = DaprStateManager::new("127.0.0.1", dapr_port, &config.subscriber_store);

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
query_condition: Value,
metadata: Option<HashMap<String, String>>,
) -> Result<Vec<Value>, Box<dyn std::error::Error>> {
let addr = "https://127.0.0.1".to_string();

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
@ruokun-niu ruokun-niu requested a review from a team as a code owner October 24, 2024 20:17
@ruokun-niu ruokun-niu merged commit 7bd3db6 into drasi-project:main Oct 24, 2024
30 checks passed
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