Skip to content

Commit

Permalink
Merge pull request #1035 from micronaut-projects/metrics-fix-endpoint
Browse files Browse the repository at this point in the history
fix metrics endpoint
  • Loading branch information
n0tl3ss authored Dec 5, 2024
2 parents 9f5045f + 7c0f4b9 commit 2759c12
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Objects;

/**
* Oracle SDK provides {@link MonitoringClient} that is constructed with default {@code https://telemetry.<region>.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.<region>.oraclecloud.com}. This bean encapsulates creation
* and configuration of the {@link MonitoringClient} to use {@link MonitoringClient#postMetricData(PostMetricDataRequest)}
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

}

0 comments on commit 2759c12

Please sign in to comment.