forked from suman-aella/jaeger-analytics-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Adding changes for prod deployment #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sivatarunp
wants to merge
4
commits into
HAYS_kinesis_otel_integration
Choose a base branch
from
kinesis_source
base: HAYS_kinesis_otel_integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,12 +40,14 @@ | |
| import java.util.stream.Collectors; | ||
| import java.util.stream.StreamSupport; | ||
| import java.util.zip.GZIPInputStream; | ||
| import org.apache.log4j.Logger; | ||
| import org.apache.log4j.PropertyConfigurator; | ||
|
|
||
| /** | ||
| * @author Pavol Loffay | ||
| */ | ||
| public class SparkKinesisRunner { | ||
|
|
||
| private static final Logger logger = Logger.getLogger(SparkKinesisRunner.class.getName()); | ||
| /** | ||
| * System Properties that can be passed | ||
| * SPARK_MASTER | ||
|
|
@@ -63,14 +65,27 @@ public class SparkKinesisRunner { | |
| * @throws IOException | ||
| */ | ||
| public static void main(String[] args) throws InterruptedException, IOException { | ||
| PropertyConfigurator.configure("/data/log4j.properties"); // can make it configurable | ||
| //@transient lazy logger = LogManager.getRootLogger(); | ||
| HTTPServer server = new HTTPServer(getPropOrEnv("PROMETHEUS_HOST", "localhost"), Integer.parseInt(getPropOrEnv("PROMETHEUS_PORT", "9111"))); | ||
|
|
||
| JsonUtil.init(new ObjectMapper()); | ||
|
|
||
| SparkConf sparkConf = new SparkConf() | ||
| .setAppName("Trace DSL") | ||
| .setMaster(getPropOrEnv("SPARK_MASTER", "local[*]")) | ||
| .set("spark.testing.memory", getPropOrEnv("SPARK_MEMORY", "471859200")); | ||
| .set("spark.testing.memory", getPropOrEnv("SPARK_MEMORY", "4073741824")) | ||
|
||
| .set("spark.default.parallelism", getPropOrEnv("SPARK_DEFAULT_PARALLELISM", "30")) | ||
| .set("spark.executor.cores", getPropOrEnv("SPARK_EXECUTOR_CORES", "1")) | ||
| .set("spark.driver.cores", getPropOrEnv("SPARK_DRIVER_CORES", "1")) | ||
| .set("spark.executor.instances", getPropOrEnv("SPARK_EXECUTOR_INSTANCES", "15")) | ||
| .set("spark.serializer", getPropOrEnv("SPARK_SERIALIZER", "org.apache.spark.serializer.KryoSerializer")); | ||
|
|
||
| /* other explored values of settings | ||
| .set("spark.cores.max", getPropOrEnv("SPARK_CORES_MAX", "16")) | ||
| .set("spark.default.parallelism", getPropOrEnv("SPARK_DEFAULT_PARALLELISM", "16")) | ||
| .set("spark.executor.cores", getPropOrEnv("SPARK_EXECUTOR_CORES", "12")) | ||
| */ | ||
|
|
||
| JavaSparkContext sc = new JavaSparkContext(sparkConf); | ||
| long batchInterval = Integer.parseInt(getPropOrEnv("SPARK_STREAMING_BATCH_DURATION", "10000")); | ||
|
|
@@ -85,27 +100,30 @@ public static void main(String[] args) throws InterruptedException, IOException | |
| String region = Regions.getCurrentRegion()!=null ? Regions.getCurrentRegion().getName() | ||
| : getPropOrEnv("AWS_REGION", Regions.US_EAST_1.getName()); | ||
|
|
||
| String service_endpoint = getPropOrEnv("KINESIS_ENDPOINT", "https://kinesis.us-east-1.amazonaws.com"); | ||
|
||
|
|
||
| InitialPositionInStream initialPosition; | ||
| try { | ||
| initialPosition = InitialPositionInStream | ||
| .valueOf(getPropOrEnv("KINESIS_STREAM_POSITION", "TRIM_HORIZON")); | ||
| .valueOf(getPropOrEnv("KINESIS_STREAM_POSITION", "LATEST")); | ||
| } catch (IllegalArgumentException e) { | ||
| initialPosition = InitialPositionInStream.valueOf("TRIM_HORIZON"); | ||
| initialPosition = InitialPositionInStream.valueOf("LATEST"); | ||
| } | ||
|
|
||
|
|
||
| String applicationName = (getPropOrEnv("SPARK_STREAMING_BATCH_DURATION", "10000")); | ||
| KinesisInputDStream<byte[]> kinesisStream = KinesisInputDStream.builder() | ||
| .streamingContext(ssc) | ||
| .regionName(region) | ||
| .streamName(getPropOrEnv("KINESIS_STREAM", "common_haystack_traces")) | ||
| .initialPosition(KinesisInitialPositions.fromKinesisInitialPosition(initialPosition)) | ||
| .checkpointAppName("trace-analytics") | ||
| .checkpointAppName(getPropOrEnv("DYNAMO_TABLE", "trace-analytics")) | ||
| .checkpointInterval(Duration.apply(60 * 1000)) | ||
| .build(); | ||
|
|
||
| JavaDStream<byte[]> dStream = JavaDStream.fromDStream(kinesisStream, ClassTag$.MODULE$.apply(byte[].class)); | ||
|
|
||
| long windowInterval = Integer.parseInt(getPropOrEnv("SPARK_STREAMING_WINDOW_DURATION", "60000")); | ||
| JavaDStream<Span> spanStream = dStream.window(Duration.apply(windowInterval)).flatMap((FlatMapFunction<byte[], Span>) kinesisRecord -> { | ||
| // TO DO can put windowing if needed later | ||
| //long windowInterval = Integer.parseInt(getPropOrEnv("SPARK_STREAMING_WINDOW_DURATION", "60000")); | ||
| JavaDStream<Span> spanStream = dStream.flatMap((FlatMapFunction<byte[], Span>) kinesisRecord -> { | ||
| String payload = new String(decompress(kinesisRecord), StandardCharsets.UTF_8); | ||
| String[] records = payload.split(System.lineSeparator()); | ||
| List<Span> spanList = new LinkedList<>(); | ||
|
|
@@ -120,8 +138,13 @@ public static void main(String[] args) throws InterruptedException, IOException | |
| span.serviceName = span.process.serviceName; | ||
| spanList.add(span); | ||
| } | ||
| Map<String,String> tags = new HashMap<>(); | ||
| for (Map.Entry<String, String> tag: span.tag.entrySet()) { | ||
| tags.put (tag.getKey().replace("@","."),tag.getValue()); | ||
| } | ||
| span.tag = tags; | ||
| } catch (Exception e) { | ||
| System.out.println("Exception for record : "+record); | ||
| logger.error("Exception for record : "+record); | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
@@ -130,7 +153,7 @@ public static void main(String[] args) throws InterruptedException, IOException | |
|
|
||
| JavaPairDStream<String, Span> traceIdSpanTuple = spanStream.mapToPair(record -> new Tuple2<>(record.traceID, record)); | ||
| JavaDStream<Trace> tracesStream = traceIdSpanTuple.groupByKey().map(traceIdSpans -> { | ||
| System.out.printf("TraceID: %s\n", traceIdSpans._1); | ||
| logger.info("TraceID: "+traceIdSpans._1); | ||
| Iterable<Span> spans = traceIdSpans._2(); | ||
| Trace trace = new Trace(); | ||
| trace.traceId = traceIdSpans._1(); | ||
|
|
@@ -140,12 +163,13 @@ public static void main(String[] args) throws InterruptedException, IOException | |
| }); | ||
|
|
||
| List<ModelRunner> modelRunner = Arrays.asList( | ||
| new TraceHeight(), | ||
| new ServiceDepth(), | ||
| new ServiceHeight(), | ||
| /* Removing problematic metrics*/ | ||
| //new TraceHeight(), | ||
| //new ServiceDepth(), | ||
| //new ServiceHeight(), | ||
| new NetworkLatency(), | ||
| new NumberOfErrors(), | ||
| new DirectDependencies(), | ||
| //new NumberOfErrors(), | ||
| //new DirectDependencies(), | ||
| // trace quality | ||
| new HasClientServerSpans(), | ||
| new UniqueSpanId()); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to do like this? Log4j2 will look for config file specified in a pre defined env var by default. We can set that env var to our log4j2.xml or log4j2.yml file when we run this jar.
https://logging.apache.org/log4j/2.x/manual/configuration.html