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

Added support for list values for a key in processor #1936

Closed
wants to merge 9 commits into from

Conversation

isgoutham
Copy link

Updated/Added cases in opentelemetry-collector/internal/processor/filterhelper/filterhelper.go for handling list of interfaces and map

Updated Match func in opentelemetry-collector/internal/processor/filtermatcher/attributematcher.go for validating AttributeValueARRAY data

Description: Support for list of values for a key for attribute processor
Link to tracking Issue: #1935

Updated/Added cases in opentelemetry-collector/internal/processor/filterhelper/filterhelper.go for handling list of interfaces and map

Updated Match fn in opentelemetry-collector/internal/processor/filtermatcher/attributematcher.go for validating  AttributeValueARRAY data
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 12, 2020

CLA Check
The committers are authorized under a signed CLA.

return false
default:
if !attr.Equal(*property.AttributeValue) {
Copy link
Author

Choose a reason for hiding this comment

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

handling at attr.Equal(*property.AttributeValue) would be ideal case. But attr, exist := attrs.Get(property.Key) returns String type for array values under property.Key. And further it always goes under string case execution

Copy link
Member

Choose a reason for hiding this comment

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

Can you point to the code where the return value is string?

Copy link
Author

@isgoutham isgoutham Oct 13, 2020

Choose a reason for hiding this comment

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

Here Get func. Though the property.AttributeValue is of ARRAY type (since NewAttributeValueRaw() returns NewAttributeValueArray as per my logic), the return value of Get method is of string type.

Otherwise handling at Equal func would be ideal. In fact, there is a // TODO: handle MAP and ARRAY data types. I have tried adding these cases, but attr is of string type and Equal method is falling under string case.

I have tried using attr.SetArrayVal() but this is changing whole attributes as array.

Anything should i be considering for these scenarios?

@codecov
Copy link

codecov bot commented Oct 12, 2020

Codecov Report

Merging #1936 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1936      +/-   ##
==========================================
+ Coverage   91.41%   91.42%   +0.01%     
==========================================
  Files         284      284              
  Lines       16788    16808      +20     
==========================================
+ Hits        15347    15367      +20     
  Misses       1009     1009              
  Partials      432      432              
Impacted Files Coverage Δ
internal/processor/filterhelper/filterhelper.go 100.00% <100.00%> (ø)
...ternal/processor/filtermatcher/attributematcher.go 100.00% <100.00%> (ø)
translator/internaldata/resource_to_oc.go 91.78% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 031521d...2e307bc. Read the comment docs.

@isgoutham isgoutham changed the title Added support for array values for attributes Added support for list values for a key in processor Oct 12, 2020
return av
}

func fromVal(val interface{}) pdata.AttributeValue {
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid duplicate code between this func and NewAttributeValueRaw?

Copy link
Author

Choose a reason for hiding this comment

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

Noted and updated

case map[string]interface{}:
return fromMap(v)
}
panic("data type is not supported in fromVal()")
Copy link
Member

Choose a reason for hiding this comment

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

We should not panic

Copy link
Author

Choose a reason for hiding this comment

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

Noted and updated

return pdata.NewAttributeValueInt(int64(v))
case float64:
return pdata.NewAttributeValueDouble(v)
case []interface{}:
Copy link
Member

@james-bebbington james-bebbington Oct 13, 2020

Choose a reason for hiding this comment

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

I'm not sure how this code is intended to be used, but note data of type []string or []MyStruct won't meet this condition (same for the map case below)

https://play.golang.org/p/ZRosREV0Fa2

Copy link
Author

@isgoutham isgoutham Oct 13, 2020

Choose a reason for hiding this comment

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

Its a slice case, tried here
https://play.golang.org/p/9Q4YHsuqVJ7

Copy link
Author

Choose a reason for hiding this comment

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

covered in test cases too

@isgoutham isgoutham requested a review from a team October 20, 2020 08:11
@isgoutham
Copy link
Author

Hi @bogdandrutu , could you please check this.

@isgoutham
Copy link
Author

Hi @bogdandrutu could you please review

@asldevi
Copy link

asldevi commented Oct 23, 2020

@bogdandrutu is there any blocker for this?
we're trying to do 100% sampling for all errors and right now the only is to have a processor for each of the error code. Looks like this PR would be a perfect thing for us.

Comment on lines +108 to +120
propertyAttrValue := property.AttributeValue
switch propertyAttrValue.Type() {
// Case when Attribute Values are of list values.
case pdata.AttributeValueARRAY:
for i := 0; i < propertyAttrValue.ArrayVal().Len(); i++ {
// Check attr value is exists in the AttributeValue array.
// Equal checks for any of int, string, bool and double.
if attr.Equal(propertyAttrValue.ArrayVal().At(i)) {
return true
}
}
return false
default:
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing this here I suggest that we move this code to attr.Equal. It already has a TODO comment that expects this code to be there.

Copy link
Author

@isgoutham isgoutham Oct 27, 2020

Choose a reason for hiding this comment

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

Thats right. I tried doing that earlier.
#1936 (comment)

Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

Looks like I misunderstood your proposal #1935
I will comment there.

@tigrannajaryan
Copy link
Member

Closing this PR as per discussion in #1935 since this can be done using existing functionality.

Troels51 pushed a commit to Troels51/opentelemetry-collector that referenced this pull request Jul 5, 2024
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.

5 participants