1
0
mirror of https://github.com/google/nomulus synced 2026-01-05 13:07:04 +00:00
Files
nomulus/jetty/build.gradle
Weimin Yu ca072b4861 Add log traces to Nomulus service on GKE (#2427)
* Add log traces to Nomulus service on GKE

Add request-scope log traces to Nomulus on GKE which, unlike
AppEngine and Cloud Run etc, does not generate traces for hosted
applications. This change only affects the GKE image. It does not affect
the AppEngine services.

Log traces are added to Nomulus-generated logs in request-processing
threads. Forked threads are not covered yet. The single relevant use
case (TimeLimiter) will be addressed in a followup PR.

The main change is in the logging configuration:

*  Use gcp-cloud-logging's LoggingHandler

*  Add gcp-cloud-logging's TraceLoggingEnhancer to the handler.

*  Set a thread-local trace id through the TraceLoggingEnhancer in
   ServletBase on request's entry and clear it on completion.

Also removed an unused class (`RequestLogId`).

* CR

* CR
2024-05-07 19:15:46 +00:00

112 lines
3.8 KiB
Groovy

// Copyright 2024 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
apply plugin: 'war'
tasks.register('copyJettyBase', Copy) {
from(layout.projectDirectory.dir('src/main')) {
include 'jetty-base/**'
}
into layout.buildDirectory
}
war {
setArchiveBaseName("nomulus")
setDestinationDirectory(layout.buildDirectory.dir('jetty-base/webapps'))
dependsOn(tasks.named('copyJettyBase'))
}
test {
filter {
// As the only test class in this project, this must be in the 'test'
// task. If more tests are added, this class along with the system
// property definition below, should be moved to a dedicated task.
includeTestsMatching "google.registry.jetty.LoggingPropertiesTest.*"
}
systemProperty 'java.util.logging.config.file', "${projectDir}/logging.properties"
}
tasks.named('compileTestJava') {
// Gradle insists on this execution dependency.
dependsOn(tasks.named('copyJettyBase'))
}
dependencies {
def deps = rootProject.dependencyMap
implementation project(':core')
testRuntimeOnly project(':util')
testImplementation deps['com.google.cloud:google-cloud-logging']
testImplementation deps['com.google.code.gson:gson']
testImplementation deps['com.google.flogger:flogger']
testImplementation deps['com.google.guava:guava']
testImplementation deps['com.google.truth:truth']
testImplementation deps['org.junit.jupiter:junit-jupiter-api']
testImplementation deps['org.junit.jupiter:junit-jupiter-engine']
}
tasks.register('copyConsole', Copy) {
from("${rootDir}/console-webapp/dist/console-webapp") {
include "**/*"
}
into layout.buildDirectory.dir('jetty-base/webapps/console')
dependsOn(':console-webapp:buildConsoleWebappProd')
}
tasks.register('stage') {
dependsOn(tasks.named('war'))
dependsOn(tasks.named('copyConsole'))
}
tasks.register('buildNomulusImage', Exec) {
commandLine 'docker', 'build', '-t', 'nomulus', '.'
dependsOn(tasks.named('stage'))
}
tasks.register('tagNomulusImage', Exec) {
commandLine 'docker', 'tag', 'nomulus', "gcr.io/${rootProject.gcpProject}/nomulus"
dependsOn(tasks.named('buildNomulusImage'))
}
tasks.register('pushNomulusImage', Exec) {
commandLine 'docker', 'push', "gcr.io/${rootProject.gcpProject}/nomulus"
}
tasks.register('run', JavaExec) {
// We do the check when the task actually runs, not when we define it.
// This way if one doesn't set the value, one can still run other tasks.
doFirst {
def jetty_home = System.getenv('JETTY_HOME')
if (jetty_home == null) {
throw new GradleException('JETTY_HOME is not set.')
}
}
def jetty_home = System.getenv('JETTY_HOME')
def environment = rootProject.environment
workingDir(layout.buildDirectory.dir('jetty-base'))
classpath = files(jetty_home + '/start.jar')
systemProperty('google.registry.environment', environment)
dependsOn(tasks.named('stage'))
}
tasks.register('deployNomulus', Exec) {
dependsOn(tasks.named('pushNomulusImage'), tasks.named(":proxy:pushProxyImage"))
configure verifyDeploymentConfig
commandLine './deploy-nomulus-for-env.sh', "${rootProject.environment}"
}
project.build.dependsOn(tasks.named('buildNomulusImage'))