i want you to die
parent
0ab477314e
commit
b2b3bc7f93
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,10 +1,15 @@
|
||||||
package server;
|
package server;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.trace.Span;
|
||||||
|
import io.opentelemetry.api.trace.SpanBuilder;
|
||||||
|
import io.opentelemetry.api.trace.Tracer;
|
||||||
|
import io.opentelemetry.context.Context;
|
||||||
import shared.ExceptionLogger;
|
import shared.ExceptionLogger;
|
||||||
import shared.FileUtil;
|
import shared.FileUtil;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class Connection implements Runnable {
|
public class Connection implements Runnable {
|
||||||
|
|
||||||
|
@ -12,8 +17,9 @@ public class Connection implements Runnable {
|
||||||
private final Server server;
|
private final Server server;
|
||||||
private DataOutputStream out;
|
private DataOutputStream out;
|
||||||
private DataInputStream in;
|
private DataInputStream in;
|
||||||
|
private Span fileSend;
|
||||||
|
|
||||||
public Connection(Server server, Socket clientSocket) {
|
public Connection(Server server, Tracer trace, Span parent, Socket clientSocket) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.clientSocket = clientSocket;
|
this.clientSocket = clientSocket;
|
||||||
try {
|
try {
|
||||||
|
@ -22,6 +28,15 @@ public class Connection implements Runnable {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ExceptionLogger.log(e);
|
ExceptionLogger.log(e);
|
||||||
}
|
}
|
||||||
|
parent.addEvent("Connection Established", System.nanoTime(), TimeUnit.NANOSECONDS);
|
||||||
|
SpanBuilder sb = trace.spanBuilder("New Connection");
|
||||||
|
Context ctx = Context.current();
|
||||||
|
parent.storeInContext(ctx);
|
||||||
|
sb.setParent(ctx);
|
||||||
|
sb.setAttribute("INetAddress", clientSocket.getInetAddress().toString());
|
||||||
|
sb.setAttribute("Port", clientSocket.getPort());
|
||||||
|
sb.setAttribute("LocalPort", clientSocket.getLocalPort());
|
||||||
|
fileSend = sb.startSpan();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +49,7 @@ public class Connection implements Runnable {
|
||||||
byte command = in.readByte();
|
byte command = in.readByte();
|
||||||
|
|
||||||
if (command == FileUtil.COMMAND.WRITE.type)
|
if (command == FileUtil.COMMAND.WRITE.type)
|
||||||
FileUtil.receive(in);
|
FileUtil.receive(in, fileSend);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
package server;
|
package server;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.api.trace.Span;
|
||||||
|
import io.opentelemetry.api.trace.SpanBuilder;
|
||||||
|
import io.opentelemetry.api.trace.Tracer;
|
||||||
import shared.ExceptionLogger;
|
import shared.ExceptionLogger;
|
||||||
|
import shared.OTelUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class Server {
|
public class Server {
|
||||||
|
|
||||||
|
@ -14,17 +21,24 @@ public class Server {
|
||||||
|
|
||||||
private volatile boolean running = true;
|
private volatile boolean running = true;
|
||||||
|
|
||||||
|
private static final OpenTelemetry ot = OTelUtils.create();
|
||||||
|
|
||||||
public Server() {
|
public Server() {
|
||||||
|
Tracer main = ot.getTracer("Main Server", "0.69");
|
||||||
System.out.println("Starting server");
|
System.out.println("Starting server");
|
||||||
|
SpanBuilder sb = main.spanBuilder("Start Server");
|
||||||
|
Span sbs = sb.startSpan();
|
||||||
try {
|
try {
|
||||||
|
sbs.addEvent("Server Start", System.nanoTime(), TimeUnit.NANOSECONDS);
|
||||||
ServerSocket serverSocket = new ServerSocket(SERVER_PORT);
|
ServerSocket serverSocket = new ServerSocket(SERVER_PORT);
|
||||||
System.out.println("Server Started");
|
System.out.println("Server Started");
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
executor.execute(new Connection(this, serverSocket.accept()));
|
executor.execute(new Connection(this, main, sbs, serverSocket.accept()));
|
||||||
|
|
||||||
serverSocket.close();
|
serverSocket.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
sbs.recordException(e);
|
||||||
ExceptionLogger.log(e);
|
ExceptionLogger.log(e);
|
||||||
}
|
}
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package shared;
|
package shared;
|
||||||
|
|
||||||
import client.ChunkedCompressedChecksumFileWriter;
|
import client.ChunkedCompressedChecksumFileWriter;
|
||||||
|
import io.opentelemetry.api.trace.Span;
|
||||||
import net.jpountz.lz4.LZ4Compressor;
|
import net.jpountz.lz4.LZ4Compressor;
|
||||||
import net.jpountz.lz4.LZ4Factory;
|
import net.jpountz.lz4.LZ4Factory;
|
||||||
import net.jpountz.lz4.LZ4FastDecompressor;
|
import net.jpountz.lz4.LZ4FastDecompressor;
|
||||||
|
@ -11,6 +12,7 @@ import server.ChunkedCompressedChecksumFileReader;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
|
|
||||||
|
@ -55,9 +57,10 @@ public class FileUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void receive(DataInputStream dataIn) {
|
public static void receive(DataInputStream dataIn, Span fs) {
|
||||||
try {
|
try {
|
||||||
String path = createPath(dataIn.readUTF());
|
String path = createPath(dataIn.readUTF());
|
||||||
|
fs.addEvent("Sending file " + path, System.nanoTime(), TimeUnit.NANOSECONDS);
|
||||||
System.out.println("Writing to file: " + path);
|
System.out.println("Writing to file: " + path);
|
||||||
|
|
||||||
ChunkedCompressedChecksumFileReader reader = new ChunkedCompressedChecksumFileReader(dataIn, path, FileUtil.SEED);
|
ChunkedCompressedChecksumFileReader reader = new ChunkedCompressedChecksumFileReader(dataIn, path, FileUtil.SEED);
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package shared;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator;
|
||||||
|
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
|
||||||
|
import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
|
import io.opentelemetry.context.propagation.TextMapPropagator;
|
||||||
|
import io.opentelemetry.exporter.logging.LoggingMetricExporter;
|
||||||
|
import io.opentelemetry.exporter.logging.LoggingSpanExporter;
|
||||||
|
import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter;
|
||||||
|
import io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv.ResourceAttributes;
|
||||||
|
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
||||||
|
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
|
||||||
|
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
|
||||||
|
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||||
|
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
|
||||||
|
import io.opentelemetry.sdk.resources.Resource;
|
||||||
|
import io.opentelemetry.sdk.trace.SdkTracerProvider;
|
||||||
|
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
|
||||||
|
|
||||||
|
public class OTelUtils {
|
||||||
|
|
||||||
|
public static OpenTelemetry create(){
|
||||||
|
Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME.getKey(), "cum").put(ResourceAttributes.SERVICE_VERSION.getKey(), "0.1.0").build();
|
||||||
|
|
||||||
|
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
|
||||||
|
.addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create()))
|
||||||
|
.setResource(resource)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder()
|
||||||
|
.registerMetricReader(PeriodicMetricReader.builder(LoggingMetricExporter.create()).build())
|
||||||
|
.setResource(resource)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
SdkLoggerProvider sdkLoggerProvider = SdkLoggerProvider.builder()
|
||||||
|
.addLogRecordProcessor(BatchLogRecordProcessor.builder(SystemOutLogRecordExporter.create()).build())
|
||||||
|
.setResource(resource)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return OpenTelemetrySdk.builder()
|
||||||
|
.setTracerProvider(sdkTracerProvider)
|
||||||
|
.setMeterProvider(sdkMeterProvider)
|
||||||
|
.setLoggerProvider(sdkLoggerProvider)
|
||||||
|
.setPropagators(ContextPropagators.create(TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance())))
|
||||||
|
.buildAndRegisterGlobal();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue