Add Jaeger support for Adservice. (#111)

This is the first service that exports to jaeger. Others to follow.
Requires jaeger to be instantiated using 

- helm install --name jaeger stable/jaeger-operator
- kubectl apply -f jaeger.yaml

=== jaeger.yaml Content ===
apiVersion: io.jaegertracing/v1alpha1
kind: Jaeger
metadata:
  name: jaeger

Above steps will be added to README in subsequent PR.
This commit is contained in:
rghetia 2019-01-03 12:56:06 -08:00 committed by Ahmet Alp Balkan
parent 94ed247c0b
commit d944092100
3 changed files with 24 additions and 13 deletions

View file

@ -31,6 +31,8 @@ spec:
env: env:
- name: PORT - name: PORT
value: "9555" value: "9555"
- name: JAEGER_ENABLED
value: "false"
resources: resources:
requests: requests:
cpu: 200m cpu: 200m

View file

@ -28,7 +28,6 @@ version = "0.1.0-SNAPSHOT" // CURRENT_OPENCENSUS_VERSION
def opencensusVersion = "0.17.0" // LATEST_OPENCENSUS_RELEASE_VERSION def opencensusVersion = "0.17.0" // LATEST_OPENCENSUS_RELEASE_VERSION
def grpcVersion = "1.15.0" // CURRENT_GRPC_VERSION def grpcVersion = "1.15.0" // CURRENT_GRPC_VERSION
def jacksonVersion = "2.9.6" def jacksonVersion = "2.9.6"
def prometheusVersion = "0.3.0"
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
sourceCompatibility = '1.8' sourceCompatibility = '1.8'
@ -45,7 +44,7 @@ dependencies {
compile fileTree(dir: offlineCompile, include: '*.jar') compile fileTree(dir: offlineCompile, include: '*.jar')
} else { } else {
compile "com.google.api.grpc:proto-google-common-protos:1.11.0", compile "com.google.api.grpc:proto-google-common-protos:1.11.0",
"io.opencensus:opencensus-exporter-stats-prometheus:${opencensusVersion}", "io.opencensus:opencensus-exporter-trace-jaeger:${opencensusVersion}",
"io.opencensus:opencensus-exporter-stats-stackdriver:${opencensusVersion}", "io.opencensus:opencensus-exporter-stats-stackdriver:${opencensusVersion}",
"io.opencensus:opencensus-exporter-trace-stackdriver:${opencensusVersion}", "io.opencensus:opencensus-exporter-trace-stackdriver:${opencensusVersion}",
"io.opencensus:opencensus-exporter-trace-logging:${opencensusVersion}", "io.opencensus:opencensus-exporter-trace-logging:${opencensusVersion}",
@ -53,7 +52,6 @@ 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}",
"io.prometheus:simpleclient_httpserver:${prometheusVersion}",
"org.apache.logging.log4j:log4j-core:2.11.1" "org.apache.logging.log4j:log4j-core:2.11.1"
runtime "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}", runtime "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}",

View file

@ -31,7 +31,7 @@ import io.grpc.services.*;
import io.opencensus.common.Duration; import io.opencensus.common.Duration;
import io.opencensus.common.Scope; import io.opencensus.common.Scope;
import io.opencensus.contrib.grpc.metrics.RpcViews; import io.opencensus.contrib.grpc.metrics.RpcViews;
import io.opencensus.exporter.stats.prometheus.PrometheusStatsCollector; import io.opencensus.exporter.trace.jaeger.JaegerTraceExporter;
import io.opencensus.exporter.trace.logging.LoggingTraceExporter; import io.opencensus.exporter.trace.logging.LoggingTraceExporter;
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;
@ -46,7 +46,6 @@ import io.opencensus.trace.samplers.Samplers;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -201,11 +200,6 @@ public class AdService {
public static void initStackdriver() { public static void initStackdriver() {
logger.info("Initialize StackDriver"); logger.info("Initialize StackDriver");
// Registers all RPC views.
RpcViews.registerAllViews();
// Registers logging trace exporter.
LoggingTraceExporter.register();
long sleepTime = 10; /* seconds */ long sleepTime = 10; /* seconds */
int maxAttempts = 5; int maxAttempts = 5;
boolean statsExporterRegistered = false; boolean statsExporterRegistered = false;
@ -243,18 +237,35 @@ public class AdService {
logger.info("StackDriver initialization complete."); logger.info("StackDriver initialization complete.");
} }
static void initJaeger() {
boolean enabled = Boolean.parseBoolean(System.getenv("JAEGER_ENABLED"));
if (enabled) {
// Register Jaeger Tracing.
JaegerTraceExporter.createAndRegister("http://jaeger-collector:14268/api/traces", "adservice");
logger.info("Jaeger initialization complete.");
} else {
logger.info("Jaeger initialization disabled.");
}
}
/** 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 {
// Add final keyword to pass checkStyle. // Add final keyword to pass checkStyle.
// Registers all RPC views.
RpcViews.registerAllViews();
// Registers logging trace exporter.
LoggingTraceExporter.register();
new Thread( new Runnable() { new Thread( new Runnable() {
public void run(){ public void run(){
initStackdriver(); initStackdriver();
} }
}).start(); }).start();
// Register Prometheus exporters and export metrics to a Prometheus HTTPServer. // Register Jaeger
PrometheusStatsCollector.createAndRegister(); initJaeger();
// Start the RPC server. You shouldn't see any output from gRPC before this. // Start the RPC server. You shouldn't see any output from gRPC before this.
logger.info("AdService starting."); logger.info("AdService starting.");
@ -262,4 +273,4 @@ public class AdService {
service.start(); service.start();
service.blockUntilShutdown(); service.blockUntilShutdown();
} }
} }