use of com.google.cloud.aiplatform.v1.Endpoint in project zipkin by openzipkin.
the class SelectSpansAndAnnotations method apply.
@Override
public List<Span> apply(DSLContext context) {
final Map<Pair, List<V1Span.Builder>> spansWithoutAnnotations;
final Map<Row3<Long, Long, Long>, List<Record>> dbAnnotations;
spansWithoutAnnotations = context.select(schema.spanFields).from(ZIPKIN_SPANS).where(traceIdCondition(context)).stream().map(r -> V1Span.newBuilder().traceIdHigh(maybeGet(r, ZIPKIN_SPANS.TRACE_ID_HIGH, 0L)).traceId(r.getValue(ZIPKIN_SPANS.TRACE_ID)).name(r.getValue(ZIPKIN_SPANS.NAME)).id(r.getValue(ZIPKIN_SPANS.ID)).parentId(maybeGet(r, ZIPKIN_SPANS.PARENT_ID, 0L)).timestamp(maybeGet(r, ZIPKIN_SPANS.START_TS, 0L)).duration(maybeGet(r, ZIPKIN_SPANS.DURATION, 0L)).debug(r.getValue(ZIPKIN_SPANS.DEBUG))).collect(groupingBy(s -> new Pair(s.traceIdHigh(), s.traceId()), LinkedHashMap::new, Collectors.toList()));
dbAnnotations = context.select(schema.annotationFields).from(ZIPKIN_ANNOTATIONS).where(schema.annotationsTraceIdCondition(spansWithoutAnnotations.keySet())).orderBy(ZIPKIN_ANNOTATIONS.A_TIMESTAMP.asc(), ZIPKIN_ANNOTATIONS.A_KEY.asc()).stream().collect(groupingBy((Record a) -> row(maybeGet(a, ZIPKIN_ANNOTATIONS.TRACE_ID_HIGH, 0L), a.getValue(ZIPKIN_ANNOTATIONS.TRACE_ID), a.getValue(ZIPKIN_ANNOTATIONS.SPAN_ID)), LinkedHashMap::new, // LinkedHashMap preserves order while grouping
Collectors.toList()));
V1SpanConverter converter = V1SpanConverter.create();
List<Span> allSpans = new ArrayList<>(spansWithoutAnnotations.size());
for (List<V1Span.Builder> spans : spansWithoutAnnotations.values()) {
for (V1Span.Builder span : spans) {
Row3<Long, Long, Long> key = row(span.traceIdHigh(), span.traceId(), span.id());
if (dbAnnotations.containsKey(key)) {
for (Record a : dbAnnotations.get(key)) {
Endpoint endpoint = endpoint(a);
processAnnotationRecord(a, span, endpoint);
}
}
converter.convert(span.build(), allSpans);
}
}
return allSpans;
}
use of com.google.cloud.aiplatform.v1.Endpoint in project zipkin by openzipkin.
the class JsonSerializersTest method span_specialCharsInJson.
/**
* This isn't a test of what we "should" accept as a span, rather that characters that trip-up
* json don't fail in SPAN_PARSER.
*/
@Test
public void span_specialCharsInJson() {
// service name is surrounded by control characters
Endpoint e = Endpoint.newBuilder().serviceName(new String(new char[] { 0, 'a', 1 })).build();
Span worstSpanInTheWorld = Span.newBuilder().traceId("1").id("1").name(new String(new char[] { '"', '\\', '\t', '\b', '\n', '\r', '\f' })).localEndpoint(e).addAnnotation(1L, "\u2028 and \u2029").putTag("\"foo", "Database error: ORA-00942:\u2028 and \u2029 table or view does not exist\n").build();
assertThat(parse(SPAN_PARSER, new String(SpanBytesEncoder.JSON_V2.encode(worstSpanInTheWorld), UTF_8))).isEqualTo(worstSpanInTheWorld);
}
use of com.google.cloud.aiplatform.v1.Endpoint in project zipkin by openzipkin.
the class JsonSerializers method parseEndpoint.
static Endpoint parseEndpoint(JsonParser parser) throws IOException {
if (!parser.isExpectedStartObjectToken()) {
throw new IllegalArgumentException("Not a valid JSON object, start token: " + parser.currentToken());
}
String serviceName = null, ipv4 = null, ipv6 = null;
int port = 0;
while (parser.nextToken() != JsonToken.END_OBJECT) {
JsonToken value = parser.nextValue();
if (value == JsonToken.VALUE_NULL) {
continue;
}
switch(parser.currentName()) {
case "serviceName":
serviceName = parser.getText();
break;
case "ipv4":
ipv4 = parser.getText();
break;
case "ipv6":
ipv6 = parser.getText();
break;
case "port":
port = parser.getIntValue();
break;
default:
}
}
if (serviceName == null && ipv4 == null && ipv6 == null && port == 0)
return null;
return Endpoint.newBuilder().serviceName(serviceName).ip(ipv4).ip(ipv6).port(port).build();
}
use of com.google.cloud.aiplatform.v1.Endpoint in project zipkin by openzipkin.
the class WireSpanDecoder method decodeEndpoint.
private static Endpoint decodeEndpoint(ProtoReader input) throws IOException {
Endpoint.Builder endpoint = Endpoint.newBuilder();
boolean done = false;
while (!done) {
int tag = input.nextTag();
switch(tag) {
case -1:
done = true;
break;
case 1:
{
String s = input.readString();
endpoint.serviceName(s);
break;
}
case 2:
case 3:
{
endpoint.parseIp(input.readBytes().toByteArray());
break;
}
case 4:
{
endpoint.port(input.readVarint32());
break;
}
default:
{
logAndSkip(input, tag);
break;
}
}
}
return endpoint.build();
}
use of com.google.cloud.aiplatform.v1.Endpoint in project zipkin by openzipkin.
the class ThriftEndpointCodec method write.
static void write(Endpoint value, WriteBuffer buffer) {
IPV4.write(buffer);
buffer.write(value.ipv4Bytes() != null ? value.ipv4Bytes() : INT_ZERO);
PORT.write(buffer);
int port = value.portAsInt();
// write short!
buffer.writeByte((port >>> 8L) & 0xff);
buffer.writeByte(port & 0xff);
SERVICE_NAME.write(buffer);
ThriftCodec.writeLengthPrefixed(buffer, value.serviceName() != null ? value.serviceName() : "");
byte[] ipv6 = value.ipv6Bytes();
if (ipv6 != null) {
IPV6.write(buffer);
ThriftCodec.writeInt(buffer, 16);
buffer.write(ipv6);
}
buffer.writeByte(TYPE_STOP);
}
Aggregations