-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into fix/storage-name-in…
…-view
- Loading branch information
Showing
6 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
Copyright 2024 WeAreFrank! | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package nl.nn.testtool; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
|
||
/** | ||
* Created a Span class to map incoming telemetry data from the endpoint. There is no library available with classes to catch such telemetry data in spans. | ||
*/ | ||
|
||
public class Span { | ||
private String traceId; | ||
private String parentId; | ||
private String id; | ||
private SpanKind kind; | ||
private String name; | ||
private long timestamp; | ||
private long duration; | ||
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; | ||
} | ||
|
||
public String getParentId() { | ||
return parentId; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public long getDuration() { | ||
return duration; | ||
} | ||
|
||
public Map<String, Object> getLocalEndpoint() { | ||
return localEndpoint; | ||
} | ||
|
||
public Map<String, Object> getTags() { | ||
return tags; | ||
} | ||
|
||
public String getKind() { | ||
if (kind == null) { | ||
return null; | ||
} | ||
return kind.toString(); | ||
} | ||
|
||
public Map<String, Object> toHashmap() { | ||
String date = LocalDateTime.ofInstant(Instant.ofEpochMilli(this.timestamp / 1000), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss")); | ||
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\"", "\"" + date + "\""); | ||
map.put("\"duration\"", "\"" + this.duration + "\""); | ||
map.put("\"localEndpoint\"", "\"" + this.localEndpoint + "\""); | ||
map.put("\"tags\"", "\"" + this.tags + "\""); | ||
|
||
return map; | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2021-2024 WeAreFrank! | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package nl.nn.testtool.web.api; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.*; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
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 java.lang.invoke.MethodHandles; | ||
import java.util.ArrayList; | ||
|
||
@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[] trace) { | ||
processSpans(trace); | ||
|
||
return Response.ok().build(); | ||
} | ||
|
||
@POST | ||
@Path("/") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public Response collectSpansJson(Span[] trace) { | ||
processSpans(trace); | ||
|
||
return Response.ok().build(); | ||
} | ||
|
||
private void processSpans(Span[] trace) { | ||
ArrayList<String> parentIds = new ArrayList<>(); | ||
for (Span span: trace) { | ||
if (span.getParentId() != null && !parentIds.contains(span.getParentId())) { | ||
parentIds.add(span.getParentId()); | ||
} | ||
} | ||
ArrayList<String> endpoints = new ArrayList<>(); | ||
for (int i = trace.length - 1; i >= 0; i--) { | ||
if (trace[i].getParentId() == null) { | ||
testTool.startpoint(trace[i].getTraceId(), null, trace[i].getName(), trace[i].toHashmap().toString()); | ||
endpoints.add(trace[i].getName()); | ||
} else { | ||
if (parentIds.contains(trace[i].getId())) { | ||
testTool.startpoint(trace[i].getTraceId(), null, trace[i].getName(), trace[i].toHashmap().toString()); | ||
endpoints.add(trace[i].getName()); | ||
} else { | ||
testTool.infopoint(trace[i].getTraceId(), null, trace[i].getName(), trace[i].toHashmap().toString()); | ||
} | ||
} | ||
} | ||
for (int i = endpoints.size() - 1; i >= 0; i--) { | ||
testTool.endpoint(trace[0].getTraceId(), null, endpoints.get(i), "Endpoint"); | ||
} | ||
} | ||
} |
This file contains 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