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

support ignoring alias fields from trace registry #3

Merged
merged 2 commits into from Dec 13, 2023

Conversation

ibalajiarun
Copy link

@ibalajiarun ibalajiarun commented Dec 1, 2023

Summary

Fixes aptos-labs/aptos-core#10424

This PR adds support for ignoring aliases of fields from the trace registry via a new API. In serde-rs/serde#2387, serde allowed both field names and aliases to be considered as field names during deserialization. This breaks the serde-reflection tracer, because it can only trace one field while it expects to trace multiple fields denoted by the field names and aliases. Also, serde doesn't currently denote whether a field is an alias or not in the Deserializer trait.

To work around this issue, this PR adds a new API ignore_aliases that can be called to manually ignore the aliases in a struct container from the resource registry.

This change maintains backwards compatibility in terms of generated format spec file.

Test Plan

Added unit test to reproduce the issue and use ignore_aliases to fix the issue.

@ibalajiarun ibalajiarun marked this pull request as draft December 1, 2023 17:52
@ibalajiarun ibalajiarun changed the title support tracing alias fields support ignoring alias fields from trace registry Dec 1, 2023
@ibalajiarun ibalajiarun marked this pull request as ready for review December 1, 2023 23:37
Copy link

@banool banool left a comment

Choose a reason for hiding this comment

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

When you updated aptos-core to use this, did the generate-format code now work?

@@ -243,7 +243,7 @@ where
Option(format) => format!("Option<{}>", Self::quote_type(format, known_sizes)),
Seq(format) => format!("Vec<{}>", Self::quote_type(format, None)),
Map { key, value } => format!(
"Map<{}, {}>",
Copy link

Choose a reason for hiding this comment

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

What was this Map type, I can't see any type imported with that name. I suppose it's a serde specific thing?

Copy link
Author

Choose a reason for hiding this comment

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

Not sure either. It was failing a unit test, so I fixed it. It was failing earlier too, but I guess nobody noticed.

@@ -243,7 +243,7 @@ where
Option(format) => format!("Option<{}>", Self::quote_type(format, known_sizes)),
Seq(format) => format!("Vec<{}>", Self::quote_type(format, None)),
Map { key, value } => format!(
"Map<{}, {}>",
"std::collections::BTreeMap<{}, {}>",
Copy link

Choose a reason for hiding this comment

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

Will changing to BTreeMap change any behavior?

Copy link
Author

Choose a reason for hiding this comment

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

Hopefully, its deterministic.


if alias_formats.len() != aliases.len() {
return Err(Error::Custom(format!(
"cannot ignore alias. not all aliases are found in container: {:?}",
Copy link

Choose a reason for hiding this comment

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

So if the user says "ignore alias x" but x isn't found, this will throw an error, is that right?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this was intentional.

@@ -457,3 +457,42 @@ fn test_repeated_tracing() {
))))))
);
}

#[test]
fn test_trace_deserialization_with_alias_types() {
Copy link

Choose a reason for hiding this comment

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

Nice, looks good.

@ibalajiarun
Copy link
Author

When you updated aptos-core to use this, did the generate-format code now work?

yes, it produced the same format spec as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants