-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
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
|
return false | ||
default: | ||
if !attr.Equal(*property.AttributeValue) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 Report
@@ 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
Continue to review full report at Codecov.
|
return av | ||
} | ||
|
||
func fromVal(val interface{}) pdata.AttributeValue { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not panic
There was a problem hiding this comment.
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{}: |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Hi @bogdandrutu , could you please check this. |
Hi @bogdandrutu could you please review |
@bogdandrutu is there any blocker for this? |
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this 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.
Closing this PR as per discussion in #1935 since this can be done using existing functionality. |
Updated/Added cases in
opentelemetry-collector/internal/processor/filterhelper/filterhelper.go
for handling list of interfaces and mapUpdated Match func in
opentelemetry-collector/internal/processor/filtermatcher/attributematcher.go
for validating AttributeValueARRAY dataDescription: Support for list of values for a key for attribute processor
Link to tracking Issue: #1935