Skip to content

Commit

Permalink
Change the namespace validation for oracle metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-dmytruk committed Jan 13, 2023
1 parent 41d9626 commit ba1ff9c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ default Validated<?> validate() {
"must match pattern '" + NAMESPACE_REGEX + "'",
InvalidReason.MALFORMED);
}
if (namespace().startsWith("oci_")) {
return Validated.invalid(prefix() + ".namespace", namespace(),
"cannot start with 'oci_'", InvalidReason.MALFORMED);
}
return Validated.valid(prefix() + ".namespace", namespace());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@ class OracleCloudMeterRegistryFactorySpec extends Specification {
@Shared
String compartmentOcid = System.getenv("MONITORING_COMPARTMENT_OCID")

@Shared
String configProfile = System.getenv("MONITORING_CONFIG_PROFILE")

def "test it publish metrics to ingestion telemetry endpoint"() {
given:

def confVariables = [
"micronaut.metrics.export.oraclecloud.enabled" : true,
"micronaut.metrics.export.oraclecloud.step" : "1s",
"micronaut.metrics.export.oraclecloud.namespace" : "micronaut_test",
"micronaut.metrics.export.oraclecloud.applicationName": "micronaut_test",
"micronaut.metrics.export.oraclecloud.applicationName": "micronaut_test"
]

if (compartmentOcid != null && !compartmentOcid.isEmpty()) {
confVariables["micronaut.metrics.export.oraclecloud.compartmentId"] = compartmentOcid
}
if (configProfile != null && !configProfile.isEmpty()) {
confVariables["oci.config.profile"] = configProfile
}

ApplicationContext context = ApplicationContext.run(confVariables, Environment.ORACLE_CLOUD)
OracleCloudMeterRegistry cloudMeterRegistry = context.getBean(OracleCloudMeterRegistry)
Expand All @@ -41,7 +49,7 @@ class OracleCloudMeterRegistryFactorySpec extends Specification {
description("Testing of micronaut-oraclecloud-monitoring module").
register(cloudMeterRegistry)
counter.increment(5.0)
sleep(2000)
sleep(6000)

then:
noExceptionThrown()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.micronaut.oraclecloud.monitoring.micrometer

import io.micronaut.context.ApplicationContext
import jakarta.inject.Inject
import spock.lang.Specification

class OracleCloudNamespaceValidationSpec extends Specification {

@Inject
ApplicationContext context

def "test valid namespaces"() {
given:
var pattern = OracleCloudConfig.NAMESPACE_PATTERN

expect:
pattern.matcher(string).matches()

where:
string | _
"namespace" | _
"namespace123" | _
"my_space_123" | _
"example_namespace" | _
}

def "test invalid namespaces"() {
given:
var pattern = OracleCloudConfig.NAMESPACE_PATTERN

expect:
!pattern.matcher(string).matches()

where:
string | _
"one&two" | _
"-namespace" | _
"Namespace%Example" | _
"123-my-space" | _
"NAMESPACE" | _
"example-namespace" | _
"EXAMPLE-Namespace-example123" | _
"my-space-123" | _
}
}

0 comments on commit ba1ff9c

Please sign in to comment.