Issue originating at metricbeat
schema/mapstriface conversion utility toInteger func returns:
- the integer if the conversion was possible
- a
KeyNotFound error when the key is not present
- a generic error when the conversion fails
When 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:
|
emptyIface, err := common.MapStr(data).GetValue(key) |
|
if err != nil { |
|
return 0, schema.NewKeyNotFoundError(key) |
|
} |
into this
emptyIface, err := common.MapStr(data).GetValue(key)
if err != nil || emptyIface == nil {
return 0, schema.NewKeyNotFoundError(key)
}
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 resembles KeyNotFound
|
type KeyNotFoundError struct { |
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 not
Issue originating at metricbeat
consumer_utilisationissue with RabbitMQ module in 7.0.0 #11833schema/mapstriface conversion utility
toIntegerfunc returns:KeyNotFounderror 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
NotFoundSolution 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
KeyNotFounderror 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
NilValueErrorthat resemblesKeyNotFoundbeats/libbeat/common/schema/error.go
Line 45 in 4eb0002
this sounds like a much better solution, although looking at
KeyNotFoundimplementation, 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
NilValueErroris worth it, and if we should refactor or not