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 && \
|
| tar xzv -C /opt/cprof && \
|
||||||
rm -rf profiler_java_agent.tar.gz
|
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 && \
|
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
|
chmod +x /bin/grpc_health_probe
|
||||||
|
|
||||||
|
|
|
@ -1,39 +1,27 @@
|
||||||
description = 'Ad Service'
|
plugins {
|
||||||
|
id 'com.google.protobuf' version '0.8.11'
|
||||||
buildscript {
|
id 'com.github.sherter.google-java-format' version '0.8'
|
||||||
repositories {
|
id 'idea'
|
||||||
mavenCentral()
|
id 'application'
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'idea'
|
|
||||||
apply plugin: 'java'
|
|
||||||
apply plugin: 'com.google.protobuf'
|
|
||||||
apply plugin: 'com.github.sherter.google-java-format'
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
description = 'Ad Service'
|
||||||
group = "adservice"
|
group = "adservice"
|
||||||
version = "0.1.0-SNAPSHOT"
|
version = "0.1.0-SNAPSHOT"
|
||||||
|
|
||||||
def opencensusVersion = "0.18.0"
|
def opencensusVersion = "0.25.0"
|
||||||
def grpcVersion = "1.17.0"
|
def grpcVersion = "1.26.0"
|
||||||
def jacksonVersion = "2.9.6"
|
def jacksonVersion = "2.10.2"
|
||||||
|
def protocVersion = "3.11.4"
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
sourceCompatibility = '1.8'
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = '1.8'
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
|
@ -43,9 +31,9 @@ ext {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
if (speed) {
|
if (speed) {
|
||||||
compile fileTree(dir: offlineCompile, include: '*.jar')
|
implementation fileTree(dir: offlineCompile, include: '*.jar')
|
||||||
} else {
|
} 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-api:${opencensusVersion}",
|
||||||
"io.opencensus:opencensus-contrib-grpc-util:${opencensusVersion}",
|
"io.opencensus:opencensus-contrib-grpc-util:${opencensusVersion}",
|
||||||
"io.opencensus:opencensus-exporter-trace-jaeger:${opencensusVersion}",
|
"io.opencensus:opencensus-exporter-trace-jaeger:${opencensusVersion}",
|
||||||
|
@ -56,19 +44,19 @@ dependencies {
|
||||||
"io.grpc:grpc-stub:${grpcVersion}",
|
"io.grpc:grpc-stub:${grpcVersion}",
|
||||||
"io.grpc:grpc-netty:${grpcVersion}",
|
"io.grpc:grpc-netty:${grpcVersion}",
|
||||||
"io.grpc:grpc-services:${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}",
|
"com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}",
|
||||||
"io.opencensus:opencensus-contrib-log-correlation-log4j2:${opencensusVersion}",
|
"io.opencensus:opencensus-contrib-log-correlation-log4j2:${opencensusVersion}",
|
||||||
"io.opencensus:opencensus-impl:${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 {
|
protobuf {
|
||||||
protoc {
|
protoc {
|
||||||
artifact = 'com.google.protobuf:protoc:3.5.1-1'
|
artifact = "com.google.protobuf:protoc:${protocVersion}"
|
||||||
}
|
}
|
||||||
plugins {
|
plugins {
|
||||||
grpc {
|
grpc {
|
||||||
|
@ -98,9 +86,6 @@ sourceSets {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide convenience executables for trying out the examples.
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
startScripts.enabled = false
|
startScripts.enabled = false
|
||||||
|
|
||||||
// This to cache dependencies during Docker image building. First build will take time.
|
// This to cache dependencies during Docker image building. First build will take time.
|
||||||
|
@ -116,7 +101,7 @@ task adService(type: CreateStartScripts) {
|
||||||
mainClassName = 'hipstershop.AdService'
|
mainClassName = 'hipstershop.AdService'
|
||||||
applicationName = 'AdService'
|
applicationName = 'AdService'
|
||||||
outputDir = new File(project.buildDir, 'tmp')
|
outputDir = new File(project.buildDir, 'tmp')
|
||||||
classpath = jar.outputs.files + project.configurations.runtime
|
classpath = startScripts.classpath
|
||||||
defaultJvmOpts =
|
defaultJvmOpts =
|
||||||
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
|
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
|
||||||
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adservice,-cprof_service_version=1.0.0"]
|
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adservice,-cprof_service_version=1.0.0"]
|
||||||
|
@ -126,7 +111,7 @@ task adServiceClient(type: CreateStartScripts) {
|
||||||
mainClassName = 'hipstershop.AdServiceClient'
|
mainClassName = 'hipstershop.AdServiceClient'
|
||||||
applicationName = 'AdServiceClient'
|
applicationName = 'AdServiceClient'
|
||||||
outputDir = new File(project.buildDir, 'tmp')
|
outputDir = new File(project.buildDir, 'tmp')
|
||||||
classpath = jar.outputs.files + project.configurations.runtime
|
classpath = startScripts.classpath
|
||||||
defaultJvmOpts =
|
defaultJvmOpts =
|
||||||
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
|
["-Dlog4j2.contextDataInjector=io.opencensus.contrib.logcorrelation.log4j2.OpenCensusTraceContextDataInjector",
|
||||||
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adserviceclient,-cprof_service_version=1.0.0"]
|
"-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adserviceclient,-cprof_service_version=1.0.0"]
|
||||||
|
|
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
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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
|
#!/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
|
## Gradle start up script for UN*X
|
||||||
|
@ -28,7 +44,7 @@ APP_NAME="Gradle"
|
||||||
APP_BASE_NAME=`basename "$0"`
|
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.
|
# 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.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
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\""
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
if $cygwin ; then
|
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
@ -138,19 +154,19 @@ if $cygwin ; then
|
||||||
else
|
else
|
||||||
eval `echo args$i`="\"$arg\""
|
eval `echo args$i`="\"$arg\""
|
||||||
fi
|
fi
|
||||||
i=$((i+1))
|
i=`expr $i + 1`
|
||||||
done
|
done
|
||||||
case $i in
|
case $i in
|
||||||
(0) set -- ;;
|
0) set -- ;;
|
||||||
(1) set -- "$args0" ;;
|
1) set -- "$args0" ;;
|
||||||
(2) set -- "$args0" "$args1" ;;
|
2) set -- "$args0" "$args1" ;;
|
||||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -159,14 +175,9 @@ save () {
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
echo " "
|
echo " "
|
||||||
}
|
}
|
||||||
APP_ARGS=$(save "$@")
|
APP_ARGS=`save "$@"`
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# 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"
|
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" "$@"
|
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
|
@if "%DEBUG%" == "" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
|
@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
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.
|
@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
|
@rem Find java.exe
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
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.contrib.grpc.metrics.RpcViews;
|
||||||
import io.opencensus.exporter.stats.stackdriver.StackdriverStatsConfiguration;
|
import io.opencensus.exporter.stats.stackdriver.StackdriverStatsConfiguration;
|
||||||
import io.opencensus.exporter.stats.stackdriver.StackdriverStatsExporter;
|
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.jaeger.JaegerTraceExporter;
|
||||||
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceConfiguration;
|
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceConfiguration;
|
||||||
import io.opencensus.exporter.trace.stackdriver.StackdriverTraceExporter;
|
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 Logger logger = LogManager.getLogger(AdService.class);
|
||||||
private static final Tracer tracer = Tracing.getTracer();
|
private static final Tracer tracer = Tracing.getTracer();
|
||||||
|
|
||||||
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
private static int MAX_ADS_TO_SERVE = 2;
|
private static int MAX_ADS_TO_SERVE = 2;
|
||||||
|
|
||||||
private Server server;
|
private Server server;
|
||||||
private HealthStatusManager healthMgr;
|
private HealthStatusManager healthMgr;
|
||||||
|
|
||||||
private static final AdService service = new AdService();
|
private static final AdService service = new AdService();
|
||||||
|
|
||||||
private void start() throws IOException {
|
private void start() throws IOException {
|
||||||
int port = Integer.parseInt(System.getenv("PORT"));
|
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "9555"));
|
||||||
healthMgr = new HealthStatusManager();
|
healthMgr = new HealthStatusManager();
|
||||||
|
|
||||||
server =
|
server =
|
||||||
|
@ -73,15 +76,14 @@ public final class AdService {
|
||||||
logger.info("Ad Service started, listening on " + port);
|
logger.info("Ad Service started, listening on " + port);
|
||||||
Runtime.getRuntime()
|
Runtime.getRuntime()
|
||||||
.addShutdownHook(
|
.addShutdownHook(
|
||||||
new Thread() {
|
new Thread(
|
||||||
@Override
|
() -> {
|
||||||
public void run() {
|
|
||||||
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
|
// 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");
|
System.err.println(
|
||||||
|
"*** shutting down gRPC ads server since JVM is shutting down");
|
||||||
AdService.this.stop();
|
AdService.this.stop();
|
||||||
System.err.println("*** server shut down");
|
System.err.println("*** server shut down");
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
healthMgr.setStatus("", ServingStatus.SERVING);
|
healthMgr.setStatus("", ServingStatus.SERVING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +136,7 @@ public final class AdService {
|
||||||
responseObserver.onNext(reply);
|
responseObserver.onNext(reply);
|
||||||
responseObserver.onCompleted();
|
responseObserver.onCompleted();
|
||||||
} catch (StatusRuntimeException e) {
|
} catch (StatusRuntimeException e) {
|
||||||
logger.log(Level.WARN, "GetAds Failed", e.getStatus());
|
logger.log(Level.WARN, "GetAds Failed with status {}", e.getStatus());
|
||||||
responseObserver.onError(e);
|
responseObserver.onError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,7 +300,11 @@ public final class AdService {
|
||||||
if (jaegerAddr != null && !jaegerAddr.isEmpty()) {
|
if (jaegerAddr != null && !jaegerAddr.isEmpty()) {
|
||||||
String jaegerUrl = String.format("http://%s/api/traces", jaegerAddr);
|
String jaegerUrl = String.format("http://%s/api/traces", jaegerAddr);
|
||||||
// Register Jaeger Tracing.
|
// Register Jaeger Tracing.
|
||||||
JaegerTraceExporter.createAndRegister(jaegerUrl, "adservice");
|
JaegerTraceExporter.createAndRegister(
|
||||||
|
JaegerExporterConfiguration.builder()
|
||||||
|
.setThriftEndpoint(jaegerUrl)
|
||||||
|
.setServiceName("adservice")
|
||||||
|
.build());
|
||||||
logger.info("Jaeger initialization complete.");
|
logger.info("Jaeger initialization complete.");
|
||||||
} else {
|
} else {
|
||||||
logger.info("Jaeger initialization disabled.");
|
logger.info("Jaeger initialization disabled.");
|
||||||
|
@ -308,21 +314,19 @@ public final class AdService {
|
||||||
/** Main launches the server from the command line. */
|
/** Main launches the server from the command line. */
|
||||||
public static void main(String[] args) throws IOException, InterruptedException {
|
public static void main(String[] args) throws IOException, InterruptedException {
|
||||||
// Registers all RPC views.
|
// Registers all RPC views.
|
||||||
/**
|
/*
|
||||||
* [TODO:rghetia] replace registerAllViews with registerAllGrpcViews.
|
[TODO:rghetia] replace registerAllViews with registerAllGrpcViews. registerAllGrpcViews
|
||||||
* registerAllGrpcViews registers new views using new measures however current grpc version records against
|
registers new views using new measures however current grpc version records against old
|
||||||
* old measures. When new version of grpc (0.19) is release revert back to new. After reverting
|
measures. When new version of grpc (0.19) is release revert back to new. After reverting back
|
||||||
* back to new the new measure will not provide any tags (like method). This will create
|
to new the new measure will not provide any tags (like method). This will create some
|
||||||
* some discrepencies when compared grpc measurements in Go services.
|
discrepencies when compared grpc measurements in Go services.
|
||||||
*/
|
*/
|
||||||
RpcViews.registerAllViews();
|
RpcViews.registerAllViews();
|
||||||
|
|
||||||
new Thread(
|
new Thread(
|
||||||
new Runnable() {
|
() -> {
|
||||||
public void run() {
|
|
||||||
initStats();
|
initStats();
|
||||||
initTracing();
|
initTracing();
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class AdServiceClient {
|
||||||
ManagedChannelBuilder.forAddress(host, port)
|
ManagedChannelBuilder.forAddress(host, port)
|
||||||
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
|
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
|
||||||
// needing certificates.
|
// needing certificates.
|
||||||
.usePlaintext(true)
|
.usePlaintext()
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class AdServiceClient {
|
||||||
.setRecordEvents(true)
|
.setRecordEvents(true)
|
||||||
.setSampler(Samplers.alwaysSample())
|
.setSampler(Samplers.alwaysSample())
|
||||||
.startSpan();
|
.startSpan();
|
||||||
try (Scope scope = tracer.withSpan(span)) {
|
try (Scope ignored = tracer.withSpan(span)) {
|
||||||
tracer.getCurrentSpan().addAnnotation("Getting Ads");
|
tracer.getCurrentSpan().addAnnotation("Getting Ads");
|
||||||
response = blockingStub.getAds(request);
|
response = blockingStub.getAds(request);
|
||||||
tracer.getCurrentSpan().addAnnotation("Received response from Ads Service.");
|
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) {
|
private static int getPortOrDefaultFromArgs(String[] args) {
|
||||||
int portNumber = defaultPort;
|
int portNumber = 9555;
|
||||||
if (index < args.length) {
|
if (2 < args.length) {
|
||||||
try {
|
try {
|
||||||
portNumber = Integer.parseInt(args[index]);
|
portNumber = Integer.parseInt(args[2]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.warn(
|
logger.warn(String.format("Port %s is invalid, use default port %d.", args[2], 9555));
|
||||||
String.format("Port %s is invalid, use default port %d.", args[index], defaultPort));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return portNumber;
|
return portNumber;
|
||||||
|
@ -127,7 +126,7 @@ public class AdServiceClient {
|
||||||
// Add final keyword to pass checkStyle.
|
// Add final keyword to pass checkStyle.
|
||||||
final String contextKeys = getStringOrDefaultFromArgs(args, 0, "camera");
|
final String contextKeys = getStringOrDefaultFromArgs(args, 0, "camera");
|
||||||
final String host = getStringOrDefaultFromArgs(args, 1, "localhost");
|
final String host = getStringOrDefaultFromArgs(args, 1, "localhost");
|
||||||
final int serverPort = getPortOrDefaultFromArgs(args, 2, 9555);
|
final int serverPort = getPortOrDefaultFromArgs(args);
|
||||||
|
|
||||||
// Registers all RPC views.
|
// Registers all RPC views.
|
||||||
RpcViews.registerAllGrpcViews();
|
RpcViews.registerAllGrpcViews();
|
||||||
|
|
Loading…
Reference in a new issue