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;
|
||||
|
||||
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.FileUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Connection implements Runnable {
|
||||
|
||||
|
@ -12,8 +17,9 @@ public class Connection implements Runnable {
|
|||
private final Server server;
|
||||
private DataOutputStream out;
|
||||
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.clientSocket = clientSocket;
|
||||
try {
|
||||
|
@ -22,6 +28,15 @@ public class Connection implements Runnable {
|
|||
} catch (Exception 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
|
||||
|
@ -34,7 +49,7 @@ public class Connection implements Runnable {
|
|||
byte command = in.readByte();
|
||||
|
||||
if (command == FileUtil.COMMAND.WRITE.type)
|
||||
FileUtil.receive(in);
|
||||
FileUtil.receive(in, fileSend);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
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.OTelUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Server {
|
||||
|
||||
|
@ -14,17 +21,24 @@ public class Server {
|
|||
|
||||
private volatile boolean running = true;
|
||||
|
||||
private static final OpenTelemetry ot = OTelUtils.create();
|
||||
|
||||
public Server() {
|
||||
Tracer main = ot.getTracer("Main Server", "0.69");
|
||||
System.out.println("Starting server");
|
||||
SpanBuilder sb = main.spanBuilder("Start Server");
|
||||
Span sbs = sb.startSpan();
|
||||
try {
|
||||
sbs.addEvent("Server Start", System.nanoTime(), TimeUnit.NANOSECONDS);
|
||||
ServerSocket serverSocket = new ServerSocket(SERVER_PORT);
|
||||
System.out.println("Server Started");
|
||||
|
||||
while (running)
|
||||
executor.execute(new Connection(this, serverSocket.accept()));
|
||||
executor.execute(new Connection(this, main, sbs, serverSocket.accept()));
|
||||
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
sbs.recordException(e);
|
||||
ExceptionLogger.log(e);
|
||||
}
|
||||
executor.shutdown();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package shared;
|
||||
|
||||
import client.ChunkedCompressedChecksumFileWriter;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import net.jpountz.lz4.LZ4Compressor;
|
||||
import net.jpountz.lz4.LZ4Factory;
|
||||
import net.jpountz.lz4.LZ4FastDecompressor;
|
||||
|
@ -11,6 +12,7 @@ import server.ChunkedCompressedChecksumFileReader;
|
|||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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 {
|
||||
String path = createPath(dataIn.readUTF());
|
||||
fs.addEvent("Sending file " + path, System.nanoTime(), TimeUnit.NANOSECONDS);
|
||||
System.out.println("Writing to file: " + path);
|
||||
|
||||
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