-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[connector/countconnector] Handle non-string attributes #32225
[connector/countconnector] Handle non-string attributes #32225
Conversation
connector/countconnector/config.go
Outdated
DefaultValue string `mapstructure:"default_value"` | ||
DefaultIntValue int64 `mapstructure:"default_int_value"` | ||
DefaultFloatValue float64 `mapstructure:"default_float_value"` |
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 think this design introduces unnecessary relationships between fields in the config. If we cannot use a type constraint, can we just make DefaultValue
an any
?
cfdb6ee
to
4c59f7d
Compare
@@ -41,9 +41,23 @@ func (c *counter[K]) update(ctx context.Context, attrs pcommon.Map, tCtx K) erro | |||
countAttrs := pcommon.NewMap() | |||
for _, attr := range md.attrs { | |||
if attrVal, ok := attrs.Get(attr.Key); ok { | |||
countAttrs.PutStr(attr.Key, attrVal.Str()) | |||
} else if attr.DefaultValue != "" { |
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 need to keep this check, or something equivalent.
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 need to check if there is a default value set. If not, won't the type switch below 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.
Sure, I added 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.
We do not rely on panics in the collector. There is no requirement to set a default value, so this is not even a problem. We should just skip the block, like we were doing previously.
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 hope I understand now. I added a condition to skip if the default value is nil
.
e7900e4
to
9a3064d
Compare
9a3064d
to
b4495ed
Compare
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.
Agree with @djaglowski that the panic is out of place. Other than that, I like the solution given to the default value.
b4495ed
to
a9c2d20
Compare
a9c2d20
to
a9a6cd4
Compare
Thanks @lkwronski |
Description:
Adding support for non string attributes in the count connector. I started working based on #30314 (comment), but it doesn't work. When I try to add the type constaint:
This causes the following error:
My idea was to introduce new fields
DefaultIntValue
andDefaultFloatValue
to handle number types, let me know if this makes sense, if so, I will add documentation and finalize this PR.Link to tracking Issue: Fixes #30314.
Testing: Added unit test
Documentation: TODO