Skip to content

Commit

Permalink
Feat: converted telemetry data to report
Browse files Browse the repository at this point in the history
  • Loading branch information
ricklue committed May 10, 2024
1 parent ced8337 commit af15f9d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 23 deletions.
44 changes: 32 additions & 12 deletions src/main/java/nl/nn/testtool/Span.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package nl.nn.testtool;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Span {
Expand All @@ -13,6 +15,21 @@ public class Span {
private Map<String, Object> localEndpoint;
private Map<String, Object> tags;

public Span(String traceId, String parentId, String id, SpanKind kind, String name, long timestamp, long duration, Map<String, Object> localEndpoint, Map<String, Object> tags) {
this.traceId = traceId;
this.parentId = parentId;
this.id = id;
this.kind = kind;
this.name = name;
this.timestamp = timestamp;
this.duration = duration;
this.localEndpoint = localEndpoint;
this.tags = tags;
}

public Span() {
}

public String getTraceId() {
return traceId;
}
Expand Down Expand Up @@ -45,22 +62,25 @@ public Map<String, Object> getTags() {
return tags;
}

public SpanKind getKind() {
return kind;
}

public String getKindString(){
public String getKind() {
if (kind == null) {
return null;
}
return kind.toString();
}
}

enum SpanKind {
INTERNAL,
SERVER,
CLIENT,
PRODUCER,
CONSUMER
public Map<String, Object> toHashmap() {
Map<String, Object> map = new HashMap<>();
map.put("traceId", this.traceId);
map.put("parentId", this.parentId);
map.put("id", this.id);
map.put("kind", this.kind);
map.put("name", this.name);
map.put("time", new Date(this.timestamp / 1000));
map.put("duration", this.duration);
map.put("localEndpoint", this.localEndpoint);
map.put("tags", this.tags);

return map;
}
}
9 changes: 9 additions & 0 deletions src/main/java/nl/nn/testtool/SpanKind.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nl.nn.testtool;

public enum SpanKind {
INTERNAL,
SERVER,
CLIENT,
PRODUCER,
CONSUMER
}
30 changes: 19 additions & 11 deletions src/main/java/nl/nn/testtool/web/api/CollectorApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,51 @@
*/
package nl.nn.testtool.web.api;

import lombok.Setter;
import nl.nn.testtool.Span;
import nl.nn.testtool.TestTool;
import nl.nn.testtool.web.ApiServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.lang.invoke.MethodHandles;

@Path("/" + ApiServlet.LADYBUG_API_PATH + "/collector")
public class CollectorApi extends ApiBase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private @Setter @Inject @Autowired TestTool testTool;

@POST
@Path("/")
public Response collectSpans(Span[] content) {
testCollector(content, "default");
public Response collectSpans(Span[] trace) {
testCollector(trace);

return Response.ok().build();
}

@POST
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
public Response collectSpansJson(Span[] content) {
testCollector(content, "json");
public Response collectSpansJson(Span[] trace) {
testCollector(trace);

return Response.ok().build();
}

public void testCollector(Span[] content, String consumeKind) {
for (Span span: content) {
log.info(span.getName());
public void testCollector(Span[] trace) {
try {
testTool.startpoint(trace[0].getTraceId(), null, trace[0].getLocalEndpoint().get("serviceName").toString(), "Startpoint");
for (Span span: trace) {
testTool.infopoint(span.getTraceId(), null, span.getName(), span.toHashmap().toString());
}
testTool.endpoint(trace[0].getTraceId(), null, trace[0].getLocalEndpoint().get("serviceName").toString(), "Endpoint");
} catch (Exception e) {
throw new RuntimeException(e);
}
log.info(consumeKind);
}
}

0 comments on commit af15f9d

Please sign in to comment.