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

Refactor AnyValue enum? #1917

Open
utpilla opened this issue Jul 8, 2024 · 6 comments
Open

Refactor AnyValue enum? #1917

utpilla opened this issue Jul 8, 2024 · 6 comments
Labels
enhancement New feature or request triage:todo Needs to be traiged.

Comments

@utpilla
Copy link
Contributor

utpilla commented Jul 8, 2024

There are a few concerns with the current implementation of AnyValue enum:

  1. The spec allows for null or an empty value as a valid value for AnyValue.
  2. The current implementation of appender tracing simply records the debug string for complex AnyValue variants such as Hashmap<Key, AnyValue>, Vec<Anyvalue>, and Vec<u8>. We could get hold of the concrete type and do more targeted logging for these types.
  3. Use a struct instead of enum as the public interface for representing AnyValue? Currently, AnyValue enum is marked public which means adding any new variant to it in the future would be a breaking change. We could probably use a struct that wraps over AnyValue enum and mark the enum private/internal. That would allow us to easily make changes to the enum, thereby providing us the flexibility to make changes to the implementation easily.
@utpilla utpilla added enhancement New feature or request triage:todo Needs to be traiged. labels Jul 8, 2024
@lalitb
Copy link
Member

lalitb commented Jul 8, 2024

Thanks @utpilla. Very good points.

Regarding 1 and 2, it's worth testing if the tracing library allows emitting attributes with None (encapsulated within Options) value or values with iterators to HashMap or Vector. Looking into the tracing doc, it seems possible (basically it supports anything which implements Debug trait)

Regarding 3, the struct approach seems good, though it does introduce another level of indirection. We can also evaluate other approaches, such as adding a catch-all Unknown variant. This would ensure new variants can be added without breaking existing code.

@cijothomas
Copy link
Member

On 7/9 SIG, we also discussed the need to make AnyValue and Value Enum variants consistent. The former provides conversion for lower size integers, but the latter does not. We should be consistent here.
TBD what is the list of supported types.

@demurgos
Copy link
Contributor

@cijothomas Why is there both Value and AnyValue? As far as I can tell the spec only defines AnyValue as the generic dynamic value type, but the Rust impl has both types in its public API with seemingly no real reason why sometimes it's Value and sometimes it's AnyValue.

I would be willing to send a PR to refactor value handling to use a single consistent type. I also agree with the points in the first message: Null should be fully support and the implementation should better manage its guarantees. I would strongly recommend to not expose the internal representation so it is possible to evolve it.

@lalitb
Copy link
Member

lalitb commented Sep 29, 2024

Why is there both Value and AnyValue?

This is discussed here - #1253 (comment)

@lalitb
Copy link
Member

lalitb commented Sep 29, 2024

I also agree with the points in the first message: Null should be fully support and the implementation should better manage its guarantees.

Rust doesn't have a built-in null type. While we can introduce an AnyValue::Null variant, it first needs to be validated how this variant will map from the Value type coming from tracing.

@demurgos
Copy link
Contributor

demurgos commented Sep 30, 2024

Thank you very much. I checked in the spec before posting but missed this part. It's a bit confusing to have similar but different value types. I was also confused because the proto definition does not make any distinction there. Here are some other spec discussions that I found about it:

Given the spec links, I see that AnyValue can't be null, only Value.

It would still be good to have some better way to avoid duplication between these types, but it may be more complex than expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage:todo Needs to be traiged.
Projects
None yet
Development

No branches or pull requests

4 participants