Migrate to Gradle 6 (#281)
Update build.gradle to use plugin DSL instead of outdated buildscript Update gradle wrapper to 6.3 Update jackson, opencensus, grpc & other dependencies to recent versions Fix code warnings Properly format source files using goJF task Add default port to AdService
This commit is contained in:
parent
e65565987e
commit
23ad0169c2
8 changed files with 113 additions and 95 deletions
|
@ -22,7 +22,7 @@ RUN mkdir -p /opt/cprof && \
|
|||
| tar xzv -C /opt/cprof && \
|
||||
rm -rf profiler_java_agent.tar.gz
|
||||
|
||||
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.1 && \
|
||||
RUN GRPC_HEALTH_PROBE_VERSION=v0.3.1 && \
|
||||
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
|
||||
chmod +x /bin/grpc_health_probe
|
||||
|
||||
|
|
|
@ -1,39 +1,27 @@
|
|||
description = 'Ad Service'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven {
|
||||
url "https://plugins.gradle.org/m2/"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
|
||||
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.7.1"
|
||||
}
|
||||
plugins {
|
||||
id 'com.google.protobuf' version '0.8.11'
|
||||
id 'com.github.sherter.google-java-format' version '0.8'
|
||||
id 'idea'
|
||||
id 'application'
|
||||
}
|
||||
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'com.google.protobuf'
|
||||
apply plugin: 'com.github.sherter.google-java-format'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
description = 'Ad Service'
|
||||
group = "adservice"
|
||||
version = "0.1.0-SNAPSHOT"
|
||||
|
||||
def opencensusVersion = "0.18.0"
|
||||
def grpcVersion = "1.17.0"
|
||||
def jacksonVersion = "2.9.6"
|
||||
def opencensusVersion = "0.25.0"
|
||||
def grpcVersion = "1.26.0"
|
||||
def jacksonVersion = "2.10.2"
|
||||
def protocVersion = "3.11.4"
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
sourceCompatibility = '1.8'
|
||||
targetCompatibility = '1.8'
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
ext {
|
||||
|
@ -43,9 +31,9 @@ ext {
|
|||
|
||||
dependencies {
|
||||
if (speed) {
|
||||
compile fileTree(dir: offlineCompile, include: '*.jar')
|
||||
implementation fileTree(dir: offlineCompile, include: '*.jar')
|
||||
} else {
|
||||
compile "com.google.api.grpc:proto-google-common-protos:1.12.0",
|
||||
implementation "com.google.api.grpc:proto-google-common-protos:1.17.0",
|
||||
"io.opencensus:opencensus-api:${opencensusVersion}",
|
||||
"io.opencensus:opencensus-contrib-grpc-util:${opencensusVersion}",
|
||||
"io.opencensus:opencensus-exporter-trace-jaeger:${opencensusVersion}",
|
||||
|
@ -56,19 +44,19 @@ dependencies {
|
|||
"io.grpc:grpc-stub:${grpcVersion}",
|
||||
"io.grpc:grpc-netty:${grpcVersion}",
|
||||
"io.grpc:grpc-services:${grpcVersion}",
|
||||
"org.apache.logging.log4j:log4j-core:2.11.1"
|
||||
"org.apache.logging.log4j:log4j-core:2.13.0"
|
||||
|
||||
runtime "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}",
|
||||
runtimeOnly "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}",
|
||||
"com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}",
|
||||
"io.opencensus:opencensus-contrib-log-correlation-log4j2:${opencensusVersion}",
|
||||
"io.opencensus:opencensus-impl:${opencensusVersion}",
|
||||
"io.netty:netty-tcnative-boringssl-static:2.0.8.Final"
|
||||
"io.netty:netty-tcnative-boringssl-static:2.0.26.Final"
|
||||
}
|
||||
}
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = 'com.google.protobuf:protoc:3.5.1-1'
|
||||
artifact = "com.google.protobuf:protoc:${protocVersion}"
|
||||
}
|
||||
plugins {
|
||||
grpc {
|
||||
|
@ -98,9 +86,6 @@ sourceSets {
|
|||
}
|
||||
}
|
||||
|
||||
// Provide convenience executables for trying out the examples.
|
||||
apply plugin: 'application'
|
||||
|
||||
startScripts.enabled = false
|
||||
|
||||
// This to cache dependencies during Docker image building. First build will take time.
|
||||
|
@ -116,20 +101,20 @@ task adService(type: CreateStartScripts) {
|
|||
mainClassName = 'hipstershop.AdService'
|
||||
applicationName = 'AdService'
|
||||
outputDir = new File(project.buildDir, 'tmp')
|
||||
classpath = jar.outputs.files + project.configurations.runtime
|
||||
classpath = startScripts.classpath
|
||||
defaultJvmOpts =
|
||||
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
|
||||
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adservice,-cprof_service_version=1.0.0"]
|
||||
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
|
||||
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adservice,-cprof_service_version=1.0.0"]
|
||||
}
|
||||
|
||||
task adServiceClient(type: CreateStartScripts) {
|
||||
mainClassName = 'hipstershop.AdServiceClient'
|
||||
applicationName = 'AdServiceClient'
|
||||
outputDir = new File(project.buildDir, 'tmp')
|
||||
classpath = jar.outputs.files + project.configurations.runtime
|
||||
classpath = startScripts.classpath
|
||||
defaultJvmOpts =
|
||||
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
|
||||
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adserviceclient,-cprof_service_version=1.0.0"]
|
||||
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
|
||||
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adserviceclient,-cprof_service_version=1.0.0"]
|
||||
}
|
||||
|
||||
applicationDistribution.into('bin') {
|
||||
|
|
BIN
src/adservice/gradle/wrapper/gradle-wrapper.jar
vendored
BIN
src/adservice/gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip
|
||||
|
|
51
src/adservice/gradlew
vendored
51
src/adservice/gradlew
vendored
|
@ -1,5 +1,21 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# https://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.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
|
@ -28,7 +44,7 @@ APP_NAME="Gradle"
|
|||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
@ -109,8 +125,8 @@ if $darwin; then
|
|||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
@ -138,19 +154,19 @@ if $cygwin ; then
|
|||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
@ -159,14 +175,9 @@ save () {
|
|||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
|
21
src/adservice/gradlew.bat
vendored
21
src/adservice/gradlew.bat
vendored
|
@ -1,3 +1,19 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
|
@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=.
|
|||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
|
|
@ -32,6 +32,7 @@ import io.opencensus.common.Duration;
|
|||
import io.opencensus.contrib.grpc.metrics.RpcViews;
|
||||
import io.opencensus.exporter.stats.stackdriver.StackdriverStatsConfiguration;
|
||||
import io.opencensus.exporter.stats.stackdriver.StackdriverStatsExporter;
|
||||
import io.opencensus.exporter.trace.jaeger.JaegerExporterConfiguration;
|
||||
import io.opencensus.exporter.trace.jaeger.JaegerTraceExporter;
|
||||
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceConfiguration;
|
||||
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceExporter;
|
||||
|
@ -54,14 +55,16 @@ public final class AdService {
|
|||
private static final Logger logger = LogManager.getLogger(AdService.class);
|
||||
private static final Tracer tracer = Tracing.getTracer();
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private static int MAX_ADS_TO_SERVE = 2;
|
||||
|
||||
private Server server;
|
||||
private HealthStatusManager healthMgr;
|
||||
|
||||
private static final AdService service = new AdService();
|
||||
|
||||
private void start() throws IOException {
|
||||
int port = Integer.parseInt(System.getenv("PORT"));
|
||||
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "9555"));
|
||||
healthMgr = new HealthStatusManager();
|
||||
|
||||
server =
|
||||
|
@ -73,15 +76,14 @@ public final class AdService {
|
|||
logger.info("Ad Service started, listening on " + port);
|
||||
Runtime.getRuntime()
|
||||
.addShutdownHook(
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
|
||||
System.err.println("*** shutting down gRPC ads server since JVM is shutting down");
|
||||
AdService.this.stop();
|
||||
System.err.println("*** server shut down");
|
||||
}
|
||||
});
|
||||
new Thread(
|
||||
() -> {
|
||||
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
|
||||
System.err.println(
|
||||
"*** shutting down gRPC ads server since JVM is shutting down");
|
||||
AdService.this.stop();
|
||||
System.err.println("*** server shut down");
|
||||
}));
|
||||
healthMgr.setStatus("", ServingStatus.SERVING);
|
||||
}
|
||||
|
||||
|
@ -134,7 +136,7 @@ public final class AdService {
|
|||
responseObserver.onNext(reply);
|
||||
responseObserver.onCompleted();
|
||||
} catch (StatusRuntimeException e) {
|
||||
logger.log(Level.WARN, "GetAds Failed", e.getStatus());
|
||||
logger.log(Level.WARN, "GetAds Failed with status {}", e.getStatus());
|
||||
responseObserver.onError(e);
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +300,11 @@ public final class AdService {
|
|||
if (jaegerAddr != null && !jaegerAddr.isEmpty()) {
|
||||
String jaegerUrl = String.format("http://%s/api/traces", jaegerAddr);
|
||||
// Register Jaeger Tracing.
|
||||
JaegerTraceExporter.createAndRegister(jaegerUrl, "adservice");
|
||||
JaegerTraceExporter.createAndRegister(
|
||||
JaegerExporterConfiguration.builder()
|
||||
.setThriftEndpoint(jaegerUrl)
|
||||
.setServiceName("adservice")
|
||||
.build());
|
||||
logger.info("Jaeger initialization complete.");
|
||||
} else {
|
||||
logger.info("Jaeger initialization disabled.");
|
||||
|
@ -308,21 +314,19 @@ public final class AdService {
|
|||
/** Main launches the server from the command line. */
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
// Registers all RPC views.
|
||||
/**
|
||||
* [TODO:rghetia] replace registerAllViews with registerAllGrpcViews.
|
||||
* registerAllGrpcViews registers new views using new measures however current grpc version records against
|
||||
* old measures. When new version of grpc (0.19) is release revert back to new. After reverting
|
||||
* back to new the new measure will not provide any tags (like method). This will create
|
||||
* some discrepencies when compared grpc measurements in Go services.
|
||||
*/
|
||||
/*
|
||||
[TODO:rghetia] replace registerAllViews with registerAllGrpcViews. registerAllGrpcViews
|
||||
registers new views using new measures however current grpc version records against old
|
||||
measures. When new version of grpc (0.19) is release revert back to new. After reverting back
|
||||
to new the new measure will not provide any tags (like method). This will create some
|
||||
discrepencies when compared grpc measurements in Go services.
|
||||
*/
|
||||
RpcViews.registerAllViews();
|
||||
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
initStats();
|
||||
initTracing();
|
||||
}
|
||||
() -> {
|
||||
initStats();
|
||||
initTracing();
|
||||
})
|
||||
.start();
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public class AdServiceClient {
|
|||
ManagedChannelBuilder.forAddress(host, port)
|
||||
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
|
||||
// needing certificates.
|
||||
.usePlaintext(true)
|
||||
.usePlaintext()
|
||||
.build());
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class AdServiceClient {
|
|||
.setRecordEvents(true)
|
||||
.setSampler(Samplers.alwaysSample())
|
||||
.startSpan();
|
||||
try (Scope scope = tracer.withSpan(span)) {
|
||||
try (Scope ignored = tracer.withSpan(span)) {
|
||||
tracer.getCurrentSpan().addAnnotation("Getting Ads");
|
||||
response = blockingStub.getAds(request);
|
||||
tracer.getCurrentSpan().addAnnotation("Received response from Ads Service.");
|
||||
|
@ -97,14 +97,13 @@ public class AdServiceClient {
|
|||
}
|
||||
}
|
||||
|
||||
private static int getPortOrDefaultFromArgs(String[] args, int index, int defaultPort) {
|
||||
int portNumber = defaultPort;
|
||||
if (index < args.length) {
|
||||
private static int getPortOrDefaultFromArgs(String[] args) {
|
||||
int portNumber = 9555;
|
||||
if (2 < args.length) {
|
||||
try {
|
||||
portNumber = Integer.parseInt(args[index]);
|
||||
portNumber = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn(
|
||||
String.format("Port %s is invalid, use default port %d.", args[index], defaultPort));
|
||||
logger.warn(String.format("Port %s is invalid, use default port %d.", args[2], 9555));
|
||||
}
|
||||
}
|
||||
return portNumber;
|
||||
|
@ -127,7 +126,7 @@ public class AdServiceClient {
|
|||
// Add final keyword to pass checkStyle.
|
||||
final String contextKeys = getStringOrDefaultFromArgs(args, 0, "camera");
|
||||
final String host = getStringOrDefaultFromArgs(args, 1, "localhost");
|
||||
final int serverPort = getPortOrDefaultFromArgs(args, 2, 9555);
|
||||
final int serverPort = getPortOrDefaultFromArgs(args);
|
||||
|
||||
// Registers all RPC views.
|
||||
RpcViews.registerAllGrpcViews();
|
||||
|
|
Loading…
Reference in a new issue