use of zipkin2.storage.mysql.v1.internal.generated.tables.ZipkinAnnotations in project zipkin by openzipkin.
the class SelectSpansAndAnnotations method toTraceIdQuery.
SelectOffsetStep<? extends Record> toTraceIdQuery(DSLContext context, QueryRequest request) {
long endTs = request.endTs() * 1000;
TableOnConditionStep<?> table = ZIPKIN_SPANS.join(ZIPKIN_ANNOTATIONS).on(schema.joinCondition(ZIPKIN_ANNOTATIONS));
int i = 0;
for (Map.Entry<String, String> kv : request.annotationQuery().entrySet()) {
ZipkinAnnotations aTable = ZIPKIN_ANNOTATIONS.as("a" + i++);
if (kv.getValue().isEmpty()) {
table = maybeOnService(table.join(aTable).on(schema.joinCondition(aTable)).and(aTable.A_KEY.eq(kv.getKey())), aTable, request.serviceName());
} else {
table = maybeOnService(table.join(aTable).on(schema.joinCondition(aTable)).and(aTable.A_TYPE.eq(V1BinaryAnnotation.TYPE_STRING)).and(aTable.A_KEY.eq(kv.getKey())).and(aTable.A_VALUE.eq(kv.getValue().getBytes(UTF_8))), aTable, request.serviceName());
}
}
List<SelectField<?>> distinctFields = new ArrayList<>(schema.spanIdFields);
distinctFields.add(max(ZIPKIN_SPANS.START_TS));
SelectConditionStep<Record> dsl = context.selectDistinct(distinctFields).from(table).where(ZIPKIN_SPANS.START_TS.between(endTs - request.lookback() * 1000, endTs));
if (request.serviceName() != null) {
dsl.and(localServiceNameCondition().and(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.eq(request.serviceName())));
}
if (request.remoteServiceName() != null) {
dsl.and(ZIPKIN_SPANS.REMOTE_SERVICE_NAME.eq(request.remoteServiceName()));
}
if (request.spanName() != null) {
dsl.and(ZIPKIN_SPANS.NAME.eq(request.spanName()));
}
if (request.minDuration() != null && request.maxDuration() != null) {
dsl.and(ZIPKIN_SPANS.DURATION.between(request.minDuration(), request.maxDuration()));
} else if (request.minDuration() != null) {
dsl.and(ZIPKIN_SPANS.DURATION.greaterOrEqual(request.minDuration()));
}
return dsl.groupBy(schema.spanIdFields).orderBy(max(ZIPKIN_SPANS.START_TS).desc()).limit(request.limit());
}
Aggregations