-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[pkg/ottl] Add BoolGetter and IsBool converter #27900
[pkg/ottl] Add BoolGetter and IsBool converter #27900
Conversation
I'm not sure if I have misunderstood your issue, but I have written the IsBool converter referencing the IsString converter. Please let me know if anything goes wrong. I appreciate your time and effort in reviewing this. Thank you. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
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.
@Dennis40816 thank you for your contribution, sorry I took so long to review this.
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.
@Dennis40816 please add a changelog.
I'll rebase this branch to the latest |
Introduces two new types, BoolGetter and BoolLikeGetter, as prerequisites for the upcoming IsBool Converter feature. BoolGetter is designed to retrieve a bool value directly and will return a TypeError if the type doesn't match. It only accepts: 1. Native bool 2. pcommon.ValueTypeBool BoolLikeGetter will attempt to convert the underlying value to a bool, if possible, and return an error for incompatible types. It accepts bool, int, int64, string, and float64, as well as corresponding pcommon.ValueTypes. If the received pointer is nil, it will return nil.
This commit focuses on enhancing the test coverage for boolean type getter methods. Four new test functions have been added: - `Test_StandardBoolGetter`: Validates the behavior of standard Boolean getters. - `Test_StandardBoolGetter_WrappedError`: Ensures that standard Boolean getters correctly wrap and return errors. - `Test_StandardBoolLikeGetter`: Checks if object-based getters correctly convert to Boolean values. - `Test_StandardBoolLikeGetter_WrappedError`: Validates that errors from Bool-like getters are correctly wrapped and returned.
This commit updates pkg/ottl/README.md to include BoolGetter and BoolLikeGetter in the list of supported single-value parameters for OTTL functions.
This commit adds a new file, `func_is_bool.go`, to the `pkg/ottl/ottlfuncs` directory. This file houses the implementation of the `IsBool` function, designed to validate the type of `BoolGetter` objects. The `IsBool` function is crafted to serve as an integral part of OTTL's expression evaluation mechanism. The function will return `true` for the following two types: - Native boolean type - pcommon.ValueTypeBool
This commit introduces a new test file, func_is_bool_test.go, within the pkg/ottl/ottlfuncs directory. The test file contains comprehensive unit tests for the IsBool converter, ensuring its accuracy in type validation for various input value scenarios. Specifically, the tests cover: - Native boolean values - pcommon.ValueTypeBool objects - Incorrect types such as integers and slices - Error handling for type errors
This commit integrates the IsBool converter into the OTTL function registry by modifying the `functions.go` file. Specifically, the function `NewIsBoolFactory[K]()` has been included in the list of available converters. The update ensures that the IsBool converter is now available for use within the existing OTTL framework.
This commit updates the README.md file in the `pkg/ottl/ottlfuncs` directory to include documentation for the newly added IsBool converter. Detailed explanations, usage guidelines, and examples have been provided for the benefit of users. The documentation serves as a comprehensive guide for utilizing the IsBool converter within the OTTL ecosystem.
Add nolint:error lint for function `Test_StandardBoolLikeGetter_WrappedError` in `expression_test.go`.
Replace interface{} to any according to PR 29072.
e20e9f0
to
6cdf739
Compare
**Description:** This PR focuses on adding a new feature to the pkg/ottl package—namely, the `IsBool` converter, along with its prerequisites, `BoolGetter` and `BoolLikeGetter`. The series of commits implement the core logic, unit tests, and documentation to ensure that the `IsBool` converter is seamlessly integrated into the OTTL framework. By using this feature, users can conveniently determine whether a given value is a boolean or not. **Link to tracking Issue:** open-telemetry#27897 **Testing:** - A comprehensive set of unit tests were added to validate the functionality of the `IsBool` converter. The tests cover native boolean values, `pcommon.ValueTypeBool` objects, and incorrect types such as integers and slices. - Tests for `BoolGetter` and `BoolLikeGetter` were also included to verify their behavior and error handling mechanisms. Detailed test implementations can be found in [pkg/ottl/expression_test.go](https://github.com/Dennis40816/opentelemetry-collector-contrib/blob/0d1c2c0216f5647404573a6cfe66ebc0081a4167/pkg/ottl/expression_test.go#L1452). **Documentation:** - Updated README.md in the `pkg/ottl/ottlfuncs` directory to include detailed descriptions, usage guidelines, and examples for the `IsBool` converter. - The README file also reflects the addition of `BoolGetter` and `BoolLikeGetter` to the list of supported types for single-value parameters in OTTL functions.
Description:
This PR focuses on adding a new feature to the pkg/ottl package—namely, the
IsBool
converter, along with its prerequisites,BoolGetter
andBoolLikeGetter
. The series of commits implement the core logic, unit tests, and documentation to ensure that theIsBool
converter is seamlessly integrated into the OTTL framework. By using this feature, users can conveniently determine whether a given value is a boolean or not.Link to tracking Issue:
#27897
Testing:
IsBool
converter. The tests cover native boolean values,pcommon.ValueTypeBool
objects, and incorrect types such as integers and slices.BoolGetter
andBoolLikeGetter
were also included to verify their behavior and error handling mechanisms. Detailed test implementations can be found in pkg/ottl/expression_test.go.Documentation:
pkg/ottl/ottlfuncs
directory to include detailed descriptions, usage guidelines, and examples for theIsBool
converter.BoolGetter
andBoolLikeGetter
to the list of supported types for single-value parameters in OTTL functions.