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:
parent
94ed247c0b
commit
d944092100
3 changed files with 24 additions and 13 deletions
|
@ -31,6 +31,8 @@ spec:
|
|||
env:
|
||||
- name: PORT
|
||||
value: "9555"
|
||||
- name: JAEGER_ENABLED
|
||||
value: "false"
|
||||
resources:
|
||||
requests:
|
||||
cpu: 200m
|
||||
|
|
|
@ -28,7 +28,6 @@ version = "0.1.0-SNAPSHOT" // CURRENT_OPENCENSUS_VERSION
|
|||
def opencensusVersion = "0.17.0" // LATEST_OPENCENSUS_RELEASE_VERSION
|
||||
def grpcVersion = "1.15.0" // CURRENT_GRPC_VERSION
|
||||
def jacksonVersion = "2.9.6"
|
||||
def prometheusVersion = "0.3.0"
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
sourceCompatibility = '1.8'
|
||||
|
@ -45,7 +44,7 @@ dependencies {
|
|||
compile fileTree(dir: offlineCompile, include: '*.jar')
|
||||
} else {
|
||||
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-trace-stackdriver:${opencensusVersion}",
|
||||
"io.opencensus:opencensus-exporter-trace-logging:${opencensusVersion}",
|
||||
|
@ -53,7 +52,6 @@ dependencies {
|
|||
"io.grpc:grpc-stub:${grpcVersion}",
|
||||
"io.grpc:grpc-netty:${grpcVersion}",
|
||||
"io.grpc:grpc-services:${grpcVersion}",
|
||||
"io.prometheus:simpleclient_httpserver:${prometheusVersion}",
|
||||
"org.apache.logging.log4j:log4j-core:2.11.1"
|
||||
|
||||
runtime "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}",
|
||||
|
|
|
@ -31,7 +31,7 @@ import io.grpc.services.*;
|
|||
import io.opencensus.common.Duration;
|
||||
import io.opencensus.common.Scope;
|
||||
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.stats.stackdriver.StackdriverStatsConfiguration;
|
||||
import io.opencensus.exporter.stats.stackdriver.StackdriverStatsExporter;
|
||||
|
@ -46,7 +46,6 @@ import io.opencensus.trace.samplers.Samplers;
|
|||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -201,11 +200,6 @@ public class AdService {
|
|||
public static void initStackdriver() {
|
||||
logger.info("Initialize StackDriver");
|
||||
|
||||
// Registers all RPC views.
|
||||
RpcViews.registerAllViews();
|
||||
|
||||
// Registers logging trace exporter.
|
||||
LoggingTraceExporter.register();
|
||||
long sleepTime = 10; /* seconds */
|
||||
int maxAttempts = 5;
|
||||
boolean statsExporterRegistered = false;
|
||||
|
@ -243,18 +237,35 @@ public class AdService {
|
|||
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. */
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
// Add final keyword to pass checkStyle.
|
||||
|
||||
// Registers all RPC views.
|
||||
RpcViews.registerAllViews();
|
||||
|
||||
// Registers logging trace exporter.
|
||||
LoggingTraceExporter.register();
|
||||
|
||||
new Thread( new Runnable() {
|
||||
public void run(){
|
||||
initStackdriver();
|
||||
}
|
||||
}).start();
|
||||
|
||||
// Register Prometheus exporters and export metrics to a Prometheus HTTPServer.
|
||||
PrometheusStatsCollector.createAndRegister();
|
||||
// Register Jaeger
|
||||
initJaeger();
|
||||
|
||||
// Start the RPC server. You shouldn't see any output from gRPC before this.
|
||||
logger.info("AdService starting.");
|
||||
|
@ -262,4 +273,4 @@ public class AdService {
|
|||
service.start();
|
||||
service.blockUntilShutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue