Search in sources :

Example 1 with OTelTraceSource

use of com.amazon.dataprepper.plugins.source.oteltrace.OTelTraceSource in project data-prepper by opensearch-project.

the class ZipkinOpenSearchToOtel method setUpOtelTraceSource.

public static OTelTraceSource setUpOtelTraceSource() {
    final HashMap<String, Object> integerHashMap = new HashMap<>();
    integerHashMap.put("request_timeout", 1);
    final OTelTraceSource SOURCE = new OTelTraceSource(null, null, null);
    SOURCE.start(getBuffer());
    return SOURCE;
}
Also used : HashMap(java.util.HashMap) OTelTraceSource(com.amazon.dataprepper.plugins.source.oteltrace.OTelTraceSource)

Example 2 with OTelTraceSource

use of com.amazon.dataprepper.plugins.source.oteltrace.OTelTraceSource in project data-prepper by opensearch-project.

the class ZipkinOpenSearchToOtel method main.

public static void main(final String[] args) throws IOException {
    if (args.length < 1) {
        System.err.println("Missing indexPattern as arg");
        System.exit(1);
    }
    final String indexPattern = args[0];
    final String field = args.length >= 2 ? args[1] : null;
    final String value = args.length >= 3 ? args[2] : null;
    final boolean isTest = !System.getProperty("test", "false").equalsIgnoreCase("false");
    OTelTraceSource oTelTraceSource = null;
    if (isTest) {
        System.out.println("Setting up testing OtelTraceSource");
        oTelTraceSource = setUpOtelTraceSource();
    }
    final ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration.Builder(Collections.singletonList("https://localhost:9200")).withUsername("admin").withPassword("admin").build();
    final RestHighLevelClient restHighLevelClient = connectionConfiguration.createClient();
    final OpenSearchReader reader = new OpenSearchReader(indexPattern, field, value);
    final TraceServiceGrpc.TraceServiceBlockingStub client = createGRPCClient();
    System.out.println("Reading batch 0");
    List<Map<String, Object>> sources = reader.nextBatch(restHighLevelClient);
    System.out.println(String.format("Batch size: %d", sources.size()));
    System.out.println(String.format("Total number of hits: %d", reader.getTotal()));
    int i = 0;
    while (sources.size() > 0) {
        System.out.println(String.format("Processing batch %d as ExportTraceServiceRequest", i));
        try {
            final ExportTraceServiceRequest exportTraceServiceRequest = ZipkinOpenSearchToOtelPrepper.sourcesToRequest(sources);
            client.export(exportTraceServiceRequest);
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
        System.out.println(String.format("Reading batch %d", i + 1));
        sources = reader.nextBatch(restHighLevelClient);
        i++;
    }
    System.out.println("Clearing reader scroll context ...");
    reader.clearScroll(restHighLevelClient);
    System.out.println("Closing REST client");
    restHighLevelClient.close();
    if (isTest) {
        closeOtelTraceSource(oTelTraceSource);
    }
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) IOException(java.io.IOException) ConnectionConfiguration(com.amazon.dataprepper.plugins.sink.opensearch.ConnectionConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) TraceServiceGrpc(io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc) OTelTraceSource(com.amazon.dataprepper.plugins.source.oteltrace.OTelTraceSource)

Aggregations

OTelTraceSource (com.amazon.dataprepper.plugins.source.oteltrace.OTelTraceSource)2 HashMap (java.util.HashMap)2 ConnectionConfiguration (com.amazon.dataprepper.plugins.sink.opensearch.ConnectionConfiguration)1 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)1 TraceServiceGrpc (io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc)1 IOException (java.io.IOException)1 Map (java.util.Map)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1