-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[libbeat]MapStr/Conv toInteger should behave different when converting from nil #11983
Comments
Thanks for investigating this and exploring possible solutions. On what apps are you finding nil values? I think current behaviour is "correct" because actually a nil is not an integer, but I agree that we should handle this case. We should decide what behaviour we want in case of
Any solution we decide should be implemented for all types, not only for integers. I'd be slightly in favour of adding an option to allow nil values, this would be backwards compatible and it would be the same for any type. It would also allow to have different behaviours for different services, as nil won't mean the same in all places. In principle I wouldn't add a
You can see more about the last refactors around here in this PR: #7335 But yes, these values are mean to classify or discard errors. I'd keep this "propagation" by now, I agree that it could maybe better to propagate the options from top to bottom and don't generate the errors if not needed, but this would require almost a full rewrite of this, not sure if it worths it. I also agree that it is not the error what is optional or required but the key. We could make the |
related issue is: #11833 I would avoid keeping this as is, it is up to the reporter app to decide if the simplest solution would be to create an That would be an easy fix for the issue, and I think I can live with the caveat above. WDYT? |
Adding this as an option sounds good to me 👍 |
closing after #12089 got merged |
Issue originating at metricbeat
consumer_utilisation
issue with RabbitMQ module in 7.0.0 #11833schema/mapstriface conversion utility
toInteger
func returns:KeyNotFound
error when the key is not presentWhen using these conversion functions we will be considering an error a key that exist but whose value is nil, while some apps will report keys with empty values that should be treated as
NotFound
Solution 1
turn this:
beats/libbeat/common/schema/mapstriface/mapstriface.go
Lines 205 to 208 in 4eb0002
into this
it is a very simple solution that should not modify any current usage of the int conversion, but it returns a
KeyNotFound
error when in fact the key might have been found, but the value is nil. The result is ok, the semantics are twisted.Solution 2
Create an
NilValueError
that resemblesKeyNotFound
beats/libbeat/common/schema/error.go
Line 45 in 4eb0002
this sounds like a much better solution, although looking at
KeyNotFound
implementation, this rings overcomplicated (is Optional and Required needed for an error object?). The reason for having these error fields is probably a scenario where a set of keys are being processed and all errors are being retrieved and classified upon their originating schema properties (Optional, Required), and these fields are "propagated" from the schema. If that's the case, I would suggest a refactor to decouple, simplify error management and make it more intuitive: errors are not optional or required, probably they fall into 2 categories: (real) errors or something to log at most. If that fits the logic of this conversion functions, those fields could be removed, and only real errors be returned.For sure I'll be missing many scenarios here, I'm only proposing the 2 solutions above as starting points. Personally, I would go Solution 1 (although I don't like it) to solve current issues ASAP. Then think if creating a
NilValueError
is worth it, and if we should refactor or notThe text was updated successfully, but these errors were encountered: