Skip to content

Commit

Permalink
OCI SDK doesn't have service with telemetry-ingestion so we create one
Browse files Browse the repository at this point in the history
  • Loading branch information
n0tl3ss committed Dec 17, 2024
1 parent c858304 commit 08750d0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package io.micronaut.oraclecloud.monitoring;

import com.oracle.bmc.ClientConfiguration;
import com.oracle.bmc.Service;
import com.oracle.bmc.Services;
import com.oracle.bmc.auth.AbstractAuthenticationDetailsProvider;
import com.oracle.bmc.auth.RegionProvider;
import com.oracle.bmc.http.ClientConfigurator;
Expand All @@ -41,6 +43,7 @@
*/
@Singleton
public class MonitoringIngestionClient {
public static final Service SERVICE = Services.serviceBuilder().serviceName("MONITORING-INGESTION").serviceEndpointPrefix("telemetry-ingestion").serviceEndpointTemplate("https://telemetry-ingestion.{region}.{secondLevelDomain}").build();

private final ClientConfiguration clientConfiguration;
private final ClientConfigurator clientConfigurator;
Expand Down Expand Up @@ -109,7 +112,7 @@ public MonitoringClient getDelegate() {
throw new IllegalArgumentException("Region is required for the Monitoring Ingestion client");
}

String ingestionEndpoint = regionProvider.getRegion().getEndpoint(MonitoringClient.SERVICE)
String ingestionEndpoint = regionProvider.getRegion().getEndpoint(MonitoringIngestionClient.SERVICE)
.orElse(String.format("https://telemetry-ingestion.%s.oraclecloud.com", regionProvider.getRegion().getRegionId()));

MonitoringClient.Builder builder = MonitoringClient.builder().
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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.*
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 = "OracleCloudMonitorClientEndpointUsingRegionProviderSpec")
class OracleCloudMonitorClientEndpointUsingRegionProviderSpec extends Specification {

@Inject
ApplicationContext context

def "test oci sdk metrics client filter request returns exception" () {
when:
MonitoringIngestionClient monitoringIngestionClient = context.getBean(MonitoringIngestionClient)
def delegate = monitoringIngestionClient.getDelegate()

then:
delegate.getEndpoint() == "https://telemetry-ingestion.eu-jovanovac-1.oraclecloud20.com"
}

@Singleton
@BootstrapContextCompatible
@Primary
@Replaces(RegionProvider.class)
@Requires(property = "spec.name", value = "OracleCloudMonitorClientEndpointUsingRegionProviderSpec")
static class RegionProviderReplacement implements RegionProvider {

@Override
Region getRegion() {
return Region.EU_JOVANOVAC_1
}
}

}

0 comments on commit 08750d0

Please sign in to comment.