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 is_array filter and test for AttributeType #540

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

arthurDiff
Copy link

Added is_array fn to AttributeType enum.

@arthurDiff arthurDiff requested a review from a team as a code owner January 8, 2025 03:54
Copy link

linux-foundation-easycla bot commented Jan 8, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@lquerel
Copy link
Contributor

lquerel commented Jan 8, 2025

@arthurDiff Thank you for this PR, but I believe this ticket unfortunately lacked detail. What @lmolkova originally wanted was a Jinja filter or test integrated into our template engine based on the Minijinja implementation.

The idea would be to replace this Jinja hack (see the original pb description here):

{%- if "[]" in attribute.type and "template" not in attribute.type %}
...

with a Jinja test similar to this declaration:

{%- if attribute is array %}
...

You can find several examples of such tests in the following file (the one you could update):

crates/weaver_forge/src/extensions/otel.rs

I would be happy to provide more details or any kind of help if needed.

@arthurDiff
Copy link
Author

@arthurDiff Thank you for this PR, but I believe this ticket unfortunately lacked detail. What @lmolkova originally wanted was a Jinja filter or test integrated into our template engine based on the Minijinja implementation.

The idea would be to replace this Jinja hack (see the original pb description here):

{%- if "[]" in attribute.type and "template" not in attribute.type %}
...

with a Jinja test similar to this declaration:

{%- if attribute is array %}
...

You can find several examples of such tests in the following file (the one you could update):

crates/weaver_forge/src/extensions/otel.rs

I would be happy to provide more details or any kind of help if needed.

Hi @lquerel ! Sorry about the delay and thanks for the clarification! Should be implemented with minijinja now.

Comment on lines +463 to +473
matches!(
attr_type,
"string[]"
| "int[]"
| "double[]"
| "boolean[]"
| "template[string[]]"
| "template[int[]]"
| "template[double[]]"
| "template[boolean[]]"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

@lmolkova This test looks fine to me, but could you confirm: for semconvs, should a template[xxx[]] be considered an array, or should we treat any template as not being an array, even when templating an array of something?

Copy link
Author

Choose a reason for hiding this comment

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

Just added in documentation update and new test case for full coverage! just let me know if that needs updating!

Copy link
Contributor

@lquerel lquerel left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Just 2 comments:

  • I asked Liudmila to confirm if templates of arrays must be considered arrays. Nothing to do on your side for now.
  • You should add a description of the Jinja test in the following documentation.

After we should be ready to go :-).

Thank you

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.5%. Comparing base (213fa72) to head (02f4eef).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/weaver_forge/src/extensions/otel.rs 80.0% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #540   +/-   ##
=====================================
  Coverage   74.5%   74.5%           
=====================================
  Files         51      51           
  Lines       3960    3965    +5     
=====================================
+ Hits        2953    2957    +4     
- Misses      1007    1008    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arthurDiff
Copy link
Author

arthurDiff commented Jan 9, 2025

Overall LGTM. Just 2 comments:

  • I asked Liudmila to confirm if templates of arrays must be considered arrays. Nothing to do on your side for now.
  • You should add a description of the Jinja test in the following documentation.

After we should be ready to go :-).

Thank you

Sounds good! Out of curiosity. is there reason for match attribute types; weaver uses literal string instead of static const?
For example like this?

impl AttributeType {
    const PRIMITIVE_STRING: &str = "string";
    const PRIMITIVE_STRING_ARRAY: &str = "string[]";
}

or 

impl PrimitiveOrArrayTypeSpec{
    const STR: &str = "string";
    const STR_ARRAY: &str = "string[]";
}

@arthurDiff arthurDiff closed this Jan 9, 2025
@lquerel
Copy link
Contributor

lquerel commented Jan 9, 2025

@arthurDiff Regarding your question about strings, I’m not sure I fully understand. Are you suggesting introducing constants instead of using literal strings directly in the code? If so, then yes, they could indeed be replaced with static const &str.

Additionally, I didn’t understand why you closed this PR after making changes. It’s probably an error, so I'm reopening it so that we can proceed with the merge once we have received a response from @lmolkova. Thanks

@lquerel lquerel reopened this Jan 9, 2025
@arthurDiff
Copy link
Author

@arthurDiff Regarding your question about strings, I’m not sure I fully understand. Are you suggesting introducing constants instead of using literal strings directly in the code? If so, then yes, they could indeed be replaced with static const &str.

Additionally, I didn’t understand why you closed this PR after making changes. It’s probably an error, so I'm reopening it so that we can proceed with the merge once we have received a response from @lmolkova. Thanks

Yup! I think using static const str will help avoid errors instead of string literal.
and sorry about that rushing this morning must have closed it by accident! thanks for reopening it.
I will wait for @lmolkova and get it merged with response! Thanks for the information.

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