-
Notifications
You must be signed in to change notification settings - Fork 566
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
Fixed race condition in the OCI Metrics integration test between retrieval of metrics from registry and asserting that from expected results #4897
Conversation
…ieval of metrics from registry and asserting that from expected results. To fix the issue, here are the list 1. Used CountDownLatches to signal when to start testing, for example, test only after results has been retrieved. 2. Make OciMetricsCdiExtension Priority higher than MetricsCdiExtension so that it will only start after MetricsCdiExtension has completed.
...metrics/metrics/src/test/java/io/helidon/integrations/oci/metrics/OciMetricsSupportTest.java
Outdated
Show resolved
Hide resolved
...metrics/metrics/src/test/java/io/helidon/integrations/oci/metrics/OciMetricsSupportTest.java
Outdated
Show resolved
Hide resolved
...metrics/metrics/src/test/java/io/helidon/integrations/oci/metrics/OciMetricsSupportTest.java
Show resolved
Hide resolved
…ate and fail test if InterruptedException is received in delay()
I think there is still a possible race condition (although probably unlikely). What if the mocking code in The real goal of the test is to make sure that the value stored in the counter is used correctly in preparing the OCI metrics data, specifically that the mocking code captures We can accomplish that goal by:
After the main test thread starts the web server, it |
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.
Sorry, more changes (but at least they simplify things). See the other longer comment.
I agree with the feedback and hence implemented it. Tested it again for around 800 iterations and issue is not reproduced. |
The goal of this PR is to resolve the issue reported in #4813 |
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.
LGTM
The change includes the following: 1. Port of PR helidon-io#4003 that adds the Helidon Metrics to OCI integration 2. Port of PR helidon-io#4897 that fixes race condition in the unit test 3. Adjust code to deal with MP metrics API changes 4. Change endpoint to the ingestion endpoint when posting the metrics as this is not handled anymore by the OCI SDK integration due to changes in the OCI Java SDK v3. 5. Change MonitoringClient.class to Monitoring.class for mocking using Mockito in the unit test as the OCI Java SDK v3 converted some of the methods in MonitoringClient as Final making them difficult to mock. 6. Trim the OCI Metadata value which contains the metric description if the value exceeds 256 characters, otherwise it will fail. 7. OCI Monitoring service only allows a maximum of 50 metrics per posting, hence additional configuration parameters were added to control sending metrics in batches. The configuration parameters are: a. batchSize - Maximum no. of metrics to send in a batch. Defaults to 50 which is what OCI allows b. batchDelay - Interval between batch posting For example if there are 51 metrics and batchSize is set to 25 and batchDelay to 5 seconds, the Helidon metric integration module will divide the posting to 3 batches sending 25 metrics on the 1st and 2nd batches and 1 metric on the 3rd batch with 5 seconds interval between batch posting. 8. Refactor OciMetricsCdiExtension to add a new bean (OciMetricsBean) to handle the Observer method which will inject Monitoring. Previous code of OciMetricsCdiExtension cannot independently handle instantiation of Monitoring client via CDI. 9. Add unit tests to verify batch posting feature and the use of ingestion endpoint.
* Add Helidon Metrics integration with OCI The change includes the following: 1. Port of PR #4003 that adds the Helidon Metrics to OCI integration 2. Port of PR #4897 that fixes race condition in the unit test 3. Adjust code to deal with MP metrics API changes 4. Change endpoint to the ingestion endpoint when posting the metrics as this is not handled anymore by the OCI SDK integration due to changes in the OCI Java SDK v3. 5. Change MonitoringClient.class to Monitoring.class for mocking using Mockito in the unit test as the OCI Java SDK v3 converted some of the methods in MonitoringClient as Final making them difficult to mock. 6. Trim the OCI Metadata value which contains the metric description if the value exceeds 256 characters, otherwise it will fail. 7. OCI Monitoring service only allows a maximum of 50 metrics per posting, hence additional configuration parameters were added to control sending metrics in batches. The configuration parameters are: a. batchSize - Maximum no. of metrics to send in a batch. Defaults to 50 which is what OCI allows b. batchDelay - Interval between batch posting For example if there are 51 metrics and batchSize is set to 25 and batchDelay to 5 seconds, the Helidon metric integration module will divide the posting to 3 batches sending 25 metrics on the 1st and 2nd batches and 1 metric on the 3rd batch with 5 seconds interval between batch posting. 8. Refactor OciMetricsCdiExtension to add a new bean (OciMetricsBean) to handle the Observer method which will inject Monitoring. Previous code of OciMetricsCdiExtension cannot independently handle instantiation of Monitoring client via CDI. 9. Add unit tests to verify batch posting feature and the use of ingestion endpoint. 10. Add io.helidon.config.Config as parameter in OCIMetricsBean's Observer method so it can be injected 11. Various changes based on review feedback to fix dependencies, remove use of stream in list, execute rule.onNewWebserver only if enabled, add default value on @ConfigProperty and validate builder methods' parameters are not null
To fix the issue, here are the list of changes made: