Skip to content

Commit

Permalink
DOKY-200 Configure Datadog (#130)
Browse files Browse the repository at this point in the history
Use plugin and dependency management aliases; add logging config

Replaced explicit plugin and dependency definitions with version catalog aliases for better maintainability. Introduced centralized logging configuration leveraging `Logback`, including JSON encoding for production. Updated `Dockerfile` to include `Datadog` setup and refined build tasks to improve deployment consistency.
  • Loading branch information
hanna-eismant authored Dec 13, 2024
1 parent 1a89b82 commit 21b733f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 20 deletions.
32 changes: 26 additions & 6 deletions app-server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import com.github.gradle.node.npm.task.NpmTask

plugins {
id("com.microsoft.azure.azurewebapp") version "1.7.1"
id("org.jetbrains.dokka") version "1.9.20"
id("com.github.gmazzo.buildconfig") version "5.3.5"
id("com.github.node-gradle.node") version "7.0.2"
alias(libs.plugins.spring.boot)
alias(libs.plugins.azurewebapp)
alias(libs.plugins.dokka)
alias(libs.plugins.buildconfig)
alias(libs.plugins.node.gradle)
}

dependencyManagement {
Expand All @@ -30,8 +31,6 @@ dependencies {
implementation(libs.azure.blob)
implementation(libs.bundles.kafka)

developmentOnly(libs.spring.boot.devtools)

annotationProcessor(libs.spring.boot.config.processor)

testImplementation(libs.bundles.testing.integration)
Expand Down Expand Up @@ -78,6 +77,7 @@ testing {
implementation(libs.spring.boot.starter.security.get().toString())

implementation(libs.kotlin.logging.get().toString())

}
}
register<JvmTestSuite>("apiTest") {
Expand Down Expand Up @@ -137,6 +137,26 @@ buildConfig {
buildConfigField("DEPLOY_VERSION", provider { deployVersion })
}

tasks {
jar {
manifest {
attributes(
"Manifest-Version" to "1.0",
"Main-Class" to "org.hkurh.doky.DokyApplication",
"Implementation-Title" to "Doky",
"Implementation-Version" to deployVersion,
"Implementation-Vendor" to "hkurh-pets",
"Created-By" to "Kotlin Gradle",
"Built-By" to "Hanna Kurhuzenkava"
)
}
}

assemble {
dependsOn(jar)
}
}

node {
download = true
version = "20.12.2"
Expand Down
38 changes: 38 additions & 0 deletions app-server/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProfile name="!prod">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<springProfile name="prod">
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<timeZone>UTC</timeZone>
</timestamp>
<loggerName/>
<logLevel>
<fieldName>status</fieldName>
</logLevel>
<threadName/>
<stackTrace/>
<message/>
<nestedField>
<fieldName>mdc</fieldName>
<providers>
<mdc/>
</providers>
</nestedField>
<throwableClassName/>
</providers>
</encoder>
</appender>
<root level="info">
<appender-ref ref="stdout"/>
</root>
</springProfile>
</configuration>
15 changes: 7 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ allprojects {
group = "org.hkurh"

plugins {
kotlin("jvm") version "1.9.25"
kotlin("plugin.spring") version "1.9.25"
kotlin("plugin.jpa") version "1.9.25" apply false
id("org.springframework.boot") version "3.3.4" apply false
id("io.spring.dependency-management") version "1.1.6"
id("org.sonarqube") version "5.1.0.4882"
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.plugin.spring)
alias(libs.plugins.kotlin.plugin.jpa) apply false
alias(libs.plugins.spring.boot) apply false
alias(libs.plugins.spring.dependency.management)
alias(libs.plugins.sonarqube)
}

dependencyManagement {
Expand All @@ -33,7 +33,6 @@ subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.kotlin.plugin.spring")
apply(plugin = "org.jetbrains.kotlin.plugin.jpa")
apply(plugin = "org.springframework.boot")
apply(plugin = "io.spring.dependency-management")

java {
Expand All @@ -44,7 +43,7 @@ subprojects {

val libs = rootProject.extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
implementation(libs.findLibrary("kotlin.logging").get())
implementation(libs.findBundle("logging").get())
testImplementation(libs.findBundle("testing.unit").get())
}
}
Expand Down
2 changes: 0 additions & 2 deletions email-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ dependencies {
implementation(libs.bundles.kafka)
implementation(libs.bundles.json)

developmentOnly(libs.spring.boot.devtools)

annotationProcessor(libs.spring.boot.config.processor)

testImplementation(libs.bundles.testing.integration)
Expand Down
20 changes: 18 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ azure-blob = "12.25.3"
httpclient = "4.5.13"
rest-assured = "5.3.0"
junit4 = "4.13.2"
logback-encoder = "8.0"
spring-dependency-management = "1.1.6"
sonarqube = "5.1.0.4882"
azurewebapp = "1.7.1"
dokka = "1.9.20"
buildconfig = "5.3.5"
node-gradle = "7.0.2"

[libraries]
spring-boot-bom = { group = "org.springframework.boot", name = "spring-boot-dependencies", version.ref = "spring-boot" }
Expand All @@ -34,7 +41,6 @@ spring-boot-starter-security = { group = "org.springframework.boot", name = "spr
spring-boot-starter-validation = { group = "org.springframework.boot", name = "spring-boot-starter-validation" }
spring-boot-starter-test = { group = "org.springframework.boot", name = "spring-boot-starter-test" }
spring-boot-config-processor = { group = "org.springframework.boot", name = "spring-boot-configuration-processor" }
spring-boot-devtools = { group = "org.springframework.boot", name = "spring-boot-devtools" }
spring-kafka-production = { group = "org.springframework.kafka", name = "spring-kafka" }
spring-kafka-test = { group = "org.springframework.kafka", name = "spring-kafka-test" }
azure-appconfiguration-config-web = { group = "com.azure.spring", name = "spring-cloud-azure-appconfiguration-config-web" }
Expand Down Expand Up @@ -66,8 +72,11 @@ azure-blob = { group = "com.azure", name = "azure-storage-blob", version.ref = "
httpclient = { group = "org.apache.httpcomponents", name = "httpclient", version.ref = "httpclient" }
rest-assured = { group = "io.rest-assured", name = "rest-assured", version.ref = "rest-assured" }
junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
logback-classic = { group = "ch.qos.logback", name = "logback-classic" }
logback-encoder = { group = "net.logstash.logback", name = "logstash-logback-encoder", version.ref = "logback-encoder" }

[bundles]
logging = ["kotlin-logging", "logback-classic", "logback-encoder"]
flyway = ["flyway-core", "flyway-sqlserver", "flyway-mysql"]
database-connectors = ["sqlserver-connector", "mysql-connector"]
testing-unit = ["junit-jupiter", "mockito-jupiter", "mockito-kotlin"]
Expand All @@ -83,5 +92,12 @@ jwt = ["jjwt-api", "jjwt-impl", "jjwt-jackson"]

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-jvm" }
kotlin-plugin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin-jvm" }
kotlin-plugin-jpa = { id = "org.jetbrains.kotlin.plugin.jpa", version.ref = "kotlin-jvm" }
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" }

spring-dependency-management = { id = "io.spring.dependency-management", version.ref = "spring-dependency-management" }
sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" }
azurewebapp = { id = "com.microsoft.azure.azurewebapp", version.ref = "azurewebapp" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildconfig" }
node-gradle = { id = "com.github.node-gradle.node", version.ref = "node-gradle" }
14 changes: 12 additions & 2 deletions teamcity/app-server.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
FROM openjdk:17

COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
ADD 'https://dtdg.co/latest-java-tracer' /dd_tracer/java/dd-java-agent.jar

ARG DD_VERSION=1

ENV DD_SERVICE=app-server
ENV DD_ENV=prod
ENV DD_VERSION=$DD_VERSION

EXPOSE 8080

ENV ENV_PROFILE=prod
ARG JAR_FILE=app-server/build/libs/app-server.jar
COPY ${JAR_FILE} app.jar

ENTRYPOINT ["java","-jar", "-Dspring.profiles.active=${ENV_PROFILE}", "/app.jar"]
ENTRYPOINT ["/app/datadog-init"]

CMD ["java","-jar", "-Dspring.profiles.active=prod", "/app.jar"]

0 comments on commit 21b733f

Please sign in to comment.