-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Helidon Metrics integration with OCI (#5829)
* 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
- Loading branch information
Showing
17 changed files
with
2,028 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2021, 2023 Oracle and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.helidon.integrations.oci.metrics</groupId> | ||
<artifactId>helidon-integrations-oci-metrics-project</artifactId> | ||
<version>3.1.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>helidon-integrations-oci-metrics-cdi</artifactId> | ||
<name>Helidon Integrations OCI Metrics CDI</name> | ||
<description>Helidon Metrics to OCI via CDI</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.integrations.oci.metrics</groupId> | ||
<artifactId>helidon-integrations-oci-metrics</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.microprofile.server</groupId> | ||
<artifactId>helidon-microprofile-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.microprofile.tests</groupId> | ||
<artifactId>helidon-microprofile-tests-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
53 changes: 53 additions & 0 deletions
53
...oci/metrics/cdi/src/main/java/io/helidon/integrations/oci/metrics/cdi/OciMetricsBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.helidon.integrations.oci.metrics.cdi; | ||
|
||
import io.helidon.config.Config; | ||
import io.helidon.integrations.oci.metrics.OciMetricsSupport; | ||
import io.helidon.microprofile.server.RoutingBuilders; | ||
|
||
import com.oracle.bmc.monitoring.Monitoring; | ||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.Initialized; | ||
import jakarta.enterprise.event.Observes; | ||
import jakarta.inject.Singleton; | ||
|
||
import static jakarta.interceptor.Interceptor.Priority.LIBRARY_BEFORE; | ||
|
||
/** | ||
* OCI metrics integration CDI extension. | ||
*/ | ||
|
||
// This bean is added to handle injection on the ObserverMethod as it does not work on an Extension class. | ||
@Singleton | ||
public class OciMetricsBean { | ||
|
||
// Make Priority higher than MetricsCdiExtension so this will only start after MetricsCdiExtension has completed. | ||
void registerOciMetrics(@Observes @Priority(LIBRARY_BEFORE + 20) @Initialized(ApplicationScoped.class) Object ignore, | ||
Config config, Monitoring monitoringClient) { | ||
Config helidonConfig = config.get("ocimetrics"); | ||
if (helidonConfig.exists()) { | ||
OciMetricsSupport.Builder builder = OciMetricsSupport.builder() | ||
.config(helidonConfig) | ||
.monitoringClient(monitoringClient); | ||
|
||
RoutingBuilders.create(helidonConfig) | ||
.routingBuilder() | ||
.register(builder.build()); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ics/cdi/src/main/java/io/helidon/integrations/oci/metrics/cdi/OciMetricsCdiExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2022, 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.helidon.integrations.oci.metrics.cdi; | ||
|
||
import jakarta.enterprise.event.Observes; | ||
import jakarta.enterprise.inject.spi.BeforeBeanDiscovery; | ||
import jakarta.enterprise.inject.spi.Extension; | ||
|
||
/** | ||
* OCI metrics integration CDI extension. | ||
*/ | ||
public class OciMetricsCdiExtension implements Extension { | ||
|
||
// A new bean is added to handle the Observer Method as injection does not work here | ||
void addOciMetricsBean(@Observes BeforeBeanDiscovery event) { | ||
event.addAnnotatedType(OciMetricsBean.class, OciMetricsBean.class.getName()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...s/oci/metrics/cdi/src/main/java/io/helidon/integrations/oci/metrics/cdi/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2022, 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Integrating with OCI Metrics Using CDI. | ||
*/ | ||
package io.helidon.integrations.oci.metrics.cdi; |
34 changes: 34 additions & 0 deletions
34
integrations/oci/metrics/cdi/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2022, 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Integrating with OCI Metrics Using CDI. | ||
*/ | ||
module io.helidon.integrations.oci.metrics.cdi { | ||
requires io.helidon.config.mp; | ||
requires io.helidon.integrations.oci.metrics; | ||
requires io.helidon.microprofile.config; | ||
requires io.helidon.microprofile.server; | ||
|
||
requires oci.java.sdk.monitoring; | ||
|
||
requires jakarta.interceptor.api; | ||
provides jakarta.enterprise.inject.spi.Extension with io.helidon.integrations.oci.metrics.cdi.OciMetricsCdiExtension; | ||
|
||
opens io.helidon.integrations.oci.metrics.cdi to weld.core.impl, io.helidon.microprofile.cdi; | ||
|
||
exports io.helidon.integrations.oci.metrics.cdi; | ||
} |
Oops, something went wrong.