BulkIndexWriter { public abstract String writeDocument(T input, ByteBufOutputStream sink);  abstract String writeDocument(T input, ByteBufOutputStream sink); static final BulkIndexWriter<Span> SPAN; static final BulkIndexWriter<Span> SPAN_SEARCH_DISABLED; static final BulkIndexWriter<Map.Entry<String, String>> AUTOCOMPLETE; }
@Test public void span_addsDocumentId() throws Exception { String id = BulkIndexWriter.SPAN.writeDocument(STABLE_SPAN, buffer); assertThat(id) .isEqualTo("7180c278b62e8f6a216a2aea45d08fc9-198140c2a26bfa58fed4a572dfe3d63b"); }
@Test public void spanSearchDisabled_addsDocumentId() throws Exception { String id = BulkIndexWriter.SPAN_SEARCH_DISABLED.writeDocument(STABLE_SPAN, buffer); assertThat(id) .isEqualTo("7180c278b62e8f6a216a2aea45d08fc9-bfe7a3c0d9ee83b1d218bd0f383f006a"); }
@Test public void spanSearchFields_skipsWhenNoData() { Span span = Span.newBuilder() .traceId("20") .id("22") .parentId("21") .timestamp(0L) .localEndpoint(FRONTEND) .kind(Kind.CLIENT) .build(); BulkIndexWriter.SPAN.writeDocument(span, buffer); assertThat(buffer.buffer().toString(StandardCharsets.UTF_8)).startsWith("{\"traceId\":\""); }
@Test public void spanSearchFields_addsTimestampFieldWhenNoTags() { Span span = Span.newBuilder() .traceId("20") .id("22") .name("") .parentId("21") .timestamp(1000L) .localEndpoint(FRONTEND) .kind(Kind.CLIENT) .build(); BulkIndexWriter.SPAN.writeDocument(span, buffer); assertThat(buffer.buffer().toString(StandardCharsets.UTF_8)) .startsWith("{\"timestamp_millis\":1,\"traceId\":"); }
@Test public void spanSearchFields_addsQueryFieldForAnnotations() { Span span = Span.newBuilder() .traceId("20") .id("22") .name("") .parentId("21") .localEndpoint(FRONTEND) .addAnnotation(1L, "\"foo") .build(); BulkIndexWriter.SPAN.writeDocument(span, buffer); assertThat(buffer.buffer().toString(StandardCharsets.UTF_8)) .startsWith("{\"_q\":[\"\\\"foo\"],\"traceId"); }
@Test public void spanSearchFields_addsQueryFieldForTags() { Span span = Span.newBuilder() .traceId("20") .id("22") .parentId("21") .localEndpoint(FRONTEND) .putTag("\"foo", "\"bar") .build(); BulkIndexWriter.SPAN.writeDocument(span, buffer); assertThat(buffer.buffer().toString(StandardCharsets.UTF_8)) .startsWith("{\"_q\":[\"\\\"foo\",\"\\\"foo=\\\"bar\"],\"traceId"); }
@Test public void spanSearchFields_readableByNormalJsonCodec() { Span span = Span.newBuilder().traceId("20").id("20").name("get").timestamp(TODAY * 1000).build(); BulkIndexWriter.SPAN.writeDocument(span, buffer); assertThat(SpanBytesDecoder.JSON_V2.decodeOne(ByteBufUtil.getBytes(buffer.buffer()))) .isEqualTo(span); }
@Test public void spanSearchDisabled_doesntAddQueryFields() { BulkIndexWriter.SPAN_SEARCH_DISABLED.writeDocument(CLIENT_SPAN, buffer); assertThat(buffer.buffer().toString(StandardCharsets.UTF_8)) .startsWith("{\"traceId\":\""); }