diff --git a/oraclecloud-httpclient-netty/src/test/groovy/io/micronaut/oraclecloud/client/OciMonitoringSpec.groovy b/oraclecloud-httpclient-netty/src/test/groovy/io/micronaut/oraclecloud/client/OciMonitoringSpec.groovy index 098f91ad8..1e96b89df 100644 --- a/oraclecloud-httpclient-netty/src/test/groovy/io/micronaut/oraclecloud/client/OciMonitoringSpec.groovy +++ b/oraclecloud-httpclient-netty/src/test/groovy/io/micronaut/oraclecloud/client/OciMonitoringSpec.groovy @@ -92,8 +92,7 @@ class OciMonitoringSpec extends Specification { } MonitoringClient createTelemetryClient() { - String ingestionEndpoint = String.format("https://telemetry-ingestion.%s.oraclecloud.com", - regionProvider.getRegion().getRegionId()); + String ingestionEndpoint = regionProvider.getRegion().getEndpoint(MonitoringClient.SERVICE).orElseThrow() return MonitoringClient.builder().endpoint(ingestionEndpoint).build(authenticationDetailsProvider) } diff --git a/oraclecloud-micrometer/src/main/java/io/micronaut/oraclecloud/monitoring/MonitoringIngestionClient.java b/oraclecloud-micrometer/src/main/java/io/micronaut/oraclecloud/monitoring/MonitoringIngestionClient.java index 5566ff1b2..a0c4c3c98 100644 --- a/oraclecloud-micrometer/src/main/java/io/micronaut/oraclecloud/monitoring/MonitoringIngestionClient.java +++ b/oraclecloud-micrometer/src/main/java/io/micronaut/oraclecloud/monitoring/MonitoringIngestionClient.java @@ -30,7 +30,7 @@ import java.util.Objects; /** - * Oracle SDK provides {@link MonitoringClient} that is constructed with default {@code https://telemetry..oraclecloud.com} endpoint. + * Oracle SDK provides {@link MonitoringClient} that is constructed with default endpoint based on region provided by region provider. * For sending metrics to the Oracle Cloud Monitoring service the {@link MonitoringClient#postMetricData(PostMetricDataRequest)} is used * but the endpoint must be configured to {@code https://telemetry-ingestion..oraclecloud.com}. This bean encapsulates creation * and configuration of the {@link MonitoringClient} to use {@link MonitoringClient#postMetricData(PostMetricDataRequest)} @@ -105,8 +105,13 @@ public MonitoringClient getDelegate() { if (delegate == null) { synchronized (MonitoringIngestionClient.class) { if (delegate == null) { - String ingestionEndpoint = String.format("https://telemetry-ingestion.%s.oraclecloud.com", - regionProvider.getRegion().getRegionId()); + if (regionProvider.getRegion() == null) { + throw new IllegalArgumentException("Region is required for the Monitoring Ingestion client"); + } + + String ingestionEndpoint = regionProvider.getRegion().getEndpoint(MonitoringClient.SERVICE) + .orElse(String.format("https://telemetry-ingestion.%s.oraclecloud.com", regionProvider.getRegion().getRegionId())); + MonitoringClient.Builder builder = MonitoringClient.builder(). endpoint(ingestionEndpoint); diff --git a/oraclecloud-micrometer/src/test/groovy/io/micronaut/oraclecloud/monitoring/micrometer/OracleCloudMeterRawRegistrySpec.groovy b/oraclecloud-micrometer/src/test/groovy/io/micronaut/oraclecloud/monitoring/micrometer/OracleCloudMeterRawRegistrySpec.groovy index 7bba5cb1c..2ebe611f4 100644 --- a/oraclecloud-micrometer/src/test/groovy/io/micronaut/oraclecloud/monitoring/micrometer/OracleCloudMeterRawRegistrySpec.groovy +++ b/oraclecloud-micrometer/src/test/groovy/io/micronaut/oraclecloud/monitoring/micrometer/OracleCloudMeterRawRegistrySpec.groovy @@ -1,6 +1,5 @@ package io.micronaut.oraclecloud.monitoring.micrometer -import com.oracle.bmc.monitoring.MonitoringClient import com.oracle.bmc.monitoring.model.Datapoint import io.micrometer.core.instrument.* import io.micronaut.http.client.HttpClientRegistry diff --git a/oraclecloud-micrometer/src/test/groovy/io/micronaut/oraclecloud/monitoring/micrometer/OracleCloudMonitorClientEndpointSpec.groovy b/oraclecloud-micrometer/src/test/groovy/io/micronaut/oraclecloud/monitoring/micrometer/OracleCloudMonitorClientEndpointSpec.groovy new file mode 100644 index 000000000..d647e4e01 --- /dev/null +++ b/oraclecloud-micrometer/src/test/groovy/io/micronaut/oraclecloud/monitoring/micrometer/OracleCloudMonitorClientEndpointSpec.groovy @@ -0,0 +1,49 @@ +package io.micronaut.oraclecloud.monitoring.micrometer + +import com.oracle.bmc.Region +import com.oracle.bmc.auth.RegionProvider +import io.micronaut.context.ApplicationContext +import io.micronaut.context.annotation.BootstrapContextCompatible +import io.micronaut.context.annotation.Primary +import io.micronaut.context.annotation.Property +import io.micronaut.context.annotation.Replaces +import io.micronaut.context.annotation.Requires +import io.micronaut.oraclecloud.monitoring.MonitoringIngestionClient +import io.micronaut.test.extensions.spock.annotation.MicronautTest +import jakarta.inject.Inject +import jakarta.inject.Singleton +import spock.lang.Specification + +@MicronautTest(startApplication = false) +@Property(name="micronaut.metrics.export.oraclecloud.enabled", value = "false") +@Property(name="spec.name", value = "OracleCloudMonitorClientEndpointSpec") +class OracleCloudMonitorClientEndpointSpec extends Specification { + + @Inject + ApplicationContext context + + def "test oci sdk metrics client filter request returns exception" () { + when: + MonitoringIngestionClient monitoringIngestionClient = context.getBean(MonitoringIngestionClient) + monitoringIngestionClient.getDelegate() + + then: + final IllegalArgumentException exception = thrown() + exception.message == "Region is required for the Monitoring Ingestion client" + + } + + @Singleton + @BootstrapContextCompatible + @Primary + @Replaces(RegionProvider.class) + @Requires(property = "spec.name", value = "OracleCloudMonitorClientEndpointSpec") + static class RegionProviderReplacement implements RegionProvider { + + @Override + Region getRegion() { + return null + } + } + +}