Skip to content

Commit

Permalink
feat: [SRTP-115] Instrumentation otel azure (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
petretiandrea authored Nov 25, 2024
1 parent 351d5da commit ec83156
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 13 deletions.
25 changes: 21 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ repositories {
mavenCentral()
}

//ext {
// set('springCloudAzureVersion', "5.18.0")
//}
ext {
set('springCloudAzureVersion', "5.18.0")
set('otelInstrumentationVersion','2.10.0')
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
Expand All @@ -42,6 +43,12 @@ dependencies {
implementation("org.openapitools:jackson-databind-nullable:0.2.6")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("org.springframework.boot:spring-boot-starter-validation")

// opentelemetry
// implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter")
// provides the same functionality of spring-boot-starter but configure the azure exporter
implementation("com.azure.spring:spring-cloud-azure-starter-monitor:1.0.0-beta.6")

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'io.projectreactor:reactor-test'
Expand All @@ -50,7 +57,8 @@ dependencies {

dependencyManagement {
imports {
// mavenBom "com.azure.spring:spring-cloud-azure-dependencies:${springCloudAzureVersion}"
mavenBom "com.azure.spring:spring-cloud-azure-dependencies:${springCloudAzureVersion}"
mavenBom "io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:${otelInstrumentationVersion}"
}
}

Expand Down Expand Up @@ -99,6 +107,15 @@ openApiGenerate {
])
}

graalvmNative {
binaries {
main {
buildArgs.add("--initialize-at-build-time=org.slf4j.helpers")
jvmArgs.add("-Djava.security.properties=${file("${projectDir}/src/main/resources/custom.security").absolutePath}")
}
}
}

test {
finalizedBy jacocoTestReport // report is always generated after tests run
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
logging.level.root=INFO


spring.application.name=rtp-activator

# enable spring boot actuator health endpoint
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/custom.security
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jdk.jar.disabledAlgorithms=MD2, MD5, RSA, DSA
26 changes: 26 additions & 0 deletions src/main/terraform/container_app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ resource "azurerm_container_app" "rtp-activator" {
name = "IDENTITY_CLIENT_ID"
secret_name = "identity-client-id"
}

dynamic "env" {
for_each = var.rtp_environment_configs
content {
name = env.key
value = env.value
}
}

dynamic "env" {
for_each = var.rtp_environment_secrets
content {
name = env.key
secret_name = replace(lower(env.key), "_", "-")
}
}
}

max_replicas = var.rtp_activator_max_replicas
Expand All @@ -57,6 +73,16 @@ resource "azurerm_container_app" "rtp-activator" {
value = "${data.azurerm_user_assigned_identity.rtp-activator.client_id}"
}


dynamic "secret" {
for_each = var.rtp_environment_secrets
content {
name = replace(lower(secret.key), "_", "-")
key_vault_secret_id = "${data.azurerm_key_vault.rtp-kv.vault_uri}secrets/${secret.value}"
identity = data.azurerm_user_assigned_identity.rtp-activator.id
}
}

identity {
type = "UserAssigned"
identity_ids = [data.azurerm_user_assigned_identity.rtp-activator.id]
Expand Down
8 changes: 8 additions & 0 deletions src/main/terraform/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ data "azurerm_user_assigned_identity" "rtp-activator" {
name = var.id_name
resource_group_name = var.id_resource_group_name
}

# ------------------------------------------------------------------------------
# General purpose key vault used to protect secrets.
# ------------------------------------------------------------------------------
data "azurerm_key_vault" "rtp-kv" {
name = local.rtp_kv_name
resource_group_name = local.rtp_kv_resource_group_name
}
14 changes: 11 additions & 3 deletions src/main/terraform/env/cstar-d-weu-rtp/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ tags = {
# ------------------------------------------------------------------------------
cae_name = "cstar-d-mcshared-cae"
cae_resource_group_name = "cstar-d-mcshared-app-rg"
id_name = "cstar-d-mcshared-auth-id"
id_resource_group_name = "cstar-d-mcshared-identity-rg"
id_name = "cstar-d-weu-rtp-activator-id"
id_resource_group_name = "cstar-d-weu-rtp-identity-rg"

# ------------------------------------------------------------------------------
# Names of key vault secrets.
Expand All @@ -39,4 +39,12 @@ rtp_activator_cpu = 0.25
rtp_activator_memory = "0.5Gi"
rtp_activator_max_replicas = 5
rtp_activator_min_replicas = 1
rtp_activator_base_url = "https://mil-d-apim.azure-api.net/rtp-activator"
rtp_activator_base_url = "https://mil-d-apim.azure-api.net/rtp-activator"

rtp_environment_configs = {
OTEL_TRACES_SAMPLER: "always_on"
}

rtp_environment_secrets = {
APPLICATIONINSIGHTS_CONNECTION_STRING: "appinsights-connection-string"
}
14 changes: 11 additions & 3 deletions src/main/terraform/env/cstar-p-weu-rtp/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ tags = {
# ------------------------------------------------------------------------------
cae_name = "cstar-p-mcshared-cae"
cae_resource_group_name = "cstar-p-mcshared-app-rg"
id_name = "cstar-p-mcshared-auth-id"
id_resource_group_name = "cstar-p-mcshared-identity-rg"
id_name = "cstar-p-weu-rtp-activator-id"
id_resource_group_name = "cstar-p-weu-rtp-identity-rg"

# ------------------------------------------------------------------------------
# Names of key vault secrets.
Expand All @@ -39,4 +39,12 @@ rtp_activator_cpu = 0.25
rtp_activator_memory = "0.5Gi"
rtp_activator_max_replicas = 5
rtp_activator_min_replicas = 1
rtp_activator_base_url = "https://mil-d-apim.azure-api.net/rtp_activator"
rtp_activator_base_url = "https://mil-d-apim.azure-api.net/rtp_activator"

rtp_environment_configs = {
OTEL_TRACES_SAMPLER: "always_on"
}

rtp_environment_secrets = {
APPLICATIONINSIGHTS_CONNECTION_STRING: "appinsights-connection-string"
}
12 changes: 10 additions & 2 deletions src/main/terraform/env/cstar-u-weu-rtp/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ tags = {
# ------------------------------------------------------------------------------
cae_name = "cstar-u-mcshared-cae"
cae_resource_group_name = "cstar-u-mcshared-app-rg"
id_name = "cstar-u-mcshared-auth-id"
id_resource_group_name = "cstar-u-mcshared-identity-rg"
id_name = "cstar-u-weu-rtp-activator-id"
id_resource_group_name = "cstar-u-weu-rtp-identity-rg"

# ------------------------------------------------------------------------------
# Names of key vault secrets.
Expand All @@ -40,3 +40,11 @@ rtp_activator_memory = "0.5Gi"
rtp_activator_max_replicas = 5
rtp_activator_min_replicas = 1
rtp_activator_base_url = "https://mil-d-apim.azure-api.net/rtp-activator"

rtp_environment_configs = {
OTEL_TRACES_SAMPLER: "always_on"
}

rtp_environment_secrets = {
APPLICATIONINSIGHTS_CONNECTION_STRING: "appinsights-connection-string"
}
3 changes: 3 additions & 0 deletions src/main/terraform/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ locals {
# Project label.
#
project = var.domain == "" ? "${var.prefix}-${var.env_short}" : "${var.prefix}-${var.env_short}-${var.domain}"

rtp_kv_name = "${var.prefix}-${var.env_short}-${var.location_short}-${var.domain}-kv"
rtp_kv_resource_group_name = "${var.prefix}-${var.env_short}-${var.location_short}-${var.domain}-sec-rg"
}
10 changes: 10 additions & 0 deletions src/main/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,13 @@ variable "rtp_activator_memory" {
variable "rtp_activator_image" {
type = string
}

variable "rtp_environment_configs" {
type = map(any)
default = {}
}

variable "rtp_environment_secrets" {
type = map(any)
default = {}
}

0 comments on commit ec83156

Please sign in to comment.