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 custom serialized for last_error, update schemas #1140

Merged
merged 6 commits into from
Oct 23, 2023

Conversation

piotrpio
Copy link
Contributor

  • Added custom serde form async_nats::service::error::Error to properly format error string
  • Fixed metadata to always use default if not provided in json (or passed as null)
  • Extracted Ping as a separate struct and added metadata to it

Signed-off-by: Piotr Piotrowski piotr@synadia.com

@piotrpio piotrpio force-pushed the service-api-config-serde branch 2 times, most recently from 28171d2 to 09a2629 Compare October 17, 2023 11:15
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

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

Overall, good PR.

Some changes and nits requested.

@@ -177,13 +170,59 @@ pub struct Stats {
#[serde(default, with = "serde_nanos")]
pub average_processing_time: std::time::Duration,
/// Last error that occurred.
#[serde(with = "serde_error_string")]
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should add skip_serializing_if = "Option::is_none" ?
Or with experience when working on cross compatibility tests its better to serialize to ""?

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 think it's a good idea, although it is required in json schema: https://github.com/nats-io/jsm.go/blob/main/schemas/micro/v1/stats_response.json

On the other hand, it's marked as optional in ADR. I would say it should be optional and we should update the schema, then we can add skip_serializing_if here. What do you think?

async-nats/src/service/mod.rs Show resolved Hide resolved
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
@piotrpio piotrpio requested a review from Jarema October 18, 2023 14:12
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
/// Queue group to which this endpoint is assigned to.
pub queue_group: String,
}

mod serde_error_string {
Copy link
Member

Choose a reason for hiding this comment

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

As we have our own error type, the serde impl can be attached to it directly.

Copy link
Member

Choose a reason for hiding this comment

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

as discussed, as a first pass, this is ok, as we would need some custom logic for serializing into "" instead of null in case of None etc.

Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

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

LGTM!

@Jarema Jarema merged commit 4fa004f into main Oct 23, 2023
10 checks passed
@Jarema Jarema deleted the service-api-config-serde branch October 23, 2023 08:45
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.

2 participants